camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [6/6] camel git commit: CAMEL-9112: camel-script should not fail if script engine problem in OSGi. camel-script feature should not load groovy/jruby by default, use the camel-script-groovy / camel-script-jruby if you want to use them. Fixed the itest.
Date Sat, 26 Sep 2015 08:35:04 GMT
CAMEL-9112: camel-script should not fail if script engine problem in OSGi. camel-script feature
should not load groovy/jruby by default, use the camel-script-groovy / camel-script-jruby
if you want to use them. Fixed the itest.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8e8f7aa4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8e8f7aa4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8e8f7aa4

Branch: refs/heads/master
Commit: 8e8f7aa4c4468f50715c97b02c209cc61995aa38
Parents: 415b41b
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Sep 26 10:36:31 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Sep 26 10:36:31 2015 +0200

----------------------------------------------------------------------
 .../builder/script/ScriptLanguageResolver.java  |  2 +-
 .../org/apache/camel/script/osgi/Activator.java | 46 +++++++++++---------
 .../features/src/main/resources/features.xml    |  6 +--
 .../camel/itest/karaf/AbstractFeatureTest.java  | 16 ++++++-
 .../camel/itest/karaf/CamelScriptTest.java      |  4 +-
 5 files changed, 45 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8e8f7aa4/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
