camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r787148 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ components/camel-osgi/src/main/java/org/apache/camel/osgi/
Date Mon, 22 Jun 2009 06:13:01 GMT
Author: davsclaus
Date: Mon Jun 22 06:13:01 2009
New Revision: 787148

URL: http://svn.apache.org/viewvc?rev=787148&view=rev
Log:
CAMEL-1725: improved logging when using osgi or not.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPackageScanClassResolver.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java
    camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.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=787148&r1=787147&r2=787148&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 Jun 22 06:13:01 2009
@@ -48,7 +48,7 @@
  */
 public class DefaultPackageScanClassResolver implements PackageScanClassResolver {
 
-    protected static final transient Log LOG = LogFactory.getLog(DefaultPackageScanClassResolver.class);
+    protected final transient Log log = LogFactory.getLog(getClass());
     private Set<ClassLoader> classLoaders;
     private Set<PackageScanFilter> scanFilters;
 
@@ -68,8 +68,8 @@
             classLoaders = new HashSet<ClassLoader>();
             ClassLoader ccl = Thread.currentThread().getContextClassLoader();
             if (ccl != null) {
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("The thread context class loader: " + ccl + "  is used to load
the class");
+                if (log.isTraceEnabled()) {
+                    log.trace("The thread context class loader: " + ccl + "  is used to load
the class");
                 }
                 classLoaders.add(ccl);
             }
@@ -88,8 +88,8 @@
             return Collections.EMPTY_SET;
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Searching for annotations of " + annotation.getName() + " in packages:
" + Arrays.asList(packageNames));
+        if (log.isDebugEnabled()) {
+            log.debug("Searching for annotations of " + annotation.getName() + " in packages:
" + Arrays.asList(packageNames));
         }
 
         PackageScanFilter test = getCompositeFilter(new AnnotatedWithPackageScanFilter(annotation,
true));
@@ -98,8 +98,8 @@
             find(test, pkg, classes);
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found: " + classes);
+        if (log.isDebugEnabled()) {
+            log.debug("Found: " + classes);
         }
 
         return classes;
@@ -111,8 +111,8 @@
             return Collections.EMPTY_SET;
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Searching for annotations of " + annotations + " in packages: " +
Arrays.asList(packageNames));
+        if (log.isDebugEnabled()) {
+            log.debug("Searching for annotations of " + annotations + " in packages: " +
Arrays.asList(packageNames));
         }
 
         PackageScanFilter test = getCompositeFilter(new AnnotatedWithAnyPackageScanFilter(annotations,
true));
@@ -121,8 +121,8 @@
             find(test, pkg, classes);
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found: " + classes);
+        if (log.isDebugEnabled()) {
+            log.debug("Found: " + classes);
         }
 
         return classes;
@@ -134,8 +134,8 @@
             return Collections.EMPTY_SET;
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Searching for implementations of " + parent.getName() + " in packages:
" + Arrays.asList(packageNames));
+        if (log.isDebugEnabled()) {
+            log.debug("Searching for implementations of " + parent.getName() + " in packages:
" + Arrays.asList(packageNames));
         }
 
         PackageScanFilter test = getCompositeFilter(new AssignableToPackageScanFilter(parent));
@@ -144,8 +144,8 @@
             find(test, pkg, classes);
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found: " + classes);
+        if (log.isDebugEnabled()) {
+            log.debug("Found: " + classes);
         }
 
         return classes;
@@ -162,8 +162,8 @@
             find(filter, pkg, classes);
         }
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Found: " + classes);
+        if (log.isDebugEnabled()) {
+            log.debug("Found: " + classes);
         }
 
         return classes;
@@ -180,8 +180,8 @@
     }
 
     protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class>
classes) {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Searching for: " + test + " in package: " + packageName + " using
classloader: "
+        if (log.isTraceEnabled()) {
+            log.trace("Searching for: " + test + " in package: " + packageName + " using
classloader: "
                     + loader.getClass().getName());
         }
 
@@ -189,10 +189,10 @@
         try {
             urls = getResources(loader, packageName);
             if (!urls.hasMoreElements()) {
-                LOG.trace("No URLs returned by classloader");
+                log.trace("No URLs returned by classloader");
             }
         } catch (IOException ioe) {
-            LOG.warn("Could not read package: " + packageName, ioe);
+            log.warn("Could not read package: " + packageName, ioe);
             return;
         }
 
@@ -200,14 +200,14 @@
             URL url = null;
             try {
                 url = urls.nextElement();
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("URL from classloader: " + url);
+                if (log.isTraceEnabled()) {
+                    log.trace("URL from classloader: " + url);
                 }
 
                 String urlPath = url.getFile();
                 urlPath = URLDecoder.decode(urlPath, "UTF-8");
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("Decoded urlPath: " + urlPath);
+                if (log.isTraceEnabled()) {
+                    log.trace("Decoded urlPath: " + urlPath);
                 }
 
                 // If it's a file in a directory, trim the stupid file: spec
@@ -217,7 +217,7 @@
 
                 // osgi bundles should be skipped
                 if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:"))
{
-                    LOG.trace("It's a virtual osgi bundle, skipping");
+                    log.trace("It's a virtual osgi bundle, skipping");
                     continue;
                 }
 
@@ -226,21 +226,21 @@
                     urlPath = urlPath.substring(0, urlPath.indexOf('!'));
                 }
 
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("Scanning for classes in [" + urlPath + "] matching criteria:
" + test);
+                if (log.isTraceEnabled()) {
+                    log.trace("Scanning for classes in [" + urlPath + "] matching criteria:
" + test);
                 }
 
                 File file = new File(urlPath);
                 if (file.isDirectory()) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Loading from directory: " + file);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Loading from directory: " + file);
                     }
                     loadImplementationsInDirectory(test, packageName, file, classes);
                 } else {
                     InputStream stream;
                     if (urlPath.startsWith("http:")) {
                         // load resources using http such as java webstart
-                        LOG.debug("The current jar is accessed via http");
+                        log.debug("The current jar is accessed via http");
                         URL urlStream = new URL(urlPath);
                         URLConnection con = urlStream.openConnection();
                         // disable cache mainly to avoid jar file locking on Windows
@@ -250,13 +250,13 @@
                         stream = new FileInputStream(file);
                     }
 
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Loading from jar: " + file);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Loading from jar: " + file);
                     }
                     loadImplementationsInJar(test, packageName, stream, urlPath, classes);
                 }
             } catch (IOException ioe) {
-                LOG.warn("Could not read entries in url: " + url, ioe);
+                log.warn("Could not read entries in url: " + url, ioe);
             }
         }
     }
