You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2020/04/01 13:32:56 UTC

[sling-org-apache-sling-scripting-sightly-testing] branch master updated: SLING-9320 - Allow precompiled units to access objects from the same bundle through the Use API

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 749ee3f  SLING-9320 - Allow precompiled units to access objects from the same bundle through the Use API
749ee3f is described below

commit 749ee3f1a4e10c94edebb85c9ab77980bba10e71
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Apr 1 15:32:36 2020 +0200

    SLING-9320 - Allow precompiled units to access objects from the same bundle through the Use API
    
    * extended the JavaUseProvider to use the precompiled unit's bundle classloader for
    loading classes
    * added IT
---
 pom.xml                                            | 77 ++++++++++++++++++++--
 .../sightly/testing/internal/InternalUsePojo.java  | 46 +++++++++++++
 .../SLING-INF/content/sightly-testing.xml          | 33 ++++++++++
 .../sightly/testing/precompiled/precompiled.html   | 47 +++++++++++++
 .../sightly/it/SlingSpecificsSightlyIT.java        | 16 +++++
 src/test/provisioning/scripting.txt                |  2 +-
 src/test/provisioning/sightly.txt                  |  1 +
 src/test/provisioning/sling.txt                    |  4 +-
 8 files changed, 216 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index f5c6657..a521ca5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.sling</groupId>
-        <artifactId>sling</artifactId>
+        <artifactId>sling-bundle-parent</artifactId>
         <version>35</version>
         <relativePath />
     </parent>
@@ -80,7 +80,7 @@
                 <plugin>
                     <groupId>org.apache.sling</groupId>
                     <artifactId>slingstart-maven-plugin</artifactId>
-                    <version>1.8.2</version>
+                    <version>1.9.4</version>
                     <extensions>true</extensions>
                     <configuration>
                         <usePomDependencies>true</usePomDependencies>
@@ -94,16 +94,15 @@
                             </server>
                         </servers>
                         <disableExtendingMavenClasspath>true</disableExtendingMavenClasspath>
+                        <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
                     </configuration>
                     <executions>
                         <execution>
                             <id>customise-starter</id>
+                            <phase>pre-integration-test</phase>
                             <goals>
                                 <goal>prepare-package</goal>
                             </goals>
-                            <configuration>
-                                <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
-                            </configuration>
                         </execution>
                         <execution>
                             <id>package-starter</id>
@@ -112,7 +111,6 @@
                             </goals>
                             <configuration>
                                 <attachArtifact>false</attachArtifact>
-                                <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
                             </configuration>
                         </execution>
                         <execution>
@@ -143,6 +141,63 @@
                 </configuration>
             </plugin>
             <plugin>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>htl-maven-plugin</artifactId>
+                <version>1.3.5-1.4.0-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <id>validate-htl-scripts</id>
+                        <goals>
+                            <goal>validate</goal>
+                        </goals>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <generateJavaClasses>true</generateJavaClasses>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.sling</groupId>
+                <artifactId>scriptingbundle-maven-plugin</artifactId>
+                <version>0.1.1-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <phase>process-resources</phase>
+                        <goals>
+                            <goal>metadata</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>bnd-process</id>
+                        <goals>
+                            <goal>bnd-process</goal>
+                        </goals>
+                        <configuration>
+                            <bnd><![CDATA[
+Provide-Capability: ${org.apache.sling.scriptingbundle.maven.plugin.Provide-Capability}
+Require-Capability: osgi.extender;filter:="(&(osgi.extender=sling.scripting)(version>=1.0.0)(!(version>=2.0.0)))",${org.apache.sling.scriptingbundle.maven.plugin.Require-Capability}
+Sling-ResourceType-Precompiled: true
+Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-testing
+                                ]]></bnd>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
+                <configuration>
+                    <failOnMissing>false</failOnMissing>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
                 <executions>
@@ -226,6 +281,7 @@
                                 [artifacts]
                                 org.apache.sling/org.apache.sling.starter/12-SNAPSHOT/slingstart
                                 org.apache.sling/org.apache.sling.commons.compiler/2.3.7-SNAPSHOT
+                                org.apache.sling/org.apache.sling.scripting.bundle.tracker/0.1.1-SNAPSHOT
                             </model>
                             <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
                             <modelPattern>sightly.txt</modelPattern>
