camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject [1/2] camel git commit: [CAMEL-9099] Correctly read META-INF/services/javax.script.ScriptEngineFactory
Date Tue, 25 Aug 2015 07:53:48 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 194bdaf0d -> 644e013cf
  refs/heads/master b49898de5 -> bc103e141


[CAMEL-9099] Correctly read META-INF/services/javax.script.ScriptEngineFactory


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

Branch: refs/heads/master
Commit: bc103e141cae698091a3ea2c36ec44471d926486
Parents: b49898d
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
Authored: Tue Aug 25 09:38:40 2015 +0200
Committer: Grzegorz Grzybek <gr.grzybek@gmail.com>
Committed: Tue Aug 25 09:38:40 2015 +0200

----------------------------------------------------------------------
 components/camel-script/pom.xml                 |  5 ++
 .../org/apache/camel/script/osgi/Activator.java | 13 +++-
 .../apache/camel/script/osgi/ActivatorTest.java | 74 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bc103e14/components/camel-script/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-script/pom.xml b/components/camel-script/pom.xml
index 00d4b2e..41417a0 100644
--- a/components/camel-script/pom.xml
+++ b/components/camel-script/pom.xml
@@ -115,6 +115,11 @@
             <artifactId>slf4j-log4j12</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/camel/blob/bc103e14/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 0db41a4..33365b2 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
@@ -224,7 +224,18 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer,
Serv
         private ScriptEngineFactory getFactory() {
             try {
                 BufferedReader in = IOHelper.buffered(new InputStreamReader(configFile.openStream()));
-                String className = in.readLine();
+                String className = null;
+                while ((className = in.readLine()) != null) {
+                    if ("".equals(className.trim()) || className.trim().startsWith("#"))
{
+                        continue;
+                    } else if (className.contains("#")) {
+                        className = className.substring(0, className.indexOf('#')).trim();
+                        break;
+                    } else {
+                        className = className.trim();
+                        break;
+                    }
+                }
                 in.close();
                 Class<?> cls = bundle.loadClass(className);
                 if (!ScriptEngineFactory.class.isAssignableFrom(cls)) {

http://git-wip-us.apache.org/repos/asf/camel/blob/bc103e14/components/camel-script/src/test/java/org/apache/camel/script/osgi/ActivatorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/test/java/org/apache/camel/script/osgi/ActivatorTest.java
b/components/camel-script/src/test/java/org/apache/camel/script/osgi/ActivatorTest.java
new file mode 100644
index 0000000..b2719df
--- /dev/null
+++ b/components/camel-script/src/test/java/org/apache/camel/script/osgi/ActivatorTest.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.script.osgi;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import javax.script.ScriptEngineFactory;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.ReturnValues;
+import org.mockito.internal.stubbing.answers.AnswerReturnValuesAdapter;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+public class ActivatorTest {
+
+    public static Logger LOG = LoggerFactory.getLogger(ActivatorTest.class);
+
+    private Bundle mockBundle;
+
+    @Before
+    public void mockBundle() throws ClassNotFoundException {
+        mockBundle = Mockito.mock(Bundle.class);
+        when(mockBundle.loadClass(anyString())).thenAnswer(new Answer() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                return ActivatorTest.class.getClassLoader().loadClass(invocation.getArguments()[0].toString());
+            }
+        });
+    }
+
+    @Test
+    public void findScriptEngines() throws IOException {
+        Enumeration<URL> urls = getClass().getClassLoader().getResources(Activator.META_INF_SERVICES_DIR
+ "/" + Activator.SCRIPT_ENGINE_SERVICE_FILE);
+        assertThat(urls.hasMoreElements(), is(true));
+        while (urls.hasMoreElements()) {
+            URL url = urls.nextElement();
+            LOG.info("Found {}", url);
+            System.out.println("Found: " + url);
+            Activator.BundleScriptEngineResolver resolver = new Activator.BundleScriptEngineResolver(mockBundle,
url);
+            ScriptEngineFactory factory = ReflectionTestUtils.invokeMethod(resolver, "getFactory");
+            System.out.println("Factory: " + factory);
+            assertNotNull(factory);
+        }
+    }
+
+}


Mime
View raw message