incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r690922 - /incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
Date Mon, 01 Sep 2008 09:33:10 GMT
Author: bdelacretaz
Date: Mon Sep  1 02:33:09 2008
New Revision: 690922

URL: http://svn.apache.org/viewvc?rev=690922&view=rev
Log:
SLING-636 - Log more info about script engine extension mappings

Modified:
    incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java

Modified: incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java?rev=690922&r1=690921&r2=690922&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
(original)
+++ incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
Mon Sep  1 02:33:09 2008
@@ -21,8 +21,11 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineFactory;
@@ -107,23 +110,47 @@
             ScriptEngineManager tmp = new ScriptEngineManager(loader);
 
             // register script engines from bundles
+            final SortedSet<Object> extensions = new TreeSet<Object>(); 
             for (Bundle bundle : engineSpiBundles) {
-                registerFactories(tmp, bundle);
+                extensions.addAll(registerFactories(tmp, bundle));
             }
 
             // register script engines from registered services
             for (ScriptEngineFactory factory : engineSpiServices) {
-                registerFactory(tmp, factory);
+                extensions.addAll(registerFactory(tmp, factory));
             }
 
             scriptEngineManager = tmp;
+            
+            // Log messages to verify which ScriptEngine is actually used
+            // for our registered extensions
+            if(log.isInfoEnabled()) {
+                for(Object o : extensions) {
+                    final String ext = o.toString();
+                    final ScriptEngine e = scriptEngineManager.getEngineByExtension(ext);
+                    if(e == null) {
+                        log.warn("No ScriptEngine found for extension '{}' that was just
registered", ext);
+                    } else {
+                        log.info(
+                                "Script extension '{}' is now handled by ScriptEngine '{}',
version='{}', class='{}'",
+                                new Object [] {
+                                        ext,
+                                        e.getFactory().getEngineName(),
+                                        e.getFactory().getEngineVersion(),
+                                        e.getClass().getName()
+                                }
+                                );
+                    }
+                }
+            }
         }
         return scriptEngineManager;
     }
 
-    private void registerFactories(ScriptEngineManager mgr, Bundle bundle) {
+    private Collection<?> registerFactories(ScriptEngineManager mgr, Bundle bundle)
{
         URL url = bundle.getEntry(ENGINE_FACTORY_SERVICE);
         InputStream ins = null;
+        final SortedSet<String> extensions = new TreeSet<String>(); 
         try {
             ins = url.openStream();
             BufferedReader reader = new BufferedReader(new InputStreamReader(
@@ -135,6 +162,7 @@
                     Class<ScriptEngineFactory> clazz = bundle.loadClass(line);
                     ScriptEngineFactory spi = clazz.newInstance();
                     registerFactory(mgr, spi);
+                    extensions.addAll(spi.getExtensions());
                 } catch (Throwable t) {
                     log.error("Cannot register ScriptEngineFactory " + line, t);
                 }
@@ -148,9 +176,11 @@
                 }
             }
         }
+        
+        return extensions;
     }
 
-    private void registerFactory(ScriptEngineManager mgr,
+    private Collection<?> registerFactory(ScriptEngineManager mgr,
             ScriptEngineFactory factory) {
         log.info("Adding ScriptEngine {}, {} for language {}, {}",
             new Object[] { factory.getEngineName(), factory.getEngineVersion(),
@@ -167,6 +197,8 @@
         for (Object name : factory.getNames()) {
             mgr.registerEngineName((String) name, factory);
         }
+        
+        return factory.getExtensions();
     }
 
     // ---------- BundleListener interface -------------------------------------



Mime
View raw message