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 2017/01/09 14:38:45 UTC
svn commit: r1777973 - in /sling/trunk/bundles/scripting/sightly: compiler/
compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/
compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/
compiler/src/test/resources/ testin...
Author: radu
Date: Mon Jan 9 14:38:45 2017
New Revision: 1777973
URL: http://svn.apache.org/viewvc?rev=1777973&view=rev
Log:
SLING-6445 - HTL scripts do not compile on Windows if the compiler needs to generate any warnings
* applied patch from Vlad B\u0103ilescu
* improved launchpad readiness test
* updated HTL test dependencies
(Closes #196)
Added:
sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-mac.html
sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-win.html
Modified:
sling/trunk/bundles/scripting/sightly/compiler/pom.xml
sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyCompilerTest.java
sling/trunk/bundles/scripting/sightly/testing/pom.xml
sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt
sling/trunk/bundles/scripting/sightly/testing/src/test/java/LaunchpadReadyIT.java
Modified: sling/trunk/bundles/scripting/sightly/compiler/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/pom.xml?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/compiler/pom.xml Mon Jan 9 14:38:45 2017
@@ -234,7 +234,19 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
- <version>1.5.5</version>
+ <version>1.6.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java (original)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java Mon Jan 9 14:38:45 2017
@@ -166,8 +166,19 @@ public final class SightlyCompiler {
int offendingInputIndex = documentFragment.indexOf(offendingInput);
if (offendingInputIndex > -1) {
String textBeforeError = documentFragment.substring(0, offendingInputIndex);
- int line = lineOffset + textBeforeError.length() - textBeforeError.replaceAll(System.lineSeparator(), "").length();
- int column = textBeforeError.substring(textBeforeError.lastIndexOf(System.lineSeparator())).length();
+ int line = lineOffset;
+ int lastNewLineIndex = 0;
+ for (String s : new String[] {"\r\n", "\r", "\n"}) {
+ int l = textBeforeError.split(s, -1).length - 1;
+ if (l + lineOffset > line) {
+ line = l + lineOffset;
+ int ix = textBeforeError.lastIndexOf(s);
+ if (ix > 0) {
+ lastNewLineIndex = ix + s.length() - 1;
+ }
+ }
+ }
+ int column = textBeforeError.substring(lastNewLineIndex).length();
if (column != columnOffset) {
column +=columnOffset;
}
Modified: sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyCompilerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyCompilerTest.java?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyCompilerTest.java (original)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/test/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyCompilerTest.java Mon Jan 9 14:38:45 2017
@@ -26,10 +26,16 @@ import org.apache.sling.scripting.sightl
import org.apache.sling.scripting.sightly.compiler.SightlyCompiler;
import org.apache.sling.scripting.sightly.impl.TestUtils;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SightlyCompiler.class)
public class SightlyCompilerTest {
private SightlyCompiler compiler = new SightlyCompiler();
@@ -42,18 +48,47 @@ public class SightlyCompilerTest {
@Test
public void testMissingExplicitContext() {
- String script = "/missing-explicit-context.html";
+ for (String s : new String[] {"", "-win", "-mac"}) {
+ String script = "/missing-explicit-context" + s + ".html";
+ testMissingExplicitContext(script);
+ }
+ }
+
+ private void testMissingExplicitContext(String script) {
CompilationResult result = compile(script);
List<CompilerMessage> warnings = result.getWarnings();
- assertTrue("Expected compilation warnings.", warnings.size() == 1);
+ assertTrue(script + ": Expected compilation warnings.", warnings.size() == 1);
CompilerMessage warningMessage = warnings.get(0);
- assertEquals("Expected warning on a different line.", 18, warningMessage.getLine());
+ assertEquals(script + ": Expected warning on a different line.", 18, warningMessage.getLine());
+ assertEquals(script + ": Expected warning on a different column.", 14, warningMessage.getColumn());
assertTrue(script.equals(warningMessage.getScriptName()));
assertEquals("${some.value}: Element script requires that all expressions have an explicit context specified. The expression will" +
" be replaced with an empty string.", warningMessage.getMessage());
}
@Test
+ public void testMissingExplicitContextOnWindows() {
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.lineSeparator()).thenReturn("\r\n");
+
+ for (String s : new String[] {"", "-win", "-mac"}) {
+ String script = "/missing-explicit-context" + s + ".html";
+ testMissingExplicitContext(script);
+ }
+ }
+
+ @Test
+ public void testMissingExplicitContextOnMac() {
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.lineSeparator()).thenReturn("\r");
+
+ for (String s : new String[] {"", "-win", "-mac"}) {
+ String script = "/missing-explicit-context" + s + ".html";
+ testMissingExplicitContext(script);
+ }
+ }
+
+ @Test
public void testSensitiveAttributes() {
String script = "/sensitive-attributes.html";
CompilationResult result = compile(script);
Added: sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-mac.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-mac.html?rev=1777973&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-mac.html (added)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-mac.html Mon Jan 9 14:38:45 2017
@@ -0,0 +1 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
<script>
var a = '${some.value}';
</script>
\ No newline at end of file
Added: sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-win.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-win.html?rev=1777973&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-win.html (added)
+++ sling/trunk/bundles/scripting/sightly/compiler/src/test/resources/missing-explicit-context-win.html Mon Jan 9 14:38:45 2017
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+<script>
+ var a = '${some.value}';
+</script>
Modified: sling/trunk/bundles/scripting/sightly/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/pom.xml?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing/pom.xml Mon Jan 9 14:38:45 2017
@@ -70,11 +70,11 @@
<jacoco.maven.plugin.version>0.7.6.201602180812</jacoco.maven.plugin.version>
<!-- HTL modules under test versions -->
- <org.apache.sling.scripting.sightly.compiler.version>1.0.3-SNAPSHOT</org.apache.sling.scripting.sightly.compiler.version>
- <org.apache.sling.scripting.sightly.compiler.java.version>1.0.5-SNAPSHOT</org.apache.sling.scripting.sightly.compiler.java.version>
- <org.apache.sling.scripting.sightly.version>1.0.27-SNAPSHOT</org.apache.sling.scripting.sightly.version>
- <org.apache.sling.scripting.sightly.js.provider.version>1.0.17-SNAPSHOT</org.apache.sling.scripting.sightly.js.provider.version>
- <org.apache.sling.scripting.sightly.models.provider.version>1.0.5-SNAPSHOT</org.apache.sling.scripting.sightly.models.provider.version>
+ <org.apache.sling.scripting.sightly.compiler.version>1.0.5-SNAPSHOT</org.apache.sling.scripting.sightly.compiler.version>
+ <org.apache.sling.scripting.sightly.compiler.java.version>1.0.7-SNAPSHOT</org.apache.sling.scripting.sightly.compiler.java.version>
+ <org.apache.sling.scripting.sightly.version>1.0.29-SNAPSHOT</org.apache.sling.scripting.sightly.version>
+ <org.apache.sling.scripting.sightly.js.provider.version>1.0.19-SNAPSHOT</org.apache.sling.scripting.sightly.js.provider.version>
+ <org.apache.sling.scripting.sightly.models.provider.version>1.0.7-SNAPSHOT</org.apache.sling.scripting.sightly.models.provider.version>
</properties>
<build>
@@ -452,6 +452,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.rules</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt (original)
+++ sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt Mon Jan 9 14:38:45 2017
@@ -25,9 +25,6 @@
# Dependencies
[artifacts]
org.apache.sling/org.apache.sling.launchpad/9-SNAPSHOT/slingstart
- org.apache.sling/org.apache.sling.jcr.resource/2.9.1-SNAPSHOT
- org.apache.sling/org.apache.sling.scripting.api/2.1.12
- org.apache.sling/org.apache.sling.scripting.core/2.0.44
org.apache.sling/org.apache.sling.scripting.sightly.compiler
org.apache.sling/org.apache.sling.scripting.sightly.compiler.java
org.apache.sling/org.apache.sling.scripting.sightly
Modified: sling/trunk/bundles/scripting/sightly/testing/src/test/java/LaunchpadReadyIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/test/java/LaunchpadReadyIT.java?rev=1777973&r1=1777972&r2=1777973&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/test/java/LaunchpadReadyIT.java (original)
+++ sling/trunk/bundles/scripting/sightly/testing/src/test/java/LaunchpadReadyIT.java Mon Jan 9 14:38:45 2017
@@ -17,16 +17,21 @@
* under the License.
******************************************************************************/
-import java.io.IOException;
-
-import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.testing.clients.SlingClient;
+import org.apache.sling.testing.junit.rules.SlingInstanceRule;
+import org.junit.ClassRule;
import org.junit.Test;
-public class LaunchpadReadyIT extends HttpTestBase {
+public class LaunchpadReadyIT {
+
+ @ClassRule
+ public static final SlingInstanceRule SLING_INSTANCE_RULE = new SlingInstanceRule();
@Test
- public void testLaunchpadReady() throws IOException {
- assertHttpStatus(HTTP_URL + "/index.html", 200);
+ public void testLaunchpadReady() throws Exception {
+ SlingClient client = SLING_INSTANCE_RULE.getAdminClient();
+ client.waitUntilExists("/apps/sightly", 100, 100);
+ client.waitUntilExists("/sightlytck", 100, 100);
}
}