SLING-6165 - Expose a service for Sling Scripting that provides request-scoped Resource Resolvers for scripting dependencies

* defined ScriptingResourceResolverFactory + implementation

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1766070 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index cf6ccd9..3522b77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,49 +17,49 @@
     specific language governing permissions and limitations
     under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
 
-  <parent>
-    <groupId>org.apache.sling</groupId>
-    <artifactId>sling</artifactId>
-    <version>26</version>
-    <relativePath />
-  </parent>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>29</version>
+        <relativePath/>
+    </parent>
 
-  <artifactId>org.apache.sling.scripting.api</artifactId>
-  <version>2.1.9-SNAPSHOT</version>
-  <packaging>bundle</packaging>
+    <artifactId>org.apache.sling.scripting.api</artifactId>
+    <version>2.1.9-SNAPSHOT</version>
+    <packaging>bundle</packaging>
 
-  <name>Apache Sling Scripting Implementation API</name>
-  <description>This bundle provides the internal API to implement scripting.</description>
+    <name>Apache Sling Scripting Implementation API</name>
+    <description>This bundle provides the internal API to implement scripting.</description>
 
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/api</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/api
-    </developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api</url>
-  </scm>
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/api</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/api
+        </developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/api</url>
+    </scm>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Import-Package>
-              javax.script
-            </Import-Package>
-            <Export-Package>
-              org.apache.sling.scripting.api;version=2.3.0
-            </Export-Package>
-          </instructions>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.9.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
 
 </project>
diff --git a/src/main/java/javax/script/package-info.java b/src/main/java/javax/script/package-info.java
new file mode 100644
index 0000000..c7b447c
--- /dev/null
+++ b/src/main/java/javax/script/package-info.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ ******************************************************************************/
+@Version("0.0.0")
+package javax.script;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/api/ScriptingResourceResolverFactory.java b/src/main/java/org/apache/sling/scripting/api/ScriptingResourceResolverFactory.java
new file mode 100644
index 0000000..8f8cdfb
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/api/ScriptingResourceResolverFactory.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.sling.scripting.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The {@code ScriptingResourceResolverFactory} provides methods to obtain {@link ResourceResolver}s that can be used by scripting
+ * bundles to perform their script resolution operations.
+ *
+ * @since 2.4.0
+ */
+@ProviderType
+public interface ScriptingResourceResolverFactory {
+
+    /**
+     * <p>Provides a request-scoped {@link ResourceResolver} with only read access to the search paths.</p>
+     *
+     * <p>This resolver should be used for script resolution in the context of the same request rendering process. The {@code
+     * ResourceResolver} should not be closed by consumers (calling {@link ResourceResolver#close} doesn't do anything), since this
+     * service will handle the closing operation automatically. The {@code ResourceResolver} will be shared between scripting
+     * dependencies that render parts of the response for the same request.</p>
+     */
+    ResourceResolver getRequestScopedResourceResolver();
+
+    /**
+     * Provides a {@link ResourceResolver} with only read access to the search paths. Once you're done processing {@link Resource}s with
+     * this {@code ResourceResolver} make sure to close it (or use it in a
+     * <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html"><code>try-with-resources</code><a/>
+     * block).
+     */
+    ResourceResolver getResourceResolver();
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/api/package-info.java b/src/main/java/org/apache/sling/scripting/api/package-info.java
new file mode 100644
index 0000000..8b61c4a
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/api/package-info.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ ******************************************************************************/
+@Version("2.4.0")
+package org.apache.sling.scripting.api;
+
+import org.osgi.annotation.versioning.Version;