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 2016/01/04 17:13:05 UTC
svn commit: r1722909 - in /sling/trunk/bundles/scripting/sightly:
engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/
testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/
testing/ testing/src/test/java/o...
Author: radu
Date: Mon Jan 4 16:13:05 2016
New Revision: 1722909
URL: http://svn.apache.org/viewvc?rev=1722909&view=rev
Log:
SLING-5408 - Some Sightly Java Use objects stored in the repository are not recompiled on change
* trigger recompilation if loaded POJO was changed
Added:
sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/RepoPojo.java
sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/repopojo.html
sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.original
sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.updated
Modified:
sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
sling/trunk/bundles/scripting/sightly/testing/pom.xml
sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java?rev=1722909&r1=1722908&r2=1722909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java (original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java Mon Jan 4 16:13:05 2016
@@ -35,6 +35,7 @@ import org.apache.sling.api.scripting.Sl
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.scripting.sightly.impl.compiler.SightlyJavaCompilerService;
+import org.apache.sling.scripting.sightly.impl.compiler.UnitChangeMonitor;
import org.apache.sling.scripting.sightly.impl.utils.BindingsUtils;
import org.apache.sling.scripting.sightly.pojo.Use;
import org.apache.sling.scripting.sightly.render.RenderContext;
@@ -69,6 +70,9 @@ public class JavaUseProvider implements
private SightlyJavaCompilerService sightlyJavaCompilerService = null;
@Reference
+ private UnitChangeMonitor unitChangeMonitor = null;
+
+ @Reference
private ClassLoaderWriter classLoaderWriter = null;
@Override
@@ -85,6 +89,14 @@ public class JavaUseProvider implements
Object result;
try {
Class<?> cls = classLoaderWriter.getClassLoader().loadClass(identifier);
+ if (unitChangeMonitor.getLastModifiedDateForJavaUseObject(identifier) > 0) {
+ // the object is a POJO that was changed in the repository but not recompiled;
+ result = sightlyJavaCompilerService.getInstance(renderContext, identifier, true);
+ if (result instanceof Use) {
+ ((Use) result).init(BindingsUtils.merge(globalBindings, arguments));
+ }
+ return ProviderOutcome.success(result);
+ }
// attempt OSGi service load
result = sling.getService(cls);
if (result != null) {
Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/RepoPojo.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/RepoPojo.java?rev=1722909&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/RepoPojo.java (added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/RepoPojo.java Mon Jan 4 16:13:05 2016
@@ -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.
+ ******************************************************************************/
+package apps.sightly.scripts.use;
+
+public class RepoPojo {
+
+ public static final String message = "original";
+
+}
Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/repopojo.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/repopojo.html?rev=1722909&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/repopojo.html (added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/repopojo.html Mon Jan 4 16:13:05 2016
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Sightly Repository POJO Test</title>
+</head>
+<body>
+ <div id="repopojo" data-sly-use.repopojo="apps.sightly.scripts.use.RepoPojo">${repopojo.message}</div>
+</body>
+</html>
Modified: sling/trunk/bundles/scripting/sightly/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/pom.xml?rev=1722909&r1=1722908&r2=1722909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing/pom.xml Mon Jan 4 16:13:05 2016
@@ -270,6 +270,12 @@
<artifactId>org.osgi.compendium</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
<!-- Dependency for running Sling performance tests -->
<dependency>
Modified: sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java?rev=1722909&r1=1722908&r2=1722909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java (original)
+++ sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java Mon Jan 4 16:13:05 2016
@@ -18,11 +18,19 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.it;
+import java.io.IOException;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.InputStreamBody;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
-import io.sightly.tck.http.Client;
import io.sightly.tck.html.HTMLExtractor;
+import io.sightly.tck.http.Client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -40,6 +48,7 @@ public class SlingSpecificsSightlyIT {
private static final String SLING_JS_DEPENDENCY_RESOLUTION = "/sightly/use-sibling-dependency-resolution.html";
private static final String SLING_USE_INHERITANCE_WITHOVERLAY = "/sightly/useinheritance.html";
private static final String SLING_USE_INHERITANCE_WITHOUTOVERLAY = "/sightly/useinheritance.notoverlaid.html";
+ private static final String SLING_JAVA_USE_POJO_UPDATE = "/sightly/use.repopojo.html";
@BeforeClass
public static void init() {
@@ -147,4 +156,29 @@ public class SlingSpecificsSightlyIT {
assertEquals("notoverlaid", HTMLExtractor.innerHTML(url, pageContent, "#notoverlaid"));
}
+ @Test
+ public void testRepositoryPojoUpdate() throws Exception {
+ String url = launchpadURL + SLING_JAVA_USE_POJO_UPDATE;
+ String pageContent = client.getStringContent(url, 200);
+ assertEquals("original", HTMLExtractor.innerHTML(url + System.currentTimeMillis(), pageContent, "#repopojo"));
+ uploadFile("RepoPojo.java.updated", "RepoPojo.java", "/apps/sightly/scripts/use");
+ pageContent = client.getStringContent(url, 200);
+ assertEquals("updated", HTMLExtractor.innerHTML(url + System.currentTimeMillis(), pageContent, "#repopojo"));
+ uploadFile("RepoPojo.java.original", "RepoPojo.java", "/apps/sightly/scripts/use");
+ pageContent = client.getStringContent(url, 200);
+ assertEquals("original", HTMLExtractor.innerHTML(url + System.currentTimeMillis(), pageContent, "#repopojo"));
+ }
+
+ private void uploadFile(String fileName, String serverFileName, String url) throws IOException {
+ HttpClient httpClient = HttpClientBuilder.create().build();
+ HttpPost post = new HttpPost(launchpadURL + url);
+ post.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
+ MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
+ InputStreamBody inputStreamBody = new InputStreamBody(this.getClass().getClassLoader().getResourceAsStream(fileName),
+ ContentType.TEXT_PLAIN, fileName);
+ entityBuilder.addPart(serverFileName, inputStreamBody);
+ post.setEntity(entityBuilder.build());
+ httpClient.execute(post);
+ }
+
}
Added: sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.original
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.original?rev=1722909&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.original (added)
+++ sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.original Mon Jan 4 16:13:05 2016
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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 apps.sightly.scripts.use;
+
+public class RepoPojo {
+
+ public static final String message = "original";
+
+}
Added: sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.updated
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.updated?rev=1722909&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.updated (added)
+++ sling/trunk/bundles/scripting/sightly/testing/src/test/resources/RepoPojo.java.updated Mon Jan 4 16:13:05 2016
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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 apps.sightly.scripts.use;
+
+public class RepoPojo {
+
+ public static final String message = "updated";
+
+}