geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [geode] branch develop updated: GEODE-5165: add capability to limit the packages to scan for annotation. (#1893)
Date Wed, 02 May 2018 14:57:25 GMT
This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 9514935  GEODE-5165: add capability to limit the packages to scan for annotation.
(#1893)
9514935 is described below

commit 9514935ba82aa37ba03f7c3eee706d8482684b4a
Author: jinmeiliao <jiliao@pivotal.io>
AuthorDate: Wed May 2 07:57:19 2018 -0700

    GEODE-5165: add capability to limit the packages to scan for annotation. (#1893)
---
 .../InternalConfigurationPersistenceService.java   | 13 ++++++++++++-
 .../geode/internal/lang/SystemPropertyHelper.java  | 12 +++++++++++-
 ...nternalConfigurationPersistenceServiceTest.java | 22 ++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceService.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceService.java
index 489801b..a6d7380 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceService.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceService.java
@@ -88,6 +88,7 @@ import org.apache.geode.internal.cache.persistence.PersistentMemberManager;
 import org.apache.geode.internal.cache.persistence.PersistentMemberPattern;
 import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator;
 import org.apache.geode.internal.config.JAXBService;
+import org.apache.geode.internal.lang.SystemPropertyHelper;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.management.internal.beans.FileUploader;
 import org.apache.geode.management.internal.cli.CliUtil;
@@ -179,13 +180,23 @@ public class InternalConfigurationPersistenceService implements ConfigurationPer
     }
     // else, scan the classpath to find all the classes annotated with XSDRootElement
     else {
+      String[] packages = getPackagesToScan();
       Set<Class<?>> scannedClasses =
-          ClasspathScanLoadHelper.scanClasspathForAnnotation(XSDRootElement.class, "");
+          ClasspathScanLoadHelper.scanClasspathForAnnotation(XSDRootElement.class, packages);
       this.jaxbService = new JAXBService(scannedClasses.toArray(new Class[scannedClasses.size()]));
     }
     jaxbService.validateWithLocalCacheXSD();
   }
 
+  protected String[] getPackagesToScan() {
+    String sysProperty = SystemPropertyHelper.getProperty(SystemPropertyHelper.PACKAGES_TO_SCAN);
+    String[] packages = {""};
+    if (sysProperty != null) {
+      packages = sysProperty.split(",");
+    }
+    return packages;
+  }
+
   /**
    * Gets or creates (if not created) shared configuration lock service
    */
diff --git a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
index 91ede6c..7f1848b 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/lang/SystemPropertyHelper.java
@@ -70,6 +70,16 @@ public class SystemPropertyHelper {
       "PERSISTENT_VIEW_RETRY_TIMEOUT_SECONDS";
 
   /**
+   * a comma separated string to list out the packages to scan. If not specified, the entire
+   * classpath is scanned.
+   * This is used by the FastPathScanner to scan for:
+   * 1. XSDRootElement annotation
+   *
+   * @since Geode 1.7.0
+   */
+  public static final String PACKAGES_TO_SCAN = "packagesToScan";
+
+  /**
    * This method will try to look up "geode." and "gemfire." versions of the system property.
It
    * will check and prefer "geode." setting first, then try to check "gemfire." setting.
    *
@@ -113,7 +123,7 @@ public class SystemPropertyHelper {
     return property != null ? Optional.of(property) : Optional.empty();
   }
 
-  private static String getProperty(String name) {
+  public static String getProperty(String name) {
     String property = getGeodeProperty(name);
     return property != null ? property : getGemfireProperty(name);
   }
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java
index 1e520db..b0fa995 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalConfigurationPersistenceServiceTest.java
@@ -28,7 +28,9 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.Region;
@@ -38,6 +40,7 @@ import org.apache.geode.cache.configuration.RegionConfig;
 import org.apache.geode.internal.config.JAXBServiceTest;
 import org.apache.geode.internal.config.JAXBServiceTest.ElementOne;
 import org.apache.geode.internal.config.JAXBServiceTest.ElementTwo;
+import org.apache.geode.internal.lang.SystemPropertyHelper;
 import org.apache.geode.management.internal.configuration.domain.Configuration;
 import org.apache.geode.test.junit.categories.UnitTest;
 
@@ -47,6 +50,9 @@ public class InternalConfigurationPersistenceServiceTest {
   private InternalConfigurationPersistenceService service, service2;
   private Configuration configuration;
 
+  @Rule
+  public RestoreSystemProperties restore = new RestoreSystemProperties();
+
   @Before
   public void setUp() throws Exception {
     service = spy(new InternalConfigurationPersistenceService(CacheConfig.class, ElementOne.class,
@@ -174,4 +180,20 @@ public class InternalConfigurationPersistenceServiceTest {
 
     verify(region).put(eq("non-existing-group"), any());
   }
+
+  @Test
+  public void getPackagesToScanWithoutSystemProperty() {
+    String[] packages = service.getPackagesToScan();
+    assertThat(packages).hasSize(1);
+    assertThat(packages[0]).isEqualTo("");
+  }
+
+  @Test
+  public void getPackagesToScanWithSystemProperty() {
+    System.setProperty("geode." + SystemPropertyHelper.PACKAGES_TO_SCAN,
+        "org.apache.geode,io.pivotal");
+    String[] packages = service.getPackagesToScan();
+    assertThat(packages).hasSize(2);
+    assertThat(packages).contains("org.apache.geode", "io.pivotal");
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
jinmeiliao@apache.org.

Mime
View raw message