diff --git a/distro/README b/distro/README
index 38b5d4b..7767711 100644
--- a/distro/README
+++ b/distro/README
@@ -29,8 +29,7 @@ Binaries can be downloaded from:
Documentation
-------------
Documentation is available on-line from the Projects Documentation Wiki:
-https://gcube.wiki.gcube-system.org/gcube/index.php/Integration_and_Interoperability_Facilities_Framework:_Client_Libraries_Design_Model#Scope_Management
-
+https://gcube.wiki.gcube-system.org/gcube/index.php/Common-scope
Licensing
---------
diff --git a/distro/changelog.xml b/distro/changelog.xml
index 3407866..f0c510a 100644
--- a/distro/changelog.xml
+++ b/distro/changelog.xml
@@ -2,10 +2,14 @@
First Release
-
+
Scope can now be propagated in Callable and Runnable tasks via ScopedTasks
Scopes can now be manipulated through ScopeBean objects
Scope maps are now versioned and newer versions take precedence at startup
Scope maps can now be successfully looked up in VRE scopes (bug fix)
+
+ Replaced Google's reflections with common-configuration-scanner
+ Lowered log level on scope settings to DEBUG
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 2b681f9..febd3f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
org.gcube.core
common-scope
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
Common Scope
Scope-related APIs
@@ -25,50 +25,39 @@
http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}
-
-
-
- org.gcube.distribution
- maven-bom
- [1.0.0-SNAPSHOT,)
- pom
-
-
-
-
- org.reflections
- reflections
- 0.9.8
+ org.gcube.core
+ common-configuration-scanner
+ 1.0.0-SNAPSHOT
-
+
org.gcube.core
common-scope-maps
- [1.0.0-SNAPSHOT,)
+ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)
compile
junit
junit
- 4.10
+ 4.11
test
org.slf4j
slf4j-api
- 1.6.4
+ 1.7.2
compile
org.slf4j
slf4j-simple
- 1.6.4
+ 1.7.2
test
diff --git a/src/main/java/org/gcube/common/scope/impl/DefaultScopeProvider.java b/src/main/java/org/gcube/common/scope/impl/DefaultScopeProvider.java
index 107a859..e46e2d7 100644
--- a/src/main/java/org/gcube/common/scope/impl/DefaultScopeProvider.java
+++ b/src/main/java/org/gcube/common/scope/impl/DefaultScopeProvider.java
@@ -35,14 +35,14 @@ public class DefaultScopeProvider implements ScopeProvider {
@Override
public void set(String scope) {
if (scope!=null)
- log.info("setting scope {} in thread {}",scope,Thread.currentThread().getId());
+ log.debug("setting scope {} in thread {}",scope,Thread.currentThread().getId());
scopes.set(scope);
}
@Override
public void reset() {
- log.info("resetting scope in thread {}",Thread.currentThread().getId());
+ log.debug("resetting scope in thread {}",Thread.currentThread().getId());
scopes.remove();
}
diff --git a/src/main/java/org/gcube/common/scope/impl/ServiceMapScanner.java b/src/main/java/org/gcube/common/scope/impl/ServiceMapScanner.java
index fbcb29b..f3b0dbe 100644
--- a/src/main/java/org/gcube/common/scope/impl/ServiceMapScanner.java
+++ b/src/main/java/org/gcube/common/scope/impl/ServiceMapScanner.java
@@ -2,77 +2,81 @@ package org.gcube.common.scope.impl;
import java.net.URL;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
-import java.util.regex.Pattern;
+import java.util.Set;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
+import org.gcube.common.scan.ClasspathScanner;
+import org.gcube.common.scan.ClasspathScannerFactory;
+import org.gcube.common.scan.matchers.NameMatcher;
+import org.gcube.common.scan.resources.ClasspathResource;
import org.gcube.common.scope.api.ServiceMap;
-import org.reflections.Reflections;
-import org.reflections.scanners.ResourcesScanner;
-import org.reflections.util.ClasspathHelper;
-import org.reflections.util.ConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Scans the classpath for {@link ServiceMap}s.
+ *
* @author Fabio Simeoni
- *
+ *
*/
class ServiceMapScanner {
private static Logger log = LoggerFactory.getLogger(ServiceMapScanner.class);
-
+
/**
* The path used to find service map configuration files.
*/
static final String mapConfigPattern = ".*\\.servicemap";
-
+
/**
* Scans the classpath for {@link ServiceMap}s.
*/
static Map maps() {
-
+
Map maps = new HashMap();
-
- try {
- JAXBContext context = JAXBContext
- .newInstance(DefaultServiceMap.class);
- Unmarshaller um = context.createUnmarshaller();
+ try {
- // we include urls specified in manifest files, which is required
- // when we run tests in surefire's forked-mode
- ConfigurationBuilder builder = new ConfigurationBuilder().setUrls(
- ClasspathHelper.forManifest(Utils.urlsToScan())).setScanners(
- new ResourcesScanner());
+ Set resources = getMapNames();
- Reflections reflections = new Reflections(builder);
+ JAXBContext context = JAXBContext.newInstance(DefaultServiceMap.class);
+ Unmarshaller um = context.createUnmarshaller();
- for (String resource : reflections.getResources(Pattern
- .compile(mapConfigPattern))) {
- URL url = Thread.currentThread().getContextClassLoader()
- .getResource(resource);
- log.info("loading {} ", url);
- DefaultServiceMap map = (DefaultServiceMap) um.unmarshal(url);
-
- ServiceMap current = maps.get(map.scope());
- if (current!=null && current.version()!=null)
- if (current.version().compareToIgnoreCase(map.version())==1) {
- log.warn("discarding {} because older (v.{}) than one previously loaded (v.{}) for {} ", new Object[]{url, map.version(), current.version(), map.scope()});
- continue;
- }
- else
- log.info("overwriting older map (v.{}) with newer map (v.{}) for {} ", new Object[]{current.version(), map.version(), map.scope()});
-
- maps.put(map.scope(), map);
- }
- } catch (Exception e) {
- throw new RuntimeException("could not load service maps", e);
+ for (String resource : resources) {
+
+ URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
+ log.info("loading {} ", url);
+ DefaultServiceMap map = (DefaultServiceMap) um.unmarshal(url);
+
+ ServiceMap current = maps.get(map.scope());
+ if (current != null && current.version() != null)
+ if (current.version().compareToIgnoreCase(map.version()) == 1) {
+ log.warn("discarding {} because older (v.{}) than one previously loaded (v.{}) for {} ",
+ new Object[] { url, map.version(), current.version(), map.scope() });
+ continue;
+ } else
+ log.info("overwriting older map (v.{}) with newer map (v.{}) for {} ",
+ new Object[] { current.version(), map.version(), map.scope() });
+
+ maps.put(map.scope(), map);
}
-
- return maps;
+ } catch (Exception e) {
+ throw new RuntimeException("could not load service maps", e);
}
+
+ return maps;
+ }
+
+ private static Set getMapNames() {
+
+ ClasspathScanner scanner = ClasspathScannerFactory.scanner();
+ Set names = new HashSet();
+ for (ClasspathResource r : scanner.scan(new NameMatcher(mapConfigPattern)))
+ names.add(r.name());
+ return names;
+ }
}
diff --git a/src/main/java/org/gcube/common/scope/impl/Utils.java b/src/main/java/org/gcube/common/scope/impl/Utils.java
deleted file mode 100644
index 2b088d7..0000000
--- a/src/main/java/org/gcube/common/scope/impl/Utils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.gcube.common.scope.impl;
-
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Set;
-
-import com.google.common.collect.Sets;
-
-/**
- * Classpath discovery utils.
- *
- * @author Fabio Simeoni
- *
- */
-public class Utils {
-
- // helper: we use reflections' code but exclude extension and primordial
- // classloaders
- // whose URLs we do not want to include. especially because these may have
- // non-standard URLs
- // that would need to be excluded individually from standard scanning,
- // or reflections will show (but ignore) a horrible error in the logs. and
- // we do no know how to predict what we will
- // find on any given machine
- static Set urlsToScan() {
- final Set result = Sets.newHashSet();
-
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- while (classLoader != null && classLoader.getParent() != null) {
- if (classLoader instanceof URLClassLoader) {
- URL[] urls = ((URLClassLoader) classLoader).getURLs();
- if (urls != null) {
- result.addAll(Sets. newHashSet(urls));
- }
- }
- classLoader = classLoader.getParent();
- }
-
- return result;
- }
-}