@@ -273,8 +273,8 @@
      * @throws IOException is thrown by the classloader
      */
     protected Enumeration<URL> getResources(ClassLoader loader, String packageName)
throws IOException {
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Getting resource URL for package: " + packageName + " with classloader:
" + loader);
+        if (log.isTraceEnabled()) {
+            log.trace("Getting resource URL for package: " + packageName + " with classloader:
" + loader);
         }
         return loader.getResources(packageName);
     }
@@ -350,10 +350,10 @@
                 }
             }
         } catch (IOException ioe) {
-            LOG.error("Could not search jar file '" + urlPath + "' for classes matching criteria:
" + test
+            log.error("Could not search jar file '" + urlPath + "' for classes matching criteria:
" + test
                 + " due to an IOException: " + ioe.getMessage(), ioe);
         } finally {
-            ObjectHelper.close(jarStream, urlPath, LOG);
+            ObjectHelper.close(jarStream, urlPath, log);
         }
     }
 
@@ -372,35 +372,35 @@
             Set<ClassLoader> set = getClassLoaders();
             boolean found = false;
             for (ClassLoader classLoader : set) {
-                if (LOG.isTraceEnabled()) {
-                    LOG.trace("Testing for class " + externalName + " matches criteria ["
+ test + "] using ClassLoader:" + classLoader);
+                if (log.isTraceEnabled()) {
+                    log.trace("Testing for class " + externalName + " matches criteria ["
+ test + "] using ClassLoader:" + classLoader);
                 }
                 try {
                     Class type = classLoader.loadClass(externalName);
-                    if (LOG.isTraceEnabled()) {
-                        LOG.trace("Loaded the class: " + type + " in classloader: " + classLoader);
+                    if (log.isTraceEnabled()) {
+                        log.trace("Loaded the class: " + type + " in classloader: " + classLoader);
                     }
                     if (test.matches(type)) {
-                        if (LOG.isTraceEnabled()) {
-                            LOG.trace("Found class: " + type + " which matches the filter
in classloader: " + classLoader);
+                        if (log.isTraceEnabled()) {
+                            log.trace("Found class: " + type + " which matches the filter
in classloader: " + classLoader);
                         }
                         classes.add(type);
                     }
                     found = true;
                     break;
                 } catch (ClassNotFoundException e) {
-                    LOG.debug("Could not find class '" + fqn + "' in classloader: " + classLoader
+                    log.debug("Could not find class '" + fqn + "' in classloader: " + classLoader
                         + ". Reason: " + e, e);
                 } catch (NoClassDefFoundError e) {
-                    LOG.debug("Could not find the class defintion '" + fqn + "' in classloader:
" + classLoader
+                    log.debug("Could not find the class defintion '" + fqn + "' in classloader:
" + classLoader
                               + ". Reason: " + e, e);
                 }
             }
             if (!found) {
-                LOG.warn("Could not find class '" + fqn + "' in any classloaders: " + set);
+                log.warn("Could not find class '" + fqn + "' in any classloaders: " + set);
             }
         } catch (Exception e) {
-            LOG.warn("Could not examine class '" + fqn + "' due to a " + e.getClass().getName()
+            log.warn("Could not examine class '" + fqn + "' due to a " + e.getClass().getName()
                 + " with message: " + e.getMessage(), e);
         }
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java?rev=787148&r1=787147&r2=787148&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/WebSpherePacakageScanClassResolver.java
Mon Jun 22 06:13:01 2009
@@ -63,7 +63,7 @@
         // try super first, just in vase
         Enumeration<URL> enumeration = super.getResources(loader, packageName);
         if (!enumeration.hasMoreElements()) {
-            LOG.trace("Using WebSphere workaround to load the camel jars with the annotated
converters.");
+            log.trace("Using WebSphere workaround to load the camel jars with the annotated
converters.");
             // Special WebSphere trick to load a file that exists in the JAR and then let
it go from there.
             // The trick is that we just need the URL's for the .jars that contains the type
             // converters that is annotated. So by searching for this resource WebSphere
is able to find

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=787148&r1=787147&r2=787148&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
Mon Jun 22 06:13:01 2009
@@ -45,10 +45,8 @@
                     LOG.debug("Loading converter class: " + ObjectHelper.name(type));
                 }
                 loadConverterMethods(registry, type);
-             }
-         }
+            }
+        }
     }
-    
-    
 
 }

Modified: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java?rev=787148&r1=787147&r2=787148&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
(original)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiPackageScanClassResolver.java
Mon Jun 22 06:13:01 2009
@@ -24,6 +24,8 @@
 
 import org.apache.camel.impl.DefaultPackageScanClassResolver;
 import org.apache.camel.spi.PackageScanFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
@@ -50,13 +52,13 @@
         int classesSize = classes.size(); 
         if (osgiClassLoader != null) {
             // if we have an osgi bundle loader use this one first
-            LOG.debug("Using only osgi bundle classloader");
+            log.debug("Using only osgi bundle classloader");
             findInOsgiClassLoader(test, packageName, osgiClassLoader, classes);
         }
         
         if (classes.size() == classesSize) {
             // Using the regular classloaders as a fallback
-            LOG.debug("Using only regular classloaders");
+            log.debug("Using only regular classloaders");
             for (ClassLoader classLoader : set.toArray(new ClassLoader[set.size()])) {
                 if (!isOsgiClassloader(classLoader)) {
                     find(test, packageName, classLoader, classes);
@@ -69,13 +71,13 @@
         try {
             Method mth = osgiClassLoader.getClass().getMethod("getBundle", new Class[]{});
             if (mth != null) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Loading from osgi bundle using classloader: " + osgiClassLoader);
+                if (log.isDebugEnabled()) {
+                    log.debug("Loading from osgi bundle using classloader: " + osgiClassLoader);
                 }
                 loadImplementationsInBundle(test, packageName, osgiClassLoader, mth, classes);
             }
         } catch (NoSuchMethodException e) {
-            LOG.warn("It's not an osgi bundle classloader: " + osgiClassLoader);
+            log.warn("It's not an osgi bundle classloader: " + osgiClassLoader);
         }
     }
 
@@ -118,6 +120,9 @@
     }
 
     private static final class OsgiUtil {
+
+        private static final transient Log LOG = LogFactory.getLog(OsgiUtil.class);
+
         private OsgiUtil() {
             // Helper class
         }



Mime
View raw message