You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/06/22 08:11:02 UTC

[camel] branch master updated: [CAMEL-13664]ensure the auto-generated TypeConverterLoader can be used in OSGi

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 879b972  [CAMEL-13664]ensure the auto-generated TypeConverterLoader can be used in OSGi
879b972 is described below

commit 879b97261fcd563c5ea927ad785bb062d5d30564
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Fri Jun 21 16:18:26 2019 -0400

    [CAMEL-13664]ensure the auto-generated TypeConverterLoader can be used in OSGi
---
 .../org/apache/camel/core/osgi/impl/Activator.java | 36 ++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/impl/Activator.java b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/impl/Activator.java
index ac1e0f5..115baa1 100644
--- a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/impl/Activator.java
+++ b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/impl/Activator.java
@@ -233,7 +233,35 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer<Objec
             URL url1 = bundle.getEntry(META_INF_TYPE_CONVERTER);
             URL url2 = bundle.getEntry(META_INF_TYPE_CONVERTER_LOADER);
             URL url3 = bundle.getEntry(META_INF_FALLBACK_TYPE_CONVERTER);
-            if (url1 != null || url2 != null || url3 != null) {
+            if (url2 != null) {
+                LOG.debug("Found TypeConverterLoader in bundle {}", bundle.getSymbolicName());
+                Set<Class<?>> classes = new LinkedHashSet<>();
+                Set<String> packages = getConverterPackages(bundle.getEntry(META_INF_TYPE_CONVERTER_LOADER));
+
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("Found {} {} packages: {}", packages.size(), META_INF_TYPE_CONVERTER_LOADER, packages);
+                }
+                for (String pkg : packages) {
+
+                    if (StringHelper.isClassName(pkg)) {
+                        // its a FQN class name so load it directly
+                        LOG.trace("Loading {} class", pkg);
+                        try {
+                            Class<?> clazz = bundle.loadClass(pkg);
+                            BundleTypeConverterLoader bundleTypeConverterLoader =
+                                new BundleTypeConverterLoader(bundle, url3 != null);
+                            bundleTypeConverterLoader.setTypeConverterLoader((TypeConverterLoader)clazz.newInstance());
+                            resolvers.add(bundleTypeConverterLoader);
+                            // the class could be found and loaded so continue to next
+                            continue;
+                        } catch (Throwable t) {
+                            // Ignore
+                            LOG.trace("Failed to load " + pkg + " class due " + t.getMessage() + ". This exception will be ignored.", t);
+                        }
+                    }
+                }
+                    
+            } else if (url1 != null || url3 != null) {
                 LOG.debug("Found TypeConverter in bundle {}", bundle.getSymbolicName());
                 resolvers.add(new BundleTypeConverterLoader(bundle, url3 != null));
             }
@@ -379,7 +407,7 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer<Objec
 
     protected static class BundleTypeConverterLoader extends BaseResolver<TypeConverter> implements TypeConverterLoader {
 
-        private final AnnotationTypeConverterLoader loader = new Loader();
+        private TypeConverterLoader loader = new Loader();
         private final Bundle bundle;
         private final boolean hasFallbackTypeConverter;
 
@@ -389,6 +417,10 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer<Objec
             this.bundle = bundle;
             this.hasFallbackTypeConverter = hasFallbackTypeConverter;
         }
+        
+        public void setTypeConverterLoader(TypeConverterLoader typeConverterloader) {
+            this.loader = typeConverterloader;
+        }
 
         public synchronized void load(TypeConverterRegistry registry) throws TypeConverterLoaderException {
             // must be synchronized to ensure we don't load type converters concurrently