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/17 18:58:51 UTC
[sling-org-apache-sling-scripting-sightly-testing] branch master
updated: SLING-9320 - Allow bundled render 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 c0e3e91 SLING-9320 - Allow bundled render units to access objects from the same bundle through the Use API
c0e3e91 is described below
commit c0e3e91189191b726f1d854a04f1b3a2b1180a59
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Apr 17 20:58:23 2020 +0200
SLING-9320 - Allow bundled render units to access objects from the same bundle through the Use API
* added IT
---
pom.xml | 46 ++++++++++++++++++++--
.../precompiled/models/ExportedTestModel.java | 28 +++++++++++++
.../models/impl/ExportedTestModelImpl.java | 39 ++++++++++++++++++
.../precompiled/models/impl/InternalTestModel.java | 38 ++++++++++++++++++
.../testing/precompiled/models/package-info.java | 22 +++++++++++
.../sightly/testing/precompiled/script.ecma | 19 +++++++++
.../sightly/testing/precompiled/script.js | 25 ++++++++++++
.../sightly/testing/precompiled/precompiled.html | 27 ++++++++++---
.../sightly/it/SlingSpecificsSightlyIT.java | 13 +++++-
src/test/provisioning/sightly.txt | 1 -
10 files changed, 247 insertions(+), 11 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9118c42..8140abb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling-bundle-parent</artifactId>
- <version>35</version>
+ <version>38</version>
<relativePath />
</parent>
@@ -169,6 +169,11 @@
</goals>
</execution>
</executions>
+ <configuration>
+ <scriptEngineMappings>
+ <js>rhino</js>
+ </scriptEngineMappings>
+ </configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
@@ -181,14 +186,21 @@
</goals>
<configuration>
<bnd><![CDATA[
+-plugin.slingmodels: org.apache.sling.bnd.models.ModelsScannerPlugin
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>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.bnd.models</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
@@ -282,8 +294,8 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
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
+ org.apache.sling/org.apache.sling.scripting.core/2.2.1-SNAPSHOT
</model>
- <modelDirectory>${project.basedir}/src/test/provisioning</modelDirectory>
<modelPattern>sightly.txt</modelPattern>
</configuration>
</plugin>
@@ -335,6 +347,34 @@ Sling-Initial-Content: SLING-INF/content;overwrite:=true;path:=/content/sightly-
<version>2.22.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.annotation.versioning</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.models.api</artifactId>
+ <version>1.3.8</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.3_spec</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- The integration tests -->
<dependency>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/ExportedTestModel.java b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/ExportedTestModel.java
new file mode 100644
index 0000000..0492861
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/ExportedTestModel.java
@@ -0,0 +1,28 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.precompiled.models;
+
+import org.osgi.annotation.versioning.ConsumerType;
+
+@ConsumerType
+public interface ExportedTestModel {
+
+ String sayHello();
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/ExportedTestModelImpl.java b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/ExportedTestModelImpl.java
new file mode 100644
index 0000000..88d4621
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/ExportedTestModelImpl.java
@@ -0,0 +1,39 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.precompiled.models.impl;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.Optional;
+import org.apache.sling.scripting.sightly.testing.precompiled.models.ExportedTestModel;
+
+@Model(adaptables = SlingHttpServletRequest.class, adapters = ExportedTestModel.class)
+public class ExportedTestModelImpl implements ExportedTestModel {
+
+ @Inject @Optional
+ private String name;
+
+ @Override
+ public String sayHello() {
+ return "Hello, " + (name == null ? "Anonymous" : name);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/InternalTestModel.java b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/InternalTestModel.java
new file mode 100644
index 0000000..ae78b8e
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/impl/InternalTestModel.java
@@ -0,0 +1,38 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.precompiled.models.impl;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.Optional;
+
+@Model(adaptables = SlingHttpServletRequest.class)
+public class InternalTestModel {
+
+
+ @Inject @Optional
+ private String name;
+
+ public String sayHello() {
+ return "Hello, " + (name == null ? "Anonymous" : name);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/package-info.java
new file mode 100644
index 0000000..3228c44
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/testing/precompiled/models/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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("1.0.0")
+package org.apache.sling.scripting.sightly.testing.precompiled.models;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.ecma b/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.ecma
new file mode 100644
index 0000000..892676a
--- /dev/null
+++ b/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.ecma
@@ -0,0 +1,19 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+'Evaluating ECMA scripts works just fine!';
diff --git a/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.js b/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.js
new file mode 100644
index 0000000..4591f64
--- /dev/null
+++ b/src/main/resources/javax.script/org/apache/sling/scripting/sightly/testing/precompiled/script.js
@@ -0,0 +1,25 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+/* global use*/
+use(function () {
+ 'use strict';
+ return {
+ message: 'Evaluating Use JS-objects works just fine!'
+ }
+});
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
index 9d50000..921ae11 100644
--- 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
@@ -17,11 +17,19 @@
~ under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<div class="precompiled" >
- <span class="internal-use-pojo-fqcn" data-sly-use.pojo="org.apache.sling.scripting.sightly.testing.precompiled.InternalUsePojo">
- ${pojo.resourcePath}
+ <span class="internal-use-pojo-fqcn" data-sly-use.pojoFQCN="org.apache.sling.scripting.sightly.testing.precompiled.InternalUsePojo">
+ ${pojoFQCN.resourcePath}
</span><br/>
- <span class="internal-use-pojo-scn" data-sly-use.pojo="InternalUsePojo">
- ${pojo.resourcePath}
+ <span class="internal-use-pojo-scn" data-sly-use.pojoSCN="InternalUsePojo">
+ ${pojoSCN.resourcePath}
+ </span><br/>
+ <span class="internal-exported-sling-model"
+ data-sly-use.internalExportedSlingModel="${'org.apache.sling.scripting.sightly.testing.precompiled.models.ExportedTestModel' @ name ='John Doe'}">
+ ${internalExportedSlingModel.sayHello}
+ </span><br/>
+ <span class="internal-sling-model"
+ data-sly-use.internalSlingModel="${'org.apache.sling.scripting.sightly.testing.precompiled.models.impl.InternalTestModel' @ name ='John Doe'}">
+ ${internalSlingModel.sayHello}
</span><br/>
<span class="request-adapter"
data-sly-use.requestAdapter="org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject">
@@ -45,6 +53,15 @@
</span><br/>
<span class="test-service"
data-sly-use.testService="org.apache.sling.scripting.sightly.testing.use.TestService">
- ${testService.title}
+ ${testService.sayHello}
+ </span><br/>
+ <span class="internal-script" data-sly-use.scriptEcma="script.ecma">
+ ${scriptEcma}
+ </span><br/>
+ <span class="internal-jsuse-script" data-sly-use.scriptJsUseInternal="script.js">
+ ${scriptJsUseInternal.message}
</span><br/>
+ <span class="provided-jsuse-script" data-sly-use.providedJsUse="/apps/sightly/scripts/use/jsuse.js">
+ ${providedJsUse.resourceName} - ${providedJsUse.resourceResourceType}
+ </span>
</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 c23643b..3788cad 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
@@ -123,14 +123,16 @@ public class SlingSpecificsSightlyIT {
public void testInterfaceUset() {
String url = launchpadURL + SLING_JAVA_USE_INTERFACE;
String pageContent = client.getStringContent(url, 500);
- assertTrue(pageContent.contains("No use provider could resolve identifier"));
+ assertTrue(pageContent.contains(
+ "org.apache.sling.scripting.sightly.testing.adaptable.NonImplementedInterface represents an interface or an abstract class which cannot be instantiated"));
}
@Test
public void testAbstractClassUse() {
String url = launchpadURL + SLING_JAVA_USE_ABSTRACT;
String pageContent = client.getStringContent(url, 500);
- assertTrue(pageContent.contains("No use provider could resolve identifier"));
+ assertTrue(pageContent.contains(
+ "org.apache.sling.scripting.sightly.testing.adaptable.AbstractRequestAdapterUseObject represents an interface or an abstract class which cannot be instantiated"));
}
@Test
@@ -401,6 +403,13 @@ public class SlingSpecificsSightlyIT {
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"));
+ assertEquals("Hello World!", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.test-service"));
+ assertEquals("Hello, John Doe", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.internal-exported-sling-model"));
+ assertEquals("Hello, John Doe", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.internal-sling-model"));
+ assertEquals("Evaluating ECMA scripts works just fine!", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.internal-script"));
+ assertEquals("Evaluating Use JS-objects works just fine!", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span" +
+ ".internal-jsuse-script"));
+ assertEquals("precompiled - org/apache/sling/scripting/sightly/testing/precompiled", HTMLExtractor.innerHTML(url, pageContent, "div.precompiled > span.provided-jsuse-script"));
}
private void restartSightlyEngineBundle() throws InterruptedException, IOException {
diff --git a/src/test/provisioning/sightly.txt b/src/test/provisioning/sightly.txt
index 59ae84c..b7a225b 100644
--- a/src/test/provisioning/sightly.txt
+++ b/src/test/provisioning/sightly.txt
@@ -25,7 +25,6 @@
org.apache.sling/org.apache.sling.scripting.sightly.compiler.java
org.apache.sling/org.apache.sling.scripting.sightly
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