You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ch...@apache.org on 2015/11/30 10:00:30 UTC

svn commit: r1717204 - /felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java

Author: chetanm
Date: Mon Nov 30 09:00:30 2015
New Revision: 1717204

URL: http://svn.apache.org/viewvc?rev=1717204&view=rev
Log:
FELIX-5120 - ScriptEngineManager not able to parse service file with comments at end of classname

Refactor logic to extract classnames

Modified:
    felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java

Modified: felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java?rev=1717204&r1=1717203&r2=1717204&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java (original)
+++ felix/trunk/webconsole-plugins/script-console/src/main/java/org/apache/felix/webconsole/plugins/scriptconsole/internal/ScriptEngineManager.java Mon Nov 30 09:00:30 2015
@@ -19,22 +19,35 @@
 
 package org.apache.felix.webconsole.plugins.scriptconsole.internal;
 
-import org.apache.commons.io.IOUtils;
-import org.osgi.framework.*;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineFactory;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+import org.apache.commons.io.IOUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
 /**
  * It is based on org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory
  */
@@ -187,25 +200,22 @@ class ScriptEngineManager implements Bun
         {
             ins = url.openStream();
             BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
-            String line;
-            while ((line = reader.readLine()) != null)
+            for (String className : getClassNames(reader))
             {
-                if (!line.startsWith("#") && line.trim().length() > 0)
+                try
                 {
-                    try
-                    {
-                        Class<ScriptEngineFactory> clazz = bundle.loadClass(line);
-                        ScriptEngineFactory spi = clazz.newInstance();
-                        registerFactory(mgr, spi, null);
-                        extensions.addAll(spi.getExtensions());
-                    }
-                    catch (Throwable t)
-                    {
-                        log.log(LogService.LOG_ERROR,
-                            "Cannot register ScriptEngineFactory " + line, t);
-                    }
+                    Class<ScriptEngineFactory> clazz = bundle.loadClass(className);
+                    ScriptEngineFactory spi = clazz.newInstance();
+                    registerFactory(mgr, spi, null);
+                    extensions.addAll(spi.getExtensions());
+                }
+                catch (Throwable t)
+                {
+                    log.log(LogService.LOG_ERROR,
+                            "Cannot register ScriptEngineFactory " + className, t);
                 }
             }
+
         }
         catch (IOException ioe)
         {
@@ -244,6 +254,19 @@ class ScriptEngineManager implements Bun
         }
     }
 
+    static List<String> getClassNames(BufferedReader reader) throws IOException {
+        List<String> classNames = new ArrayList<String>();
+        String line;
+        while ((line = reader.readLine()) != null)
+        {
+            if (!line.startsWith("#") && line.trim().length() > 0)
+            {
+                classNames.add(line);
+            }
+        }
+        return classNames;
+    }
+
     private static Map<Object, Object> getServiceProperties(ServiceReference reference)
     {
         Map<Object, Object> props = new HashMap<Object, Object>();