Author: cziegeler
Date: Mon Oct 17 09:00:28 2016
New Revision: 1765223

URL: http://svn.apache.org/viewvc?rev=1765223&view=rev
Log:
SLING-6004 : JspScriptEngineFactory should move to new ResourceChangeListener 
API. Apply patch from Rachit Kumar

Modified:
    sling/trunk/bundles/scripting/jsp/pom.xml
    
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/Log.java
    
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/LogFactory.java
    
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
    
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java

Modified: sling/trunk/bundles/scripting/jsp/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/pom.xml?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp/pom.xml Mon Oct 17 09:00:28 2016
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>26</version>
+        <version>29</version>
         <relativePath />
     </parent>
 
@@ -79,22 +79,18 @@
                     </instructions>
                 </configuration>
             </plugin>
-        </plugins>
-    </build>
-    <reporting>
-        <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
                 <configuration>
                   <!-- No javadocs -->
                     <excludePackageNames>
-                        org.apache.sling.scripting
+                        org.apache.sling.scripting,org.apache.juli.logging
                     </excludePackageNames>
                 </configuration>
             </plugin>
         </plugins>
-    </reporting>
+    </build>
 
     <dependencies>
         <dependency>
@@ -103,16 +99,12 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <artifactId>osgi.core</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.8</version>
+            <version>2.11.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/Log.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/Log.java?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/Log.java
 (original)
+++ 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/Log.java
 Mon Oct 17 09:00:28 2016
@@ -1,18 +1,18 @@
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed 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.juli.logging;
@@ -23,7 +23,7 @@ package org.apache.juli.logging;
  * this interface must have a constructor that takes a single String
  * parameter representing the "name" of this Log.</p>
  *
- * <p> The six logging levels used by <code>Log</code> are (in order):
+ * <p> The six logging levels used by <code>Log</code> are (in order):</p>
  * <ol>
  * <li>trace (the least serious)</li>
  * <li>debug</li>
@@ -32,7 +32,7 @@ package org.apache.juli.logging;
  * <li>error</li>
  * <li>fatal (the most serious)</li>
  * </ol>
- * The mapping of these log levels to the concepts used by the underlying
+ * <p>The mapping of these log levels to the concepts used by the underlying
  * logging system is implementation dependent.
  * The implemention should ensure, though, that this ordering behaves
  * as expected.</p>
@@ -42,14 +42,13 @@ package org.apache.juli.logging;
  * a component can avoid expensive operations (producing information
  * to be logged).</p>
  *
- * <p> For example,
- * <code><pre>
+ * <p> For example, </p>
+ * <pre>
  *    if (log.isDebugEnabled()) {
  *        ... do something expensive ...
  *        log.debug(theResult);
  *    }
- * </pre></code>
- * </p>
+ * </pre>
  *
  * <p>Configuration of the underlying logging system will generally be done
  * external to the Logging APIs, through whatever mechanism is supported by

Modified: 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/LogFactory.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/LogFactory.java?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/LogFactory.java
 (original)
+++ 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/juli/logging/LogFactory.java
 Mon Oct 17 09:00:28 2016
