sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1731860 - in /sling/trunk/bundles/scripting/sightly: engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/ testing-content/ testing-content/src/main/resources/SLING-INF/ testing-content/src/main/resources/SLING-INF/apps/si...
Date Tue, 23 Feb 2016 14:29:37 GMT
Author: radu
Date: Tue Feb 23 14:29:37 2016
New Revision: 1731860

URL: http://svn.apache.org/viewvc?rev=1731860&view=rev
Log:
SLING-5543 - Sightly Use POJOs with CR+LF line endings are not compiled correctly

* improved package declaration detection in SightlyJavaCompilerService

Added:
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/README
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/org.apache.sling.scripting.sightly.testing-content-crlf.jar
Modified:
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
    sling/trunk/bundles/scripting/sightly/testing-content/pom.xml
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/sightly.json
    sling/trunk/bundles/scripting/sightly/testing/src/main/provisioning/model.txt
    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/compiler/SightlyJavaCompilerService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java?rev=1731860&r1=1731859&r2=1731860&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
Tue Feb 23 14:29:37 2016
@@ -68,7 +68,7 @@ public class SightlyJavaCompilerService
 
     private static final Logger LOG = LoggerFactory.getLogger(SightlyJavaCompilerService.class);
 
-    public static final Pattern PACKAGE_DECL_PATTERN = Pattern.compile("(.*)(package\\s+([a-zA-Z_$][a-zA-Z\\d_$]*\\.?)*;)(.*)");
+    public static final Pattern PACKAGE_DECL_PATTERN = Pattern.compile("package\\s+([a-zA-Z_$][a-zA-Z\\d_$]*\\.?)+;");
 
     @Reference
     private ClassLoaderWriter classLoaderWriter = null;
@@ -163,24 +163,27 @@ public class SightlyJavaCompilerService
             IOUtils.closeQuietly(os);
         }
 
-        StringBuilder sourceCodeSB = new StringBuilder();
-        String[] sourceCodeLines = sourceCode.split("\n");
+        String[] sourceCodeLines = sourceCode.split("\\r\\n|[\\n\\x0B\\x0C\\r\\u0085\\u2028\\u2029]");
         boolean foundPackageDeclaration = false;
         for (String line : sourceCodeLines) {
             Matcher matcher = PACKAGE_DECL_PATTERN.matcher(line);
             if (matcher.matches()) {
-                line = matcher.group(1) + "package " + Utils.getPackageNameFromFQCN(fqcn)
+ ";" + matcher.group(4);
+                /**
+                 * This matching might return false positives like:
+                 * // package a.b.c;
+                 *
+                 * where from a syntactic point of view the source code doesn't have a package
declaration and the expectancy is that our
+                 * SightlyJavaCompilerService will add one.
+                 */
                 foundPackageDeclaration = true;
             }
-            sourceCodeSB.append(line).append("\n");
         }
 
         if (!foundPackageDeclaration) {
-            sourceCodeSB.insert(0, "package " + Utils.getPackageNameFromFQCN(fqcn) + ";\n");
+            sourceCode = "package " + Utils.getPackageNameFromFQCN(fqcn) + ";\n" + sourceCode;
         }
 
-        CompilationUnit compilationUnit = new SightlyCompilationUnit(sourceCodeSB.toString(),
fqcn);
-
+        CompilationUnit compilationUnit = new SightlyCompilationUnit(sourceCode, fqcn);
         long start = System.currentTimeMillis();
         CompilationResult compilationResult = javaCompiler.compile(new CompilationUnit[]{compilationUnit},
options);
         long end = System.currentTimeMillis();

Modified: sling/trunk/bundles/scripting/sightly/testing-content/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/pom.xml?rev=1731860&r1=1731859&r2=1731860&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing-content/pom.xml Tue Feb 23 14:29:37 2016
@@ -141,7 +141,7 @@
                             javax.inject;version=1.0.0,
                             *
                         </Import-Package>
