brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [15/50] [abbrv] brooklyn-server git commit: Sanitizes the classpath in CatalogClasspathDo to prevent issue when launching brooklyn with jsvc
Date Mon, 01 Feb 2016 17:50:31 GMT
Sanitizes the classpath in CatalogClasspathDo to prevent issue when launching brooklyn with
jsvc


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e50fc99b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e50fc99b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e50fc99b

Branch: refs/heads/0.8.0-incubating
Commit: e50fc99b5e0982db48101af6389a101f131f8396
Parents: 40281e0
Author: Martin Harris <github@nakomis.com>
Authored: Tue Aug 25 16:50:43 2015 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Tue Aug 25 16:50:43 2015 +0100

----------------------------------------------------------------------
 .../catalog/internal/CatalogClasspathDo.java    | 21 +++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e50fc99b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogClasspathDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogClasspathDo.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogClasspathDo.java
index ffb7874..a8b7bbe 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogClasspathDo.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogClasspathDo.java
@@ -179,7 +179,7 @@ public class CatalogClasspathDo {
                 try {
                     ((ManagementContextInternal)catalog.mgmt).setBaseClassPathForScanning(ClasspathHelper.forJavaClassPath());
                     log.debug("Catalog scan of default classloader returned nothing; reverting
to java.class.path");
-                    baseCP = ((ManagementContextInternal)catalog.mgmt).getBaseClassPathForScanning();
+                    baseCP = sanitizeCP(((ManagementContextInternal) catalog.mgmt).getBaseClassPathForScanning());
                     scanner = new ReflectionScanner(baseCP, prefix, baseCL, catalog.getRootClassLoader());
                 } catch (Exception e) {
                     log.info("Catalog scan is empty, and unable to use java.class.path (base
classpath is "+baseCP+"): "+e);
@@ -242,6 +242,25 @@ public class CatalogClasspathDo {
         isLoaded = true;
     }
 
+    private Iterable<URL> sanitizeCP(Iterable<URL> baseClassPathForScanning)
{
+        /*
+        If Brooklyn is being run via apache daemon[1], and the classpath contains the contents
of an empty folder,
+        (e.g. xxx:lib/patch/*:xxx) the classpath will be incorrectly expanded to include
a zero-length string
+        (e.g. xxx::xxx), which is then interpreted by {@link org.reflections.Reflections#scan}
as the root of the
+        file system. See [2], line 90+. This needs to be removed, lest we attempt to scan
the entire filesystem
+
+        [1]: http://commons.apache.org/proper/commons-daemon/
+        [2]: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.c?view=markup&pathrev=1196468
+         */
+        Iterables.removeIf(baseClassPathForScanning, new Predicate<URL>() {
+            @Override
+            public boolean apply(@Nullable URL url) {
+                return Strings.isEmpty(url.getFile()) || "/".equals(url.getFile());
+            }
+        });
+        return baseClassPathForScanning;
+    }
+
     /** removes inner classes (non-static nesteds) and others; 
      * bear in mind named ones will be hard to instantiate without the outer class instance)
*/
     private <T> Iterable<Class<? extends T>> excludeInvalidClasses(Iterable<Class<?
extends T>> input) {


Mime
View raw message