@@ -262,7 +318,7 @@
                         <artifactId>maven-failsafe-plugin</artifactId>
                         <configuration>
                             <systemPropertyVariables>
-                                <IT.expected.bundles.count>178</IT.expected.bundles.count>
+                                <IT.expected.bundles.count>179</IT.expected.bundles.count>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>
@@ -273,6 +329,13 @@
 
     <dependencies>
 
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.22.0</version>
+            <scope>provided</scope>
+        </dependency>
+
         <!-- The integration tests -->
         <dependency>
             <groupId>io.sightly</groupId>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/internal/InternalUsePojo.java b/src/main/java/org/apache/sling/scripting/sightly/testing/internal/InternalUsePojo.java
new file mode 100644
index 0000000..d23b072
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/internal/InternalUsePojo.java
@@ -0,0 +1,46 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.sightly.testing.internal;
+
+import javax.script.Bindings;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.scripting.sightly.pojo.Use;
+
+public class InternalUsePojo implements Use {
+
+    private static final String UNKNOWN_PATH = "/dev/null";
+
+    private String resourcePath;
+
+    @Override
+    public void init(Bindings bindings) {
+        Resource resource = (Resource) bindings.get(SlingBindings.RESOURCE);
+        if (resource != null) {
+            resourcePath = resource.getPath();
+        } else {
+            resourcePath = UNKNOWN_PATH;
+        }
+    }
+
+    public String getResourcePath() {
+        return resourcePath;
+    }
+}
diff --git a/src/main/resources/SLING-INF/content/sightly-testing.xml b/src/main/resources/SLING-INF/content/sightly-testing.xml
new file mode 100644
index 0000000..b686859
--- /dev/null
+++ b/src/main/resources/SLING-INF/content/sightly-testing.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<node>
+    <name>precompiled</name>
+    <primaryNodeType>nt:unstructured</primaryNodeType>
+    <property>
+        <name>sling:resourceType</name>
+        <value>org/apache/sling/scripting/sightly/testing/precompiled</value>
+        <type>String</type>
+    </property>
+    <property>
+        <name>jcr:title</name>
+        <value>HTL Precompiled Scripts Test</value>
+        <type>String</type>
+    </property>
+</node>
diff --git a/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/precompiled.html b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/precompiled.html
new file mode 100644
index 0000000..e083689
--- /dev/null
+++ b/src/main/scripts/org/apache/sling/scripting/sightly/testing/precompiled/precompiled.html
@@ -0,0 +1,47 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<div class="precompiled" >
+    <span class="internal-use-pojo" data-sly-use.pojo="org.apache.sling.scripting.sightly.testing.internal.InternalUsePojo">
+        ${pojo.resourcePath}
+    </span><br/>
+    <span class="request-adapter"
+          data-sly-use.requestAdapter="org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject">
+        ${requestAdapter.title}
+    </span><br/>
+    <span class="resource-adapter"
+          data-sly-use.resourceAdapter="org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject">
+        ${resourceAdapter.title}
+    </span><br/>
+    <span class="resolver-adapter"
+          data-sly-use.resolverAdapter="${'org.apache.sling.scripting.sightly.testing.adaptable.ResourceResolverAdapterUseObject' @ adaptable = request.resourceResolver}">
+        ${resolverAdapter.title}
+    </span><br/>
+    <span class="request-model"
+          data-sly-use.requestModel="${'org.apache.sling.scripting.sightly.testing.models.RequestModel' @ argument='SUCCESS'}">
+        ${requestModel.title}
+    </span><br/>
+    <span class="resource-model"
+          data-sly-use.resourceModel="org.apache.sling.scripting.sightly.testing.models.ResourceModel">
+        ${resourceModel.title}
+    </span><br/>
+    <span class="test-service"
+          data-sly-use.testService="org.apache.sling.scripting.sightly.testing.use.TestService">
+        ${testService.title}
+    </span><br/>
+</div>
diff --git a/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java b/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
index 642b054..d1c50f7 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
@@ -27,6 +27,7 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.sling.testing.clients.util.FormEntityBuilder;
+import org.apache.sling.testing.junit.rules.annotation.IgnoreIfProperty;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -68,6 +69,7 @@ public class SlingSpecificsSightlyIT {
     private static final String TCK_XSS = "/sightlytck/exprlang/xss.html";
     private static final String WHITESPACE = "/sightly/whitespace.html";
     private static final String SYNTHETIC_RESOURCE = "/sightly/synthetic-resource.html";
+    private static final String PRECOMPILED = "/sightly-testing/precompiled.html";
 
     @BeforeClass
     public static void init() {
@@ -385,6 +387,20 @@ public class SlingSpecificsSightlyIT {
         assertEquals("It works!", HTMLExtractor.innerHTML(url, pageContent, "#synthetic-resource-selector"));
     }
 
+    @Test
+    public void testPrecompiled() {
+        final String title = "HTL Precompiled Scripts Test";
+        String url = launchpadURL + PRECOMPILED;
+        String pageContent = client.getStringContent(url, 200);
+        assertEquals("/content/sightly-testing/precompiled", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span" +
+                ".internal-use-pojo"));
+        assertEquals(title, HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.request-adapter"));
+        assertEquals(title, HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.resource-adapter"));
+        assertEquals("SUCCESS", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.resolver-adapter"));
+        assertEquals(title, HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.request-model"));
+        assertEquals(title, HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.resource-model"));
+    }
+
     private void restartSightlyEngineBundle() throws InterruptedException, IOException {
         HttpClient httpClient = HttpClientBuilder.create().build();
         HttpPost post = new HttpPost(launchpadURL + "/system/console/bundles/org.apache.sling.scripting.sightly");
diff --git a/src/test/provisioning/scripting.txt b/src/test/provisioning/scripting.txt
index 49651bd..b323ff0 100644
--- a/src/test/provisioning/scripting.txt
+++ b/src/test/provisioning/scripting.txt
@@ -21,7 +21,7 @@
 
 [artifacts]
     org.apache.sling/org.apache.sling.scripting.api/2.2.0
-    org.apache.sling/org.apache.sling.scripting.core/2.1.0
+    org.apache.sling/org.apache.sling.scripting.core/2.2.0
     org.apache.sling/org.apache.sling.scripting.javascript/3.1.2
     org.apache.sling/org.apache.sling.scripting.jsp/2.4.0
     org.apache.sling/org.apache.sling.scripting.jsp-api/1.0.2
diff --git a/src/test/provisioning/sightly.txt b/src/test/provisioning/sightly.txt
index f1702bf..59ae84c 100644
--- a/src/test/provisioning/sightly.txt
+++ b/src/test/provisioning/sightly.txt
@@ -27,6 +27,7 @@
   org.apache.sling/org.apache.sling.scripting.sightly.js.provider
   org.apache.sling/org.apache.sling.scripting.sightly.models.provider
   org.apache.sling/org.apache.sling.scripting.sightly.testing-content
+  org.apache.sling/org.apache.sling.scripting.sightly.testing
 
 # additional configuration for testing
 [configurations]
diff --git a/src/test/provisioning/sling.txt b/src/test/provisioning/sling.txt
index bbf8049..c91c471 100644
--- a/src/test/provisioning/sling.txt
+++ b/src/test/provisioning/sling.txt
@@ -48,7 +48,7 @@
     commons-io/commons-io/2.6
     commons-fileupload/commons-fileupload/1.3.3
     org.apache.sling/org.apache.sling.commons.log.webconsole/1.0.0
-    org.apache.sling/org.apache.sling.api/2.21.0
+    org.apache.sling/org.apache.sling.api/2.22.0
     org.apache.sling/org.apache.sling.auth.core/1.4.4
     
 [artifacts startLevel=10]
@@ -118,7 +118,7 @@
     org.apache.sling/org.apache.sling.serviceuser.webconsole/1.0.2
     org.apache.sling/org.apache.sling.servlets.get/2.1.40
     org.apache.sling/org.apache.sling.servlets.post/2.3.36
-    org.apache.sling/org.apache.sling.servlets.resolver/2.5.8
+    org.apache.sling/org.apache.sling.servlets.resolver/2.6.4
     org.apache.sling/org.apache.sling.xss/2.1.18
     javax.mail/mail/1.5.0-b01
     org.apache.geronimo.bundles/jstl/1.2_1