camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r804847 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java test/resources/package_scan_test.jar
Date Mon, 17 Aug 2009 04:11:25 GMT
Author: wtam
Date: Mon Aug 17 04:11:24 2009
New Revision: 804847

URL: http://svn.apache.org/viewvc?rev=804847&view=rev
Log:
[CAMEL-1917] DefaultPackageScanClassResolver not able to scan package in jar url

Added:
    camel/trunk/camel-core/src/test/resources/package_scan_test.jar   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java?rev=804847&r1=804846&r2=804847&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
Mon Aug 17 04:11:24 2009
@@ -210,9 +210,12 @@
                     log.trace("Decoded urlPath: " + urlPath);
                 }
 
+                boolean isLocalFileSystem = "file".equals(url.getProtocol());
+
                 // If it's a file in a directory, trim the stupid file: spec
                 if (urlPath.startsWith("file:")) {
                     urlPath = urlPath.substring(5);
+                    isLocalFileSystem = true;
                 }
 
                 // osgi bundles should be skipped
@@ -238,8 +241,8 @@
                     loadImplementationsInDirectory(test, packageName, file, classes);
                 } else {
                     InputStream stream;
-                    if (urlPath.startsWith("http:")) {
-                        // load resources using http such as java webstart
+                    if (!isLocalFileSystem) {
+                        // load resources using http (and other protocols) such as java webstart

                         log.debug("The current jar is accessed via http");
                         URL urlStream = new URL(urlPath);
                         URLConnection con = urlStream.openConnection();
@@ -276,6 +279,12 @@
         if (log.isTraceEnabled()) {
             log.trace("Getting resource URL for package: " + packageName + " with classloader:
" + loader);
         }
+        
+        // If the URL is a jar, the URLClassloader.getResources() seems to require a trailing
slash.  The
+        // trailing slash is harmless for other URLs  
+        if (!packageName.endsWith("/")) {
+            packageName = packageName + "/";
+        }
         return loader.getResources(packageName);
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java?rev=804847&r1=804846&r2=804847&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/scan/DefaultPackageScanClassResolverTest.java
Mon Aug 17 04:11:24 2009
@@ -17,6 +17,8 @@
 package org.apache.camel.impl.scan;
 
 import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -120,5 +122,31 @@
         Set<Class> scanned = resolver.findImplementations(ScanTargetOne.class, scanPackage);
         validateMatchingSetContains(scanned,  ScanTargetTwo.class);
     }
+    
+    public void testFindByFilterPackageInJarUrl() throws Exception {
+        
+        ClassLoader savedClassLoader = null; 
+        try {
+            savedClassLoader = Thread.currentThread().getContextClassLoader();
+            URL url = getClass().getResource("/package_scan_test.jar");
+            
+            URL urls[] = {new URL("jar:" + url.toString() + "!/")};
+            URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);
+
+            Thread.currentThread().setContextClassLoader(classLoader);
+
+            filter.addIncludePattern("a.*.c.*");
+            resolver.addFilter(filter);
+            Set<Class> scanned = resolver.findByFilter(filter, "a.b.c");
+            assertEquals(1, scanned.size());
+            assertEquals("class a.b.c.Test", scanned.iterator().next().toString());     
      
+        } finally {
+            if (savedClassLoader != null) {
+                Thread.currentThread().setContextClassLoader(savedClassLoader);
+            } 
+        }
+
+    }
+    
 
 }

Added: camel/trunk/camel-core/src/test/resources/package_scan_test.jar
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/package_scan_test.jar?rev=804847&view=auto
==============================================================================
Binary file - no diff available.

Propchange: camel/trunk/camel-core/src/test/resources/package_scan_test.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message