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-karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 5eb4b18  CAMEL-14936: camel-core - Remove optional prefix in 
FactoryFinder
5eb4b18 is described below

commit 5eb4b189f48cb61062e3194c52975ba324784b85
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Apr 21 14:40:48 2020 +0200

    CAMEL-14936: camel-core - Remove optional prefix in FactoryFinder
---
 .../apache/camel/core/osgi/OsgiFactoryFinder.java  | 37 ++++------------------
 .../camel/core/osgi/OsgiFactoryFinderTest.java     | 15 ++-------
 .../services/org/apache/camel/component/file_test  |  3 +-
 3 files changed, 9 insertions(+), 46 deletions(-)

diff --git 
a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
 
b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
index ca6adb7..89bae2a 100644
--- 
a/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
+++ 
b/core/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiFactoryFinder.java
@@ -43,12 +43,11 @@ public class OsgiFactoryFinder extends DefaultFactoryFinder 
{
     }
 
     @Override
-    public Optional<Class<?>> findClass(String key, String propertyPrefix, 
Class<?> checkClass) {
-        final String prefix = propertyPrefix != null ? propertyPrefix : "";
-        final String classKey = propertyPrefix + key;
+    public Optional<Class<?>> findClass(String key) {
+        final String classKey = key;
 
         Class<?> answer = addToClassMap(classKey, () -> {
-            BundleEntry entry = getResource(key, checkClass);
+            BundleEntry entry = getResource(key);
             if (entry != null) {
                 URL url = entry.url;
                 InputStream in = url.openStream();
@@ -58,9 +57,9 @@ public class OsgiFactoryFinder extends DefaultFactoryFinder {
                     reader = IOHelper.buffered(in);
                     Properties properties = new Properties();
                     properties.load(reader);
-                    String className = properties.getProperty(prefix + 
"class");
+                    String className = properties.getProperty("class");
                     if (className == null) {
-                        throw new IOException("Expected property is missing: " 
+ prefix + "class");
+                        throw new IOException("Expected property is missing: 
class");
                     }
                     return entry.bundle.loadClass(className);
                 } finally {
@@ -75,20 +74,10 @@ public class OsgiFactoryFinder extends DefaultFactoryFinder 
{
         return Optional.ofNullable(answer);
     }
 
-    @Override
-    public Optional<Class<?>> findClass(String key, String propertyPrefix) {
-        return findClass(key, propertyPrefix, null);
-    }
-
     // As the META-INF of the Factory could not be export,
     // we need to go through the bundles to look for it
     // NOTE, the first found factory will be return
     public BundleEntry getResource(String name) {
-        return getResource(name, null);
-    }
-
-    // The clazz can make sure we get right version of class that we need
-    public BundleEntry getResource(String name, Class<?> clazz) {
         BundleEntry entry = null;
         Bundle[] bundles;
         
@@ -97,7 +86,7 @@ public class OsgiFactoryFinder extends DefaultFactoryFinder {
         URL url;
         for (Bundle bundle : bundles) {
             url = bundle.getEntry(getResourcePath() + name);
-            if (url != null && checkCompatibility(bundle, clazz)) {
+            if (url != null) {
                 entry = new BundleEntry();
                 entry.url = url;
                 entry.bundle = bundle;
@@ -108,19 +97,5 @@ public class OsgiFactoryFinder extends DefaultFactoryFinder 
{
         return entry;
     }
 
-    private boolean checkCompatibility(Bundle bundle, Class<?> clazz) {
-        if (clazz == null) {
-            return true;
-        }
-        // Check bundle compatibility
-        try {
-            if (bundle.loadClass(clazz.getName()) != clazz) {
-                return false;
-            }
-        } catch (Throwable t) {
-            return false;
-        }
-        return true;
-    }
 
 }
diff --git 
a/core/camel-core-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java
 
b/core/camel-core-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java
index 383a717..b79d9b6 100644
--- 
a/core/camel-core-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java
+++ 
b/core/camel-core-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.core.osgi;
 
-import java.io.IOException;
-
 import org.apache.camel.impl.engine.DefaultClassResolver;
 import org.junit.Test;
 
@@ -26,17 +24,8 @@ public class OsgiFactoryFinderTest extends 
CamelOsgiTestSupport {
     @Test
     public void testFindClass() throws Exception {
         OsgiFactoryFinder finder = new OsgiFactoryFinder(getBundleContext(), 
new DefaultClassResolver(), "META-INF/services/org/apache/camel/component/");
-        Class<?> clazz = finder.findClass("file_test", 
"strategy.factory.").orElse(null);
-        assertNotNull("We should get the file strategy factory here", clazz);
-        
-        assertFalse(finder.findClass("nofile", 
"strategy.factory.").isPresent());
-
-        try {
-            finder.findClass("file_test", "nostrategy.factory.");
-            fail("We should get exception here");
-        } catch (Exception ex) {
-            assertTrue("Should get IOException", ex.getCause() instanceof 
IOException);
-        }
+        Class<?> clazz = finder.findClass("file_test").orElse(null);
+        assertNotNull("We should get the file component here", clazz);
     }
 
 }
diff --git 
a/core/camel-core-osgi/src/test/resources/META-INF/services/org/apache/camel/component/file_test
 
b/core/camel-core-osgi/src/test/resources/META-INF/services/org/apache/camel/component/file_test
index 2172240..ef980b2 100644
--- 
a/core/camel-core-osgi/src/test/resources/META-INF/services/org/apache/camel/component/file_test
+++ 
b/core/camel-core-osgi/src/test/resources/META-INF/services/org/apache/camel/component/file_test
@@ -15,5 +15,4 @@
 # limitations under the License.
 #
 
-class=org.apache.camel.component.file.FileComponent
-strategy.factory.class=org.apache.camel.component.file.strategy.FileProcessStrategyFactory
\ No newline at end of file
+class=org.apache.camel.component.file.FileComponent
\ No newline at end of file

Reply via email to