-                        <Sling-Initial-Content>SLING-INF;uninstall:=true</Sling-Initial-Content>
+                        <Sling-Initial-Content>SLING-INF;uninstall:=true;ignoreImportProviders:=jar</Sling-Initial-Content>
                         <Sling-Model-Packages>org.apache.sling.scripting.sightly.testing.models</Sling-Model-Packages>
                         <Require-Capability>io.sightly; filter:="(&amp;(version&gt;=1.0)(!(version&gt;=2.0)))"</Require-Capability>
                     </instructions>

Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/README
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/README?rev=1731860&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/README
(added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/README
Tue Feb 23 14:29:37 2016
@@ -0,0 +1,2 @@
+The org.apache.sling.scripting.sightly.testing-content-crlf provides testing content for
SLING-5543 which can not be easily saved into
+SCM in a reliable way so that line endings are maintained without alteration.

Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/org.apache.sling.scripting.sightly.testing-content-crlf.jar
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/org.apache.sling.scripting.sightly.testing-content-crlf.jar?rev=1731860&view=auto
==============================================================================
Binary files sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/org.apache.sling.scripting.sightly.testing-content-crlf.jar
(added) and sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/install/org.apache.sling.scripting.sightly.testing-content-crlf.jar
Tue Feb 23 14:29:37 2016 differ

Modified: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/sightly.json
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/sightly.json?rev=1731860&r1=1731859&r2=1731860&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/sightly.json
(original)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/sightly.json
Tue Feb 23 14:29:37 2016
@@ -32,5 +32,9 @@
     "attributequotes": {
         "jcr:primaryType": "nt:unstructured",
         "sling:resourceType": "/apps/sightly/scripts/attributequotes"
+    },
+    "crlf": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "/apps/sightly/scripts/crlf"
     }
 }

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=1731860&r1=1731859&r2=1731860&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 Tue Feb
23 14:29:37 2016
@@ -20,7 +20,7 @@
 # Dependencies
 [artifacts]
   org.apache.sling/org.apache.sling.launchpad/8/slingstart
-  org.apache.sling/org.apache.sling.scripting.javascript/2.0.27-SNAPSHOT
+  org.apache.sling/org.apache.sling.scripting.javascript/2.0.29-SNAPSHOT
   org.apache.sling/org.apache.sling.scripting.sightly/1.0.13-SNAPSHOT
   org.apache.sling/org.apache.sling.scripting.sightly.js.provider/1.0.11-SNAPSHOT
   org.apache.sling/org.apache.sling.scripting.sightly.models.provider/1.0.1-SNAPSHOT

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=1731860&r1=1731859&r2=1731860&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
Tue Feb 23 14:29:37 2016
@@ -52,6 +52,11 @@ public class SlingSpecificsSightlyIT {
     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";
     private static final String SLING_ATTRIBUTE_QUOTES = "/sightly/attributequotes.html";
+    private static final String SLING_CRLF = "/sightly/crlf";
+    private static final String SLING_CRLF_NOPKG = SLING_CRLF + ".nopkg.html";
+    private static final String SLING_CRLF_PKG = SLING_CRLF + ".pkg.html";
+    private static final String SLING_CRLF_WRONGPKG = SLING_CRLF + ".wrongpkg.html";
+
 
     @BeforeClass
     public static void init() {
@@ -189,6 +194,27 @@ public class SlingSpecificsSightlyIT {
         assertTrue(pageContent.contains("<span data-resource=\"/sightly/attributequotes\">/sightly/attributequotes</span>"));
     }
 
+    @Test
+    public void testCRLFNoPkg() {
+        String url = launchpadURL + SLING_CRLF_NOPKG;
+        String pageContent = client.getStringContent(url, 200);
+        assertEquals("nopkg", HTMLExtractor.innerHTML(url, pageContent, "#repopojocrlf-nopkg"));
+    }
+
+    @Test
+    public void testCRLFPkg() {
+        String url = launchpadURL + SLING_CRLF_PKG;
+        String pageContent = client.getStringContent(url, 200);
+        assertEquals("pkg", HTMLExtractor.innerHTML(url, pageContent, "#repopojocrlf-pkg"));
+    }
+
+    @Test
+    public void testCRLFWrongPkg() {
+        String url = launchpadURL + SLING_CRLF_WRONGPKG;
+        String pageContent = client.getStringContent(url, 500);
+        assertTrue(pageContent.contains("CompilerException"));
+    }
+
     private void uploadFile(String fileName, String serverFileName, String url) throws IOException
{
         HttpClient httpClient = HttpClientBuilder.create().build();
         HttpPost post = new HttpPost(launchpadURL + url);



Mime
View raw message