@@ -25,7 +25,7 @@ public class LogFactory {
      * having to care about factories.
      *
      * @param clazz Class from which a log name will be derived
-     *
+     * @return The log
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */
@@ -44,7 +44,7 @@ public class LogFactory {
      * @param name Logical name of the <code>Log</code> instance to be
      *  returned (the meaning of this name is only known to the underlying
      *  logging implementation that is being wrapped)
-     *
+     * @return The log
      * @exception LogConfigurationException if a suitable <code>Log</code>
      *  instance cannot be returned
      */

Modified: 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
 (original)
+++ 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
 Mon Oct 17 09:00:28 2016
@@ -24,7 +24,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Reader;
-import java.util.Dictionary;
+import java.util.List;
+import java.util.Map;
 
 import javax.script.Bindings;
 import javax.script.ScriptContext;
@@ -39,17 +40,22 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingIOException;
 import org.apache.sling.api.SlingServletException;
 import org.apache.sling.api.resource.ResourceResolver;
+import 
org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
+import org.apache.sling.api.resource.observation.ResourceChange;
+import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
+import org.apache.sling.api.resource.observation.ResourceChangeListener;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptConstants;
@@ -66,10 +72,7 @@ import org.apache.sling.scripting.jsp.ja
 import org.apache.sling.scripting.jsp.jasper.runtime.JspApplicationContextImpl;
 import org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper;
 import org.apache.sling.scripting.jsp.util.TagUtil;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
+import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -80,7 +83,7 @@ import org.slf4j.LoggerFactory;
 @Component(label="%jsphandler.name",
            description="%jsphandler.description",
            metatype=true)
-@Service(value={javax.script.ScriptEngineFactory.class, EventHandler.class, 
Servlet.class})
+@Service(value={javax.script.ScriptEngineFactory.class,ResourceChangeListener.class,Servlet.class})
 @Properties({
    @Property(name="service.description",value="JSP Script Handler"),
    @Property(name="service.vendor",value="The Apache Software Foundation"),
@@ -94,14 +97,14 @@ import org.slf4j.LoggerFactory;
    @Property(name="jasper.mappedfile",boolValue=true),
    @Property(name="jasper.trimSpaces",boolValue=false),
    @Property(name="jasper.displaySourceFragments",boolValue=false),
-   @Property(name=EventConstants.EVENT_TOPIC, 
value={"org/apache/sling/api/resource/*"}, propertyPrivate=true),
+   @Property(name=ResourceChangeListener.PATHS, value={"/"}, 
propertyPrivate=true),
    @Property(name="felix.webconsole.label", value="slingjsp", 
propertyPrivate=true),
    @Property(name="felix.webconsole.title", value="JSP", propertyPrivate=true),
    @Property(name="felix.webconsole.category", value="Sling", 
propertyPrivate=true)
 })
 public class JspScriptEngineFactory
     extends AbstractScriptEngineFactory
-    implements EventHandler, Servlet {
+    implements Servlet,ResourceChangeListener,ExternalResourceChangeListener {
 
     @Property(boolValue = true)
     private static final String PROP_DEFAULT_IS_SESSION = "default.is.session";
@@ -193,7 +196,6 @@ public class JspScriptEngineFactory
      * @param context The script context
      * @param scriptName The name of the script
      */
-    @SuppressWarnings("unchecked")
     private void callErrorPageJsp(final Bindings bindings,
                                   final SlingScriptHelper scriptHelper,
                                   final ScriptContext context,
@@ -253,7 +255,6 @@ public class JspScriptEngineFactory
      * @throws SlingServletException
      * @throws SlingIOException
      */
-    @SuppressWarnings("unchecked")
     private void callJsp(final Bindings bindings,
                          final SlingScriptHelper scriptHelper,
                          final ScriptContext context) {
@@ -329,8 +330,8 @@ public class JspScriptEngineFactory
     /**
      * Activate this component
      */
-    protected void activate(final ComponentContext componentContext) {
-        final Dictionary<?, ?> properties = componentContext.getProperties();
+    @Activate
+    protected void activate(final BundleContext bundleContext, final 
Map<String, Object> properties) {
         this.defaultIsSession = 
PropertiesUtil.toBoolean(properties.get(PROP_DEFAULT_IS_SESSION), true);
 
         // set the current class loader as the thread context loader for
@@ -341,14 +342,14 @@ public class JspScriptEngineFactory
         try {
             this.jspFactoryHandler = JspRuntimeContext.initFactoryHandler();
 
-            this.tldLocationsCache = new 
SlingTldLocationsCache(componentContext.getBundleContext());
+            this.tldLocationsCache = new SlingTldLocationsCache(bundleContext);
 
             // prepare some classes
             ioProvider = new SlingIOProvider(this.classLoaderWriter, 
this.javaCompiler);
 
             // return options which use the jspClassLoader
             options = new JspServletOptions(slingServletContext, ioProvider,
-                componentContext, tldLocationsCache);
+                properties, tldLocationsCache);
 
             jspServletContext = new JspServletContext(ioProvider,
                 slingServletContext, tldLocationsCache);
@@ -371,11 +372,12 @@ public class JspScriptEngineFactory
     /**
      * Activate this component
      */
-    protected void deactivate(final ComponentContext componentContext) {
+    @Deactivate
+    protected void deactivate(final BundleContext bundleContext) {
         logger.info("Deactivating Apache Sling Script Engine for JSP");
 
         if ( this.tldLocationsCache != null ) {
-            
this.tldLocationsCache.deactivate(componentContext.getBundleContext());
+            this.tldLocationsCache.deactivate(bundleContext);
             this.tldLocationsCache = null;
         }
         if (jspRuntimeContext != null) {
@@ -619,18 +621,14 @@ public class JspScriptEngineFactory
 
     }
 
-    /**
-     * @see 
org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)
-     */
     @Override
-    public void handleEvent(final Event event) {
-        final String path = 
(String)event.getProperty(SlingConstants.PROPERTY_PATH);
-        if ( path != null ) {
+       public void onChange(final List<ResourceChange> changes) {
+       for(final ResourceChange change : changes){
             final JspRuntimeContext rctxt = this.jspRuntimeContext;
-            if ( rctxt != null && rctxt.handleModification(path) ) {
+            if ( rctxt != null && rctxt.handleModification(change.getPath(), 
change.getType() == ChangeType.REMOVED) ) {
                 renewJspRuntimeContext();
             }
-        }
+       }
     }
 
     /**

Modified: 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
 (original)
+++ 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
 Mon Oct 17 09:00:28 2016
@@ -16,8 +16,6 @@
  */
 package org.apache.sling.scripting.jsp;
 
-import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -29,7 +27,6 @@ import org.apache.sling.scripting.jsp.ja
 import org.apache.sling.scripting.jsp.jasper.compiler.Localizer;
 import org.apache.sling.scripting.jsp.jasper.compiler.TagPluginManager;
 import org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache;
-import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -165,6 +162,7 @@ public class JspServletOptions implement
     /**
      * Are we keeping generated code around?
      */
+    @Override
     public boolean getKeepGenerated() {
         return this.keepGenerated;
     }
@@ -172,10 +170,12 @@ public class JspServletOptions implement
     /**
      * Should white spaces between directives or actions be trimmed?
      */
+    @Override
     public boolean getTrimSpaces() {
         return this.trimSpaces;
     }
 
+    @Override
     public boolean isPoolingEnabled() {
         return this.isPoolingEnabled;
     }
@@ -183,6 +183,7 @@ public class JspServletOptions implement
     /**
      * Are we supporting HTML mapped servlets?
      */
+    @Override
     public boolean getMappedFile() {
         return this.mappedFile;
     }
@@ -190,6 +191,7 @@ public class JspServletOptions implement
     /**
      * Should errors be sent to client or thrown into stderr?
      */
+    @Override
     public boolean getSendErrorToClient() {
         return this.sendErrorToClient;
     }
@@ -197,6 +199,7 @@ public class JspServletOptions implement
     /**
      * Should class files be compiled with debug information?
      */
+    @Override
     public boolean getClassDebugInfo() {
         return this.classDebugInfo;
     }
@@ -204,6 +207,7 @@ public class JspServletOptions implement
     /**
      * Is the generation of SMAP info for JSR45 debugging suppressed?
      */
+    @Override
     public boolean isSmapSuppressed() {
         return this.isSmapSuppressed;
     }
@@ -211,6 +215,7 @@ public class JspServletOptions implement
     /**
      * Should SMAP info for JSR45 debugging be dumped to a file?
      */
+    @Override
     public boolean isSmapDumped() {
         return this.isSmapDumped;
     }
@@ -218,6 +223,7 @@ public class JspServletOptions implement
     /**
      * Are Text strings to be generated as char arrays?
      */
+    @Override
     public boolean genStringAsCharArray() {
         return this.genStringAsCharArray;
     }
@@ -225,6 +231,7 @@ public class JspServletOptions implement
     /**
      * Class ID for use in the plugin tag when the browser is IE.
      */
+    @Override
     public String getIeClassId() {
         return this.ieClassId;
     }
@@ -232,6 +239,7 @@ public class JspServletOptions implement
     /**
      * Is generation of X-Powered-By response header enabled/disabled?
      */
+    @Override
     public boolean isXpoweredBy() {
         return this.xpoweredBy;
     }
@@ -240,6 +248,7 @@ public class JspServletOptions implement
      * Allways return null for the compiler to use, assuming JDT is the default
      * which we will never overwrite.
      */
+    @Override
     public String getCompiler() {
         return null;
     }
@@ -247,6 +256,7 @@ public class JspServletOptions implement
     /**
      * @see Options#getCompilerTargetVM
      */
+    @Override
     public String getCompilerTargetVM() {
         return this.compilerTargetVM;
     }
@@ -254,10 +264,12 @@ public class JspServletOptions implement
     /**
      * @see Options#getCompilerSourceVM
      */
+    @Override
     public String getCompilerSourceVM() {
         return this.compilerSourceVM;
     }
 
+    @Override
     public boolean getErrorOnUseBeanInvalidClassAttribute() {
         return this.errorOnUseBeanInvalidClassAttribute;
     }
@@ -266,6 +278,7 @@ public class JspServletOptions implement
         this.errorOnUseBeanInvalidClassAttribute = b;
     }
 
+    @Override
     public TldLocationsCache getTldLocationsCache() {
         return this.tldLocationsCache;
     }
@@ -274,22 +287,27 @@ public class JspServletOptions implement
         this.tldLocationsCache = tldC;
     }
 
+    @Override
     public String getJavaEncoding() {
         return this.javaEncoding;
     }
 
+    @Override
     public boolean getFork() {
         return this.fork;
     }
 
+    @Override
     public JspConfig getJspConfig() {
         return this.jspConfig;
     }
 
+    @Override
     public TagPluginManager getTagPluginManager() {
         return this.tagPluginManager;
     }
 
+    @Override
     public boolean getDisplaySourceFragment() {
         return displaySourceFragments;
     }
@@ -298,6 +316,7 @@ public class JspServletOptions implement
      * Allways return null for the compiler to use, assuming JDT is the default
      * which we will never overwrite.
      */
+    @Override
     public String getCompilerClassName() {
         return null;
     }
@@ -307,19 +326,17 @@ public class JspServletOptions implement
      * ServletConfig and ServletContext.
      */
     public JspServletOptions(ServletContext servletContext,
-            IOProvider ioProvider, ComponentContext componentContext,
+            IOProvider ioProvider, Map<String, Object> config,
             TldLocationsCache tldLocationsCache) {
 
         // JVM version numbers default to current vm version
         this.compilerSourceVM = 
System.getProperty("java.specification.version");
         this.compilerTargetVM = this.compilerSourceVM;
 
-        Dictionary<?, ?> config = componentContext.getProperties();
-        Enumeration<?> enumeration = config.keys();
-        while (enumeration.hasMoreElements()) {
-            String key = (String) enumeration.nextElement();
+        for(final Map.Entry<String, Object> entry : config.entrySet()) {
+            String key = entry.getKey();
             if (key.startsWith("jasper.")) {
-                final Object value = config.get(key);
+                final Object value = entry.getValue();
                 if (value != null) {
                     final String strValue = String.valueOf(value).trim();
                     if ( strValue.length() > 0 ) {
@@ -536,6 +553,7 @@ public class JspServletOptions implement
         this.tagPluginManager = new TagPluginManager(servletContext);
     }
 
+    @Override
     public String getScratchDir() {
         return ":";
     }

Modified: 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java?rev=1765223&r1=1765222&r2=1765223&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
 (original)
+++ 
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspRuntimeContext.java
 Mon Oct 17 09:00:28 2016
@@ -45,6 +45,7 @@ import javax.servlet.jsp.PageContext;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.sling.api.resource.path.Path;
 import org.apache.sling.scripting.jsp.jasper.Constants;
 import org.apache.sling.scripting.jsp.jasper.IOProvider;
 import org.apache.sling.scripting.jsp.jasper.Options;
@@ -257,13 +258,36 @@ public final class JspRuntimeContext {
     /**
      * Handle jsp modifications
      */
-    public boolean handleModification(final String scriptName) {
+    public boolean handleModification(final String scriptName, final boolean 
isRemove) {
         if ( log.isDebugEnabled() ) {
             log.debug("Handling modification " + scriptName);
         }
 
-        JspServletWrapper wrapper = jsps.remove(scriptName);
+        final JspServletWrapper wrapper = jsps.remove(scriptName);
+        if ( wrapper == null && isRemove ) {
+            boolean removed = false;
+            final Path path = new Path(scriptName);
+            final Iterator<Map.Entry<String, JspServletWrapper>> iter = 
jsps.entrySet().iterator();
+            while ( iter.hasNext() ) {
+                final Map.Entry<String, JspServletWrapper> entry = iter.next();
+                if ( path.matches(entry.getKey()) ) {
+                    iter.remove();
+                    removed |= handleModification(entry.getKey(), 
entry.getValue());
+                }
+            }
+            return removed;
+        } else {
+            return handleModification(scriptName, wrapper);
+        }
+    }
 
+    /**
+     * Handle modification for a single script
+     * @param scriptName The script name
+     * @param wrapper The jsp wrapper
+     * @return {@code true} if changed
+     */
+    private boolean handleModification(final String scriptName, final 
JspServletWrapper wrapper) {
         // first check if jsps contains this
         boolean removed = this.invalidate(wrapper);
 
@@ -273,8 +297,7 @@ public final class JspRuntimeContext {
         }
         if ( deps != null ) {
             for(final String dep : deps) {
-                wrapper = jsps.remove(dep);
-                removed |= this.invalidate(wrapper);
+                removed |= this.invalidate(jsps.remove(dep));
             }
         }
         return removed;


Reply via email to