Author: radu
Date: Mon Nov 28 18:11:41 2016
New Revision: 1771783

URL: http://svn.apache.org/viewvc?rev=1771783&view=rev
Log:
SLING-6165 - Expose a service for Sling Scripting that provides request-scoped 
Resource Resolvers for scripting dependencies

* correctly register the ScriptingResourceResolverProviderImpl as a 
ServletRequestListener through Whiteboard
* extended the ResourceResolverWrapper provided through SLING-6336, in order to 
avoid importing the
org.apache.sling.api.resource package with a minor-limited import range

Modified:
    sling/trunk/bundles/scripting/api/pom.xml
    
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/ScriptingResourceResolverProvider.java
    
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/package-info.java
    sling/trunk/bundles/scripting/core/pom.xml
    
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java
    
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverProviderImpl.java

Modified: sling/trunk/bundles/scripting/api/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api/pom.xml?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/api/pom.xml (original)
+++ sling/trunk/bundles/scripting/api/pom.xml Mon Nov 28 18:11:41 2016
@@ -56,7 +56,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.11.0</version>
+            <version>2.15.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
     </dependencies>

Modified: 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/ScriptingResourceResolverProvider.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/ScriptingResourceResolverProvider.java?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/ScriptingResourceResolverProvider.java
 (original)
+++ 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/ScriptingResourceResolverProvider.java
 Mon Nov 28 18:11:41 2016
@@ -17,8 +17,7 @@
 package org.apache.sling.scripting.api.resource;
 
 import org.apache.sling.api.resource.ResourceResolver;
-
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * The {@code ScriptingResourceResolverProvider} provides methods to obtain 
{@link ResourceResolver}s that can be used by scripting

Modified: 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/package-info.java?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/package-info.java
 (original)
+++ 
sling/trunk/bundles/scripting/api/src/main/java/org/apache/sling/scripting/api/resource/package-info.java
 Mon Nov 28 18:11:41 2016
@@ -22,8 +22,7 @@
  * context of a Servlet API Request might lead to improper cleaning of objects 
whose life-cycle should not be longer than the request to
  * which they're bound to (for example per-thread objects)</i>.</p>
  *
- * <p>This package depends on the {@link org.apache.sling.api.resource} API, 
version 2.9.0 (bundle {@code org.apache.sling.api}, version
- * 2.11.0).</p>
+ * <p>This package depends on the {@link org.apache.sling.api.resource} API, 
version >= 2.10.0.</p>
  */
 @Version("1.0.0")
 package org.apache.sling.scripting.api.resource;

Modified: sling/trunk/bundles/scripting/core/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/pom.xml (original)
+++ sling/trunk/bundles/scripting/core/pom.xml Mon Nov 28 18:11:41 2016
@@ -124,7 +124,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.14.2</version>
+            <version>2.15.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java
 (original)
+++ 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolver.java
 Mon Nov 28 18:11:41 2016
@@ -18,20 +18,17 @@ package org.apache.sling.scripting.core.
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.util.Iterator;
 import java.util.Map;
 import javax.annotation.Nonnull;
-import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.PersistenceException;
-import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceResolverWrapper;
 import 