index a258243..a6c04c7 100644
--- a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
+++ b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptLanguageResolver.java
@@ -26,7 +26,7 @@ import org.apache.camel.spi.LanguageResolver;
 public class ScriptLanguageResolver implements LanguageResolver {
 
     public Language resolveLanguage(String name, CamelContext context) {
-        // only return if we can suppor the language
+        // only return if we can support the language
         if (ScriptBuilder.supportScriptLanguage(name)) {
             return new ScriptLanguage(name);
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/8e8f7aa4/components/camel-script/src/main/java/org/apache/camel/script/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/main/java/org/apache/camel/script/osgi/Activator.java
b/components/camel-script/src/main/java/org/apache/camel/script/osgi/Activator.java
index 33365b2..0e6bd66 100644
--- a/components/camel-script/src/main/java/org/apache/camel/script/osgi/Activator.java
+++ b/components/camel-script/src/main/java/org/apache/camel/script/osgi/Activator.java
@@ -21,13 +21,13 @@ import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineFactory;
 
@@ -210,13 +210,14 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer,
Serv
             return getScriptNames(getFactory());
         }
 
+        @SuppressWarnings("unchecked")
         private List<String> getScriptNames(ScriptEngineFactory factory) {
-            List<String> names = null;
+            List<String> names;
             if (factory != null) {
                 names = factory.getNames();
             } else {
                 // return an empty script name list
-                names = new ArrayList<String>(0);
+                names = Collections.EMPTY_LIST;
             }
             return names;
         }
@@ -224,7 +225,7 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer,
Serv
         private ScriptEngineFactory getFactory() {
             try {
                 BufferedReader in = IOHelper.buffered(new InputStreamReader(configFile.openStream()));
-                String className = null;
+                String className;
                 while ((className = in.readLine()) != null) {
                     if ("".equals(className.trim()) || className.trim().startsWith("#"))
{
                         continue;
@@ -238,8 +239,9 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer,
Serv
                 }
                 in.close();
                 Class<?> cls = bundle.loadClass(className);
+                // OSGi classloading trouble (with jruby)
                 if (!ScriptEngineFactory.class.isAssignableFrom(cls)) {
-                    throw new IllegalStateException("Invalid ScriptEngineFactory: " + cls.getName());
+                    return null;
                 }
                 return (ScriptEngineFactory) cls.newInstance();
             } catch (Exception e) {
@@ -251,28 +253,32 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer,
Serv
         public ScriptEngine resolveScriptEngine(String name) {
             try {
                 ScriptEngineFactory factory = getFactory();
-                List<String> names = getScriptNames(factory);
-                for (String test : names) {
-                    if (test.equals(name)) {
-                        ClassLoader old = Thread.currentThread().getContextClassLoader();
-                        ScriptEngine engine;
-                        try {
-                            // JRuby seems to require the correct TCCL to call getScriptEngine
-                            Thread.currentThread().setContextClassLoader(factory.getClass().getClassLoader());
-                            engine = factory.getScriptEngine();
-                        } finally {
-                            Thread.currentThread().setContextClassLoader(old);
+                if (factory != null) {
+                    List<String> names = getScriptNames(factory);
+                    for (String test : names) {
+                        if (test.equals(name)) {
+                            ClassLoader old = Thread.currentThread().getContextClassLoader();
+                            ScriptEngine engine;
+                            try {
+                                // JRuby seems to require the correct TCCL to call getScriptEngine
+                                Thread.currentThread().setContextClassLoader(factory.getClass().getClassLoader());
+                                engine = factory.getScriptEngine();
+                            } finally {
+                                Thread.currentThread().setContextClassLoader(old);
+                            }
+                            LOG.trace("Resolved ScriptEngineFactory: {} for expected name:
{}", engine, name);
+                            return engine;
                         }
-                        LOG.trace("Resolved ScriptEngineFactory: {} for expected name: {}",
engine, name);
-                        return engine;
                     }
+                    LOG.debug("ScriptEngineFactory: {} does not match expected name: {}",
factory.getEngineName(), name);
+                    return null;
                 }
-                LOG.debug("ScriptEngineFactory: {} does not match expected name: {}", factory.getEngineName(),
name);
-                return null;
             } catch (Exception e) {
                 LOG.warn("Cannot create ScriptEngineFactory: " + e.getClass().getName(),
e);
                 return null;
             }
+
+            return null;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/8e8f7aa4/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 16aa8d1..36e8ca8 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1308,20 +1308,18 @@
   <feature name='camel-script-javascript' version='${project.version}' resolver='(obr)'
start-level='50'>
     <bundle>mvn:com.google.code.scriptengines/scriptengines-javascript/${scriptengines-version}</bundle>
     <bundle dependency='true'>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.scripting-api-1.0/${servicemix-specs-version}</bundle>
-    <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.rhino/${rhino-bundle-version}</bundle>
+    <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.rhino/${rhino-bundle-version}</bundle>
   </feature>
   <feature name='camel-script-groovy' version='${project.version}' resolver='(obr)' start-level='50'>
     <bundle>mvn:com.google.code.scriptengines/scriptengines-groovy/${scriptengines-version}</bundle>
     <bundle dependency='true'>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.scripting-api-1.0/${servicemix-specs-version}</bundle>
-    <bundle>mvn:org.codehaus.groovy/groovy-all/${groovy-version}</bundle>
+    <bundle dependency='true'>mvn:org.codehaus.groovy/groovy-all/${groovy-version}</bundle>
   </feature>
   <feature name='camel-script' version='${project.version}' resolver='(obr)' start-level='50'>
     <feature version='${project.version}'>camel-core</feature>
     <bundle dependency='true'>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.scripting-api-1.0/${servicemix-specs-version}</bundle>
     <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/${antlr-bundle-version}</bundle>
     <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.rhino/${rhino-bundle-version}</bundle>
-    <bundle>mvn:org.codehaus.groovy/groovy-all/${groovy-version}</bundle>
-    <bundle dependency='true'>mvn:org.jruby/jruby-complete/${jruby-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-script/${project.version}</bundle>
   </feature>
   <feature name='camel-servlet' version='${project.version}' resolver='(obr)' start-level='50'>

http://git-wip-us.apache.org/repos/asf/camel/blob/8e8f7aa4/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
index 2e7272d..524198b 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
@@ -20,6 +20,8 @@ import java.io.File;
 import java.io.InputStream;
 import java.lang.reflect.Field;
 import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 import javax.inject.Inject;
@@ -206,11 +208,21 @@ public abstract class AbstractFeatureTest {
         return mavenOption;
     }
 
-    public static Option[] configure(String feature) {
+    public static Option[] configure(String mainFeature, String... extraFeatures) {
         switchPlatformEncodingToUTF8();
         String karafVersion = getKarafVersion();
         LOG.info("*** The karaf version is " + karafVersion + " ***");
 
+        List<String> list = new ArrayList<String>();
+        list.add("cxf-jaxb");
+        list.add("camel-core");
+        list.add("camel-spring");
+        list.add("camel-" + mainFeature);
+        for (String extra : extraFeatures) {
+            list.add("camel-" + extra);
+        }
+        String[] features = list.toArray(new String[list.size()]);
+
         Option[] options = new Option[] {
             // for remote debugging
             //org.ops4j.pax.exam.CoreOptions.vmOption("-Xdebug"),
@@ -239,7 +251,7 @@ public abstract class AbstractFeatureTest {
 
 
             // install the cxf jaxb spec as the karaf doesn't provide it by default
-            KarafDistributionOption.features(getCamelKarafFeatureUrl(), "cxf-jaxb", "camel-core",
"camel-spring", "camel-" + feature)
+            KarafDistributionOption.features(getCamelKarafFeatureUrl(), features)
         };
 
         return options;

http://git-wip-us.apache.org/repos/asf/camel/blob/8e8f7aa4/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelScriptTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelScriptTest.java
b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelScriptTest.java
index 6348567..3e43264 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelScriptTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelScriptTest.java
@@ -29,12 +29,12 @@ public class CamelScriptTest extends AbstractFeatureTest {
 
     @Test
     public void test() throws Exception {
-        testLanguage(COMPONENT);
+        testLanguage("Groovy");
     }
 
     @Configuration
     public static Option[] configure() {
-        return configure(COMPONENT);
+        return configure(COMPONENT, "script-groovy");
     }
 
 }
\ No newline at end of file


Mime
View raw message