camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r749648 [2/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/impl/converter/ ...
Date Tue, 03 Mar 2009 16:39:04 GMT
Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
(original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
Tue Mar  3 16:39:03 2009
@@ -17,21 +17,20 @@
 package org.apache.camel.osgi;
 
 import org.apache.camel.impl.converter.AnnotationTypeConverterLoader;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.BundleContext;
 
 public class OsgiAnnotationTypeConverterLoader extends AnnotationTypeConverterLoader {
     private static final transient Log LOG = LogFactory.getLog(OsgiAnnotationTypeConverterLoader.class);
-    
-    public OsgiAnnotationTypeConverterLoader(BundleContext context) {
-        super(new OsgiResolverUtil(context));
+
+    public OsgiAnnotationTypeConverterLoader(PackageScanClassResolver packageScanClassResolver)
{
+        super(packageScanClassResolver);
     }
-    
+
     protected String[] findPackageNames() {
         return Activator.findTypeConverterPackageNames();
     }
-    
-    
 
 }

Copied: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
(from r749569, camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java?p2=camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java&p1=camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java&r1=749569&r2=749648&rev=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java
(original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
Tue Mar  3 16:39:03 2009
@@ -22,25 +22,19 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.camel.util.ResolverUtil;
-import org.apache.camel.util.ResolverUtil.Test;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
+import org.apache.camel.spi.PackageScanFilter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
 
-public class OsgiResolverUtil extends ResolverUtil {
+public class OsgiPackageScanClassResolver extends DefaultPackageScanClassResolver {
     private Bundle bundle;
     
-    public OsgiResolverUtil(BundleContext context) {
+    public OsgiPackageScanClassResolver(BundleContext context) {
         bundle = context.getBundle();
     }
-    
-    /**
-     * Returns the classloaders that will be used for scanning for classes. 
-     * Here we just add BundleDelegatingClassLoader here
-     *
-     * @return the ClassLoader instances that will be used to scan for classes
-     */
+
     public Set<ClassLoader> getClassLoaders() {
         Set<ClassLoader> classLoaders = super.getClassLoaders();
         // Using the Activator's bundle to make up a class loader
@@ -49,54 +43,37 @@
         return classLoaders;
     }
     
-    /**
-     * Scans for classes starting at the package provided and descending into
-     * subpackages. Each class is offered up to the Test as it is discovered,
-     * and if the Test returns true the class is retained. Accumulated classes
-     * can be fetched by calling {@link #getClasses()}.
-     *
-     * @param test        an instance of {@link Test} that will be used to filter
-     *                    classes
-     * @param packageName the name of the package from which to start scanning
-     *                    for classes, e.g. {@code net.sourceforge.stripes}
-     */
-    public void find(Test test, String packageName) {
+    public void find(PackageScanFilter test, String packageName, Set<Class> classes)
{
         packageName = packageName.replace('.', '/');
-
         Set<ClassLoader> set = getClassLoaders();
-
         ClassLoader osgiClassLoader = getOsgiClassLoader(set);
 
         if (osgiClassLoader != null) {
             // if we have an osgi bundle loader use this one only
             LOG.debug("Using only osgi bundle classloader");
-            findInOsgiClassLoader(test, packageName, osgiClassLoader);
+            findInOsgiClassLoader(test, packageName, osgiClassLoader, classes);
         } else {
             LOG.debug("Using only regular classloaders");
             for (ClassLoader classLoader : set) {
                 if (!isOsgiClassloader(classLoader)) {
-                    find(test, packageName, classLoader);
+                    find(test, packageName, classLoader, classes);
                 }
             }
         }
     }
 
-    
-    private void findInOsgiClassLoader(Test test, String packageName, ClassLoader osgiClassLoader)
{
+    private void findInOsgiClassLoader(PackageScanFilter test, String packageName, ClassLoader
osgiClassLoader, Set<Class> classes) {
         try {
             Method mth = osgiClassLoader.getClass().getMethod("getBundle", new Class[]{});
             if (mth != null) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Loading from osgi buindle using classloader: " + osgiClassLoader);
                 }
-                loadImplementationsInBundle(test, packageName, osgiClassLoader, mth);
-                return;
+                loadImplementationsInBundle(test, packageName, osgiClassLoader, mth, classes);
             }
         } catch (NoSuchMethodException e) {
             LOG.warn("It's not an osgi bundle classloader: " + osgiClassLoader);
-            return;
         }
-        
     }
 
     /**
@@ -126,13 +103,13 @@
         return false;
     }
     
-    private void loadImplementationsInBundle(Test test, String packageName, ClassLoader loader,
Method mth) {
+    private void loadImplementationsInBundle(PackageScanFilter test, String packageName,
ClassLoader loader, Method mth, Set<Class> classes) {
         // Use an inner class to avoid a NoClassDefFoundError when used in a non-osgi env
         Set<String> urls = OsgiUtil.getImplementationsInBundle(test, packageName, loader,
mth);
         if (urls != null) {
             for (String url : urls) {
                 // substring to avoid leading slashes
-                addIfMatching(test, url);
+                addIfMatching(test, url, classes);
             }
         }
     }
@@ -141,7 +118,8 @@
         private OsgiUtil() {
             // Helper class
         }
-        static Set<String> getImplementationsInBundle(Test test, String packageName,
ClassLoader loader, Method mth) {
+        @SuppressWarnings("unchecked")
+        static Set<String> getImplementationsInBundle(PackageScanFilter test, String
packageName, ClassLoader loader, Method mth) {
             try {
                 org.osgi.framework.Bundle bundle = (org.osgi.framework.Bundle) mth.invoke(loader);
                 org.osgi.framework.Bundle[] bundles = bundle.getBundleContext().getBundles();
@@ -154,7 +132,6 @@
                     while (paths != null && paths.hasMoreElements()) {
                         URL path = paths.nextElement();
                         String pathString = path.getPath();
-                        pathString.indexOf(packageName);
                         urls.add(pathString.substring(pathString.indexOf(packageName)));
                     }
                 }

Propchange: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelOsgiTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelOsgiTestSupport.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelOsgiTestSupport.java
(original)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelOsgiTestSupport.java
Tue Mar  3 16:39:03 2009
@@ -24,6 +24,7 @@
 public class CamelOsgiTestSupport extends TestCase {
     private Activator testActivator;
     private MockBundleContext bundleContext = new MockBundleContext();
+    private OsgiPackageScanClassResolver resolver = new OsgiPackageScanClassResolver(bundleContext);
     private MockBundle bundle = new CamelMockBundle();
     
     public void setUp() throws Exception {        
@@ -44,4 +45,7 @@
         return bundleContext;
     }
 
+    public OsgiPackageScanClassResolver getResolver() {
+        return resolver;
+    }
 }

Modified: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoaderTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoaderTest.java
(original)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoaderTest.java
Tue Mar  3 16:39:03 2009
@@ -21,7 +21,7 @@
 public class OsgiAnnotationTypeConverterLoaderTest extends CamelOsgiTestSupport {
     
     public void testLoad() throws Exception {
-        OsgiAnnotationTypeConverterLoader loader = new OsgiAnnotationTypeConverterLoader(getBundleContext());
+        OsgiAnnotationTypeConverterLoader loader = new OsgiAnnotationTypeConverterLoader(getResolver());
         MockTypeConverterRegistry registry = new MockTypeConverterRegistry();
         loader.load(registry);
         assertEquals("There should have a fallback converter", registry.getFallbackTypeConverters().size(),
1);

Modified: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiResolverUtilTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiResolverUtilTest.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiResolverUtilTest.java
(original)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiResolverUtilTest.java
Tue Mar  3 16:39:03 2009
@@ -17,8 +17,6 @@
 package org.apache.camel.osgi;
 
 import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
 import java.util.Set;
 
 import org.apache.camel.Converter;
@@ -30,21 +28,19 @@
 public class OsgiResolverUtilTest extends CamelOsgiTestSupport {
     public void testOsgiResolverFindAnnotatedTest() throws IOException {
         BundleContext  context = getActivator().getBundle().getBundleContext();
-        OsgiResolverUtil resolver  = new OsgiResolverUtil(context);
+        OsgiPackageScanClassResolver resolver  = new OsgiPackageScanClassResolver(context);
              
         String[] packageNames = {"org.apache.camel.osgi.test"};
-        resolver.findAnnotated(Converter.class, packageNames);
-        Set<Class> classes = resolver.getClasses();
+        Set<Class> classes = resolver.findAnnotated(Converter.class, packageNames);
         assertEquals("There should find a class", classes.size(), 1);
         assertTrue("Find a wrong class", classes.contains(MyTypeConverter.class));
     }
     
     public void testOsgiResolverFindImplementationTest() {
         BundleContext  context = getActivator().getBundle().getBundleContext();
-        OsgiResolverUtil resolver  = new OsgiResolverUtil(context);
+        OsgiPackageScanClassResolver resolver  = new OsgiPackageScanClassResolver(context);
         String[] packageNames = {"org.apache.camel.osgi.test"};
-        resolver.findImplementations(Routes.class, packageNames);
-        Set<Class> classes = resolver.getClasses();
+        Set<Class> classes = resolver.findImplementations(Routes.class, packageNames);
         assertEquals("There should find a class", classes.size(), 1);
         assertTrue("Find a wrong class", classes.contains(MyRouteBuilder.class));
     }

Modified: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
(original)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
Tue Mar  3 16:39:03 2009
@@ -19,8 +19,9 @@
 import junit.framework.TestCase
 import junit.framework.Assert._
 
-import org.apache.camel.util.ReflectionInjector
+import org.apache.camel.impl.DefaultPackageScanClassResolver
 import org.apache.camel.impl.converter.DefaultTypeConverter
+import org.apache.camel.util.ReflectionInjector
 
 import org.w3c.dom.Document
 
@@ -29,7 +30,7 @@
  */
 class ScalaTypeConverterTest extends TestCase {
   
-  val converter = new DefaultTypeConverter(new ReflectionInjector())
+  val converter = new DefaultTypeConverter(new DefaultPackageScanClassResolver(), new ReflectionInjector())
   
   def testDocumentConverter = {
     val result = converter.convertTo(classOf[Document], <persons/>)

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Tue Mar  3 16:39:03 2009
@@ -47,10 +47,11 @@
 import org.apache.camel.processor.interceptor.Delayer;
 import org.apache.camel.processor.interceptor.TraceFormatter;
 import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.util.ProcessorTypeHelper;
-import org.apache.camel.util.ResolverUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.DisposableBean;
@@ -151,6 +152,16 @@
     public void afterPropertiesSet() throws Exception {
         // TODO there should be a neater way to do this!
 
+        // set the resolvers first
+        PackageScanClassResolver packageResolver = getBeanForType(PackageScanClassResolver.class);
+        if (packageResolver != null) {
+            getContext().setPackageScanClassResolver(packageResolver);
+        }
+        ClassResolver classResolver = getBeanForType(ClassResolver.class);
+        if (classResolver != null) {
+            getContext().setClassResolver(classResolver);
+        }
+
         Debugger debugger = getBeanForType(Debugger.class);
         if (debugger != null) {
             getContext().addInterceptStrategy(debugger);
@@ -521,19 +532,12 @@
      */
     protected void findRouteBuilders() throws Exception, InstantiationException {
         if (getPackages() != null && getPackages().length > 0) {
-            RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), getPackages(),
getContextClassLoaderOnStart(), getBeanPostProcessor(), createResolverUtil());
+            RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), getPackages(),
getContextClassLoaderOnStart(),
+                    getBeanPostProcessor(), getContext().getPackageScanClassResolver());
             finder.appendBuilders(getAdditionalBuilders());
         }
     }
     
-    /**
-     * The factory method for create the ResolverUtil
-     * @return a new instance of ResolverUtil
-     */
-    protected ResolverUtil createResolverUtil() {
-        return new ResolverUtil();
-    }
-
     public void setDataFormats(DataFormatsType dataFormats) {
         this.dataFormats = dataFormats;
     }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/RouteBuilderFinder.java
Tue Mar  3 16:39:03 2009
@@ -23,7 +23,7 @@
 
 import org.apache.camel.Routes;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.util.ResolverUtil;
+import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -38,30 +38,22 @@
     private static final transient Log LOG = LogFactory.getLog(RouteBuilderFinder.class);
     private final SpringCamelContext camelContext;
     private final String[] packages;
-    private ResolverUtil resolver;
+    private PackageScanClassResolver resolver;
     private ApplicationContext applicationContext;    
     private BeanPostProcessor beanPostProcessor;
 
     @SuppressWarnings("unchecked")
-    public RouteBuilderFinder(SpringCamelContext camelContext, String[] packages, ClassLoader
classLoader, BeanPostProcessor postProcessor, ResolverUtil resolverUtil) {
+    public RouteBuilderFinder(SpringCamelContext camelContext, String[] packages, ClassLoader
classLoader,
+                              BeanPostProcessor postProcessor, PackageScanClassResolver resolver)
{
         this.camelContext = camelContext;
         this.applicationContext = camelContext.getApplicationContext();
         this.packages = packages;
         this.beanPostProcessor = postProcessor;
-        this.resolver = resolverUtil;
-        // lets add all the available class loaders just in case of weirdness
-        // we could make this more strict once we've worked out all the gremlins
-        // in servicemix-camel
-        Set set = resolver.getClassLoaders();
-        set.clear();
-        set.add(classLoader);
-/*
-        set.add(classLoader);
-        set.add(applicationContext.getClassLoader());
-        set.add(getClass().getClassLoader());
-*/
+        this.resolver = resolver;
+        // add our provided loader as well
+        resolver.addClassLoader(classLoader);
     }
-  
+
     public String[] getPackages() {
         return packages;
     }
@@ -70,13 +62,11 @@
         return applicationContext;
     }
 
-
     /**
      * Appends all the {@link RouteBuilder} instances that can be found on the classpath
      */
     public void appendBuilders(List<Routes> list) throws IllegalAccessException, InstantiationException
{
-        resolver.findImplementations(Routes.class, packages);
-        Set<Class> classes = resolver.getClasses();
+        Set<Class> classes = resolver.findImplementations(Routes.class, packages);
         for (Class aClass : classes) {
             if (shouldIgnoreBean(aClass)) {
                 continue;

Modified: camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java
URL: http://svn.apache.org/viewvc/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java?rev=749648&r1=749647&r2=749648&view=diff
==============================================================================
--- camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java
(original)
+++ camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ConvertersMojo.java
Tue Mar  3 16:39:03 2009
@@ -31,6 +31,7 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.impl.ReportingTypeConverterLoader;
 import org.apache.camel.impl.ReportingTypeConverterLoader.TypeMapping;
 import org.apache.camel.impl.ReportingTypeConverterRegistry;
@@ -212,8 +213,7 @@
         } catch (RendererException e) {
             throw new MojoExecutionException("Error while rendering report.", e);
         } catch (MojoFailureException e) {
-            throw new MojoExecutionException(
-                    "Cannot find skin artifact for report.", e);
+            throw new MojoExecutionException("Cannot find skin artifact for report.", e);
         } catch (MavenReportException e) {
             throw new MojoExecutionException("Error generating report.", e);
         }
@@ -244,12 +244,10 @@
             ClassLoader newClassLoader = mojo.createClassLoader(oldClassLoader);
             Thread.currentThread().setContextClassLoader(newClassLoader);
 
-            ReportingTypeConverterLoader loader = new ReportingTypeConverterLoader();
+            ReportingTypeConverterLoader loader = new ReportingTypeConverterLoader(new DefaultPackageScanClassResolver());
             ReportingTypeConverterRegistry registry = new ReportingTypeConverterRegistry();
             loader.load(registry);
-            getLog().error(
-                    "FOUND type mapping; count = "
-                            + loader.getTypeConversions().length);
+            getLog().error("FOUND type mapping; count = " + loader.getTypeConversions().length);
 
             String[] errors = registry.getErrors();
             for (String error : errors) {
@@ -268,16 +266,12 @@
     private boolean createOutputDirectory(final File outputDir) {
         if (outputDir.exists()) {
             if (!outputDir.isDirectory()) {
-                getLog().error(
-                        "File with same name already exists: "
-                                + outputDir.getAbsolutePath());
+                getLog().error("File with same name already exists: " + outputDir.getAbsolutePath());
                 return false;
             }
         } else {
             if (!outputDir.mkdirs()) {
-                getLog().error(
-                        "Cannot make output directory at: "
-                                + outputDir.getAbsolutePath());
+                getLog().error("Cannot make output directory at: " + outputDir.getAbsolutePath());
                 return false;
             }
         }



Mime
View raw message