org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ScriptingResourceResolver implements ResourceResolver {
+public class ScriptingResourceResolver extends ResourceResolverWrapper {
 
     private static final Logger LOGGER = 
LoggerFactory.getLogger(ScriptingResourceResolver.class);
 
@@ -39,101 +36,18 @@ public class ScriptingResourceResolver i
     private boolean shouldLogClosing = false;
 
     public ScriptingResourceResolver(boolean shouldLogClosing, 
ResourceResolver delegate) {
+        super(delegate);
         this.shouldLogClosing = shouldLogClosing;
         this.delegate = delegate;
     }
 
     @Nonnull
     @Override
-    public Resource resolve(@Nonnull HttpServletRequest request, @Nonnull 
String absPath) {
-        return delegate.resolve(request, absPath);
-    }
-
-    @Nonnull
-    @Override
-    public Resource resolve(@Nonnull String absPath) {
-        return delegate.resolve(absPath);
-    }
-
-    @Nonnull
-    @Override
-    public Resource resolve(@Nonnull HttpServletRequest request) {
-        return delegate.resolve(request);
-    }
-
-    @Nonnull
-    @Override
-    public String map(@Nonnull String resourcePath) {
-        return delegate.map(resourcePath);
-    }
-
-    @Override
-    public String map(@Nonnull HttpServletRequest request, @Nonnull String 
resourcePath) {
-        return delegate.map(request, resourcePath);
-    }
-
-    @Override
-    public Resource getResource(@Nonnull String path) {
-        return delegate.getResource(path);
-    }
-
-    @Override
-    public Resource getResource(Resource base, @Nonnull String path) {
-        return delegate.getResource(base, path);
-    }
-
-    @Nonnull
-    @Override
-    public String[] getSearchPath() {
-        return delegate.getSearchPath();
-    }
-
-    @Nonnull
-    @Override
-    public Iterator<Resource> listChildren(@Nonnull Resource parent) {
-        return delegate.listChildren(parent);
-    }
-
-    @Override
-    public Resource getParent(@Nonnull Resource child) {
-        return delegate.getParent(child);
-    }
-
-    @Nonnull
-    @Override
-    public Iterable<Resource> getChildren(@Nonnull Resource parent) {
-        return delegate.getChildren(parent);
-    }
-
-    @Nonnull
-    @Override
-    public Iterator<Resource> findResources(@Nonnull String query, String 
language) {
-        return delegate.findResources(query, language);
-    }
-
-    @Nonnull
-    @Override
-    public Iterator<Map<String, Object>> queryResources(@Nonnull String query, 
String language) {
-        return delegate.queryResources(query, language);
-    }
-
-    @Override
-    public boolean hasChildren(@Nonnull Resource resource) {
-        return delegate.hasChildren(resource);
-    }
-
-    @Nonnull
-    @Override
     public ResourceResolver clone(Map<String, Object> authenticationInfo) 
throws LoginException {
         return new ScriptingResourceResolver(shouldLogClosing, 
delegate.clone(null));
     }
 
     @Override
-    public boolean isLive() {
-        return delegate.isLive();
-    }
-
-    @Override
     public void close() {
         LOGGER.warn("Attempted to call close on the scripting per-request 
resource resolver. This is handled automatically by the {}.",
                 ScriptingResourceResolverProvider.class.getName());
@@ -149,80 +63,4 @@ public class ScriptingResourceResolver i
         delegate.close();
     }
 
-    @Override
-    public String getUserID() {
-        return delegate.getUserID();
-    }
-
-    @Nonnull
-    @Override
-    public Iterator<String> getAttributeNames() {
-        return delegate.getAttributeNames();
-    }
-
-    @Override
-    public Object getAttribute(@Nonnull String name) {
-        return delegate.getAttribute(name);
-    }
-
-    @Override
-    public void delete(@Nonnull Resource resource) throws PersistenceException 
{
-        delegate.delete(resource);
-    }
-
-    @Nonnull
-    @Override
-    public Resource create(@Nonnull Resource parent, @Nonnull String name, 
Map<String, Object> properties) throws PersistenceException {
-        return delegate.create(parent, name, properties);
-    }
-
-    @Override
-    public void revert() {
-        delegate.revert();
-    }
-
-    @Override
-    public void commit() throws PersistenceException {
-        delegate.commit();
-    }
-
-    @Override
-    public boolean hasChanges() {
-        return delegate.hasChanges();
-    }
-
-    @Override
-    public String getParentResourceType(Resource resource) {
-        return delegate.getParentResourceType(resource);
-    }
-
-    @Override
-    public String getParentResourceType(String resourceType) {
-        return delegate.getParentResourceType(resourceType);
-    }
-
-    @Override
-    public boolean isResourceType(Resource resource, String resourceType) {
-        return delegate.isResourceType(resource, resourceType);
-    }
-
-    @Override
-    public void refresh() {
-        delegate.refresh();
-    }
-
-    @Override
-    public Resource copy(String srcAbsPath, String destAbsPath) throws 
PersistenceException {
-        return delegate.copy(srcAbsPath, destAbsPath);
-    }
-
-    @Override
-    public Resource move(String srcAbsPath, String destAbsPath) throws 
PersistenceException {
-        return delegate.move(srcAbsPath, destAbsPath);
-    }
-
-    @Override
-    public <AdapterType> AdapterType adaptTo(@Nonnull Class<AdapterType> type) 
{
-        return delegate.adaptTo(type);
-    }
 }

Modified: 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverProviderImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverProviderImpl.java?rev=1771783&r1=1771782&r2=1771783&view=diff
==============================================================================
--- 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverProviderImpl.java
 (original)
+++ 
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptingResourceResolverProviderImpl.java
 Mon Nov 28 18:11:41 2016
@@ -27,6 +27,7 @@ import org.osgi.framework.Constants;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.Designate;
 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@@ -37,7 +38,10 @@ import org.slf4j.LoggerFactory;
         service = {ScriptingResourceResolverProvider.class, 
ServletRequestListener.class},
         property = {
                 Constants.SERVICE_DESCRIPTION + "=Apache Sling Scripting 
Resource Resolver Provider",
-                Constants.SERVICE_VENDOR + "=The Apache Software Foundation"
+                Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+                HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT + "=(" 
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
+                        "=*)",
+                HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER + "=true"
         }
 
 )
@@ -79,7 +83,7 @@ public class ScriptingResourceResolverPr
                 threadResolver = new 
ScriptingResourceResolver(logStackTraceOnResolverClose, delegate);
                 perThreadResourceResolver.set(threadResolver);
                 if (LOGGER.isDebugEnabled()) {
-                    LOGGER.debug("Setting per thread resource resolver for 
thread {}.", Thread.currentThread().getName());
+                    LOGGER.debug("Set per thread resource resolver for thread 
{}.", Thread.currentThread().getId());
                 }
             } catch (LoginException e) {
                 throw new IllegalStateException("Cannot create per thread 
resource resolver.", e);
@@ -99,10 +103,11 @@ public class ScriptingResourceResolverPr
         if (scriptingResourceResolver != null) {
             scriptingResourceResolver._close();
             perThreadResourceResolver.remove();
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Removed per thread resource resolver for thread 
{}.", Thread.currentThread().getId());
+            }
         }
-        if (LOGGER.isDebugEnabled()) {
-            LOGGER.debug("Removing per thread resource resolver for thread 
{}.", Thread.currentThread().getName());
-        }
+
     }
 
     @Activate


Reply via email to