Author: cziegeler
Date: Mon Oct 17 12:40:48 2016
New Revision: 1765260

URL: http://svn.apache.org/viewvc?rev=1765260&view=rev
Log:
SLING-5784 : Use service property to identify the ServletContext registered by 
Sling

Modified:
    sling/trunk/contrib/scripting/java/pom.xml
    
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
    
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java

Modified: sling/trunk/contrib/scripting/java/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/pom.xml?rev=1765260&r1=1765259&r2=1765260&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/java/pom.xml (original)
+++ sling/trunk/contrib/scripting/java/pom.xml Mon Oct 17 12:40:48 2016
@@ -24,7 +24,7 @@
   <parent>
     <groupId>org.apache.sling</groupId>
     <artifactId>sling</artifactId>
-    <version>28</version>
+    <version>29</version>
     <relativePath />
   </parent>
 

Modified: 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java?rev=1765260&r1=1765259&r2=1765260&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
 (original)
+++ 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java
 Mon Oct 17 12:40:48 2016
@@ -71,8 +71,8 @@ import org.slf4j.LoggerFactory;
     @Property(name=JavaScriptEngineFactory.PROPERTY_COMPILER_TARGET_V_M, 
value=JavaScriptEngineFactory.VERSION_AUTO),
     @Property(name=JavaScriptEngineFactory.PROPERTY_CLASSDEBUGINFO, 
boolValue=true),
     @Property(name=JavaScriptEngineFactory.PROPERTY_ENCODING, value="UTF-8"),
-    @Property(name = ResourceChangeListener.CHANGES, value = 
{"CHANGED","REMOVED"}),
-    @Property(name = ResourceChangeListener.PATHS, value = {"glob:."}, 
propertyPrivate = true)
+    @Property(name = ResourceChangeListener.CHANGES, value = {"CHANGED", 
"REMOVED"}),
+    @Property(name = ResourceChangeListener.PATHS, value = {"."}, 
propertyPrivate = true)
 })
 public class JavaScriptEngineFactory
     extends AbstractScriptEngineFactory
@@ -93,7 +93,7 @@ public class JavaScriptEngineFactory
     @Reference
     private JavaCompiler javaCompiler;
 
-    @Reference
+    @Reference(target="(name=org.apache.sling)")
     private ServletContext slingServletContext;
 
     private SlingIOProvider ioProvider;
@@ -254,7 +254,7 @@ public class JavaScriptEngineFactory
        }
 
     private void handleModification(final String scriptName, final boolean 
remove) {
-        this.ioProvider.getServletCache().removeWrapper(scriptName);
+        this.ioProvider.getServletCache().removeWrapper(scriptName, remove);
     }
 
     private static class JavaScriptEngine extends AbstractSlingScriptEngine {

Modified: 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java?rev=1765260&r1=1765259&r2=1765260&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
 (original)
+++ 
sling/trunk/contrib/scripting/java/src/main/java/org/apache/sling/scripting/java/impl/ServletCache.java
 Mon Oct 17 12:40:48 2016
@@ -18,6 +18,7 @@
 package org.apache.sling.scripting.java.impl;
 
 import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -58,16 +59,26 @@ public final class ServletCache {
      * Remove a  ServletWrapper.
      *
      * @param servletUri Servlet URI
+     * @param isRemove Is a remove
      */
-    public void removeWrapper(final String servletUri) {
+    public void removeWrapper(final String servletUri, final boolean isRemove) 
{
         final ServletWrapper wrapper = servlets.remove(servletUri);
         if ( wrapper != null ) {
             wrapper.destroy();
+        } else if ( isRemove ) {
+            final Iterator<Map.Entry<String, ServletWrapper>> iter = 
servlets.entrySet().iterator();
+            while ( iter.hasNext() ) {
+                final Map.Entry<String, ServletWrapper> entry = iter.next();
+                if ( entry.getKey().startsWith(servletUri) ) {
+                    iter.remove();
+                    entry.getValue().destroy();
+                }
+            }
         }
     }
 
     /**
-     * Process a "destory" event for this web application context.
+     * Process a "destroy" event for this web application context.
      */
     public void destroy() {
         Iterator<ServletWrapper> i = this.servlets.values().iterator();


Reply via email to