You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:22:16 UTC
[sling-org-apache-sling-scripting-sightly-compiler-java] branch
master created (now cd39d0a)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git.
at cd39d0a SLING-7205 - Generate import statements for data-sly-use Java use objects
This branch includes the following new commits:
new ccb2c05 SLING-5787 - Modularise the Sightly script engine
new 25ffd02 trivial: added scm info + updated readme for sightly modules
new 7df537b SLING-5825 - Add support for implicit conversion of Enum to String
new 30a698f SLING-6028 - Replace Sightly references with HTL in both code and documentation
new 495fb6d SLING-6033 - Update Sightly bundles to parent pom 28
new dc7c4d4 trivial: corrected JavaDoc
new 522ca83 trivial: configured javadoc plugin
new ff13419 releng: updated dependency
new f84baa1 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.0
new efbad8b [maven-release-plugin] prepare for next development iteration
new b6a7525 releng: updated dependencies
new c988fec SLING-6094 - HTL can generate invalid Java code by using user-supplied input
new 087d83c SLING-6094 - HTL can generate invalid Java code by using user-supplied input
new 7fafafa SLING-6094 - HTL can generate invalid Java code by using user-supplied input
new bd046d0 SLING-6125 - Switch HTL to OSGi R6 annotations
new 0096b63 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.2
new 341a765 [maven-release-plugin] prepare for next development iteration
new a4081db SLING-6146 - SourceIdentifier should not mangle underscore characters
new 87554d7 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.4
new abde4bd [maven-release-plugin] prepare for next development iteration
new ee08d99 SLING-6186 - Add support for checking code coverage with jacoco
new b64b190 SLING-6186 - Add support for checking code coverage with jacoco
new d9fbfa1 SLING-6399 - Implement support for date and number formatting for HTL
new 9dd2698 SLING-6399 - Implement support for date and number formatting for HTL
new 041a7de releng: updated o.a.s.scripting.sightly.compiler dependency to 1.0.4
new 7d96e58 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.6
new 1c09793 [maven-release-plugin] prepare for next development iteration
new 6a61604 update to next snapshot version until releases are available on maven central
new 1dd9a28 SLING-6428 - DateFormat is printed when date-value is empty
new 81e708f SLING-6450 - [HTL] Cannot retrieve "length" property for arrays of primitive types
new 81e0e34 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.8
new 9bb9682 [maven-release-plugin] prepare for next development iteration
new 370429b use Sling Parent 30
new c7b2445 SLING-6633 - [HTL] NumberFormat should support String-properties with number value
new f6d17f4 SLING-6633 - [HTL] NumberFormat should support String-properties with number value
new 8a82bef SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler bundles
new 7e5aa10 SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler bundles
new fc06b38 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.10
new f8b6077 [maven-release-plugin] prepare for next development iteration
new 865fe2e releng: updated Provide-Capability bundle headers for HTL modules
new bd4eb8e SLING-7040 : Update commons lang 2.x to 3.5
new 0ec2560 SLING-7084 - Coverage report is not generated correctly for HTL modules
new 4f0b70d SLING-7085 - Reduce code duplication
new 97414e4 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.12
new e497ab3 [maven-release-plugin] prepare for next development iteration
new 663eb12 [maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.14
new 8f21364 [maven-release-plugin] prepare for next development iteration
new c4e666e releng: adjusted dependencies after staging release
new 7fa5a1a SLING-7167 Adjust READMEs
new cd39d0a SLING-7205 - Generate import statements for data-sly-use Java use objects
The 50 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].
[sling-org-apache-sling-scripting-sightly-compiler-java] 19/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.4
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 87554d73f45111041a9b6c0b5c5f5002d33fea89
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Oct 14 08:06:08 2016 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.4
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764828 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 698162a..18acf48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.3-SNAPSHOT</version>
+ <version>1.0.4</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 07/50:
trivial: configured javadoc plugin
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 522ca831edcaad0a276dd9541a943d8cf52cba7b
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 15:05:35 2016 +0000
trivial: configured javadoc plugin
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759284 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/pom.xml b/pom.xml
index 54772a2..ab66fd9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -99,6 +99,16 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <!-- No javadocs -->
+ <excludePackageNames>
+ org.apache.sling.scripting.sightly.java.compiler.impl
+ </excludePackageNames>
+ </configuration>
+ </plugin>
</plugins>
</build>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 30/50:
SLING-6450 - [HTL] Cannot retrieve "length" property for arrays of
primitive types
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 81e708f8094278d8e909c948cc96ddeeea78c387
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Jan 11 11:57:58 2017 +0000
SLING-6450 - [HTL] Cannot retrieve "length" property for arrays of primitive types
* treated all arrays in a unitary way, irrespective of their type, for "length" retrieval
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1778282 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/render/AbstractRuntimeObjectModel.java | 8 ++---
.../render/AbstractRuntimeObjectModelTest.java | 34 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index 357d680..4b512c3 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -16,6 +16,7 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.render;
+import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -306,11 +307,10 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
}
protected static Object getField(Object obj, String property) {
- if (obj instanceof Object[] && "length".equals(property)) {
- // Working around this limitation: http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getFields%28%29
- return ((Object[]) obj).length;
- }
Class<?> cls = obj.getClass();
+ if (cls.isArray() && "length".equals(property)) {
+ return Array.getLength(obj);
+ }
try {
Field field = cls.getDeclaredField(property);
return field.get(obj);
diff --git a/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java b/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java
new file mode 100644
index 0000000..1cc988c
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModelTest.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.render;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class AbstractRuntimeObjectModelTest {
+
+ private AbstractRuntimeObjectModel runtimeObjectModel = new AbstractRuntimeObjectModel() {};
+
+ @Test
+ public void testResolveProperty_ArrayLength() throws Exception {
+ int[] ints = new int[] {1, 2, 3};
+ Integer[] integers = new Integer[] {1, 2, 3};
+ assertEquals(ints.length, runtimeObjectModel.resolveProperty(ints, "length"));
+ assertEquals(integers.length, runtimeObjectModel.resolveProperty(integers, "length"));
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 17/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 341a76501ae079552000528311d620b8edb9c776
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Oct 10 15:47:07 2016 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764129 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4df353b..698162a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.2</version>
+ <version>1.0.3-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 32/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 9bb96828d9796c34cf960767b6099c946d0d7320
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Jan 13 11:17:52 2017 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1778545 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5a6f9ed..721e87f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.8</version>
+ <version>1.0.9-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 49/50:
SLING-7167 Adjust READMEs
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 7fa5a1a9a0c1cf77d7827f2841975312a3072146
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Oct 3 10:00:38 2017 +0000
SLING-7167 Adjust READMEs
add uniform header linking to Sling project
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810877 13f79535-47bb-0310-9956-ffa450edef68
---
README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 1b811f4..ca28942 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
-Apache Sling Scripting HTL Java Compiler
-========================================
+# Apache Sling Scripting HTL Java Compiler
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
The Apache Sling Scripting HTL Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
[`org.apache.sling.scripting.sightly.compiler`](../compiler) module into Java source code.
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 44/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.12
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 97414e49c1d8e6d35e0f6032eec28db1a1bd12c0
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Aug 29 11:09:24 2017 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.12
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1806561 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index c3f6de2..5f1f6d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.11-SNAPSHOT</version>
+ <version>1.0.12</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</url>
</scm>
<properties>
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.11-SNAPSHOT</version>
+ <version>1.0.12</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 11/50:
releng: updated dependencies
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit b6a752594ee928e86dd3fe73143e588a84c368fc
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 15:57:11 2016 +0000
releng: updated dependencies
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759318 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c763894..5d3a09e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,7 +120,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 04/50:
SLING-6028 - Replace Sightly references with HTL in both code and
documentation
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 30a698f2b830bc3a5b90ec33c55c27cf8b5b1157
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 2 14:51:07 2016 +0000
SLING-6028 - Replace Sightly references with HTL in both code and documentation
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1758968 13f79535-47bb-0310-9956-ffa450edef68
---
README.md | 6 +++---
pom.xml | 14 ++++----------
.../java/org/apache/sling/scripting/sightly/Record.java | 2 +-
.../scripting/sightly/extension/RuntimeExtension.java | 2 +-
.../sling/scripting/sightly/java/compiler/RenderUnit.java | 6 +++---
.../sightly/java/compiler/impl/VariableScope.java | 2 +-
.../java/org/apache/sling/scripting/sightly/pojo/Use.java | 4 ++--
.../sling/scripting/sightly/render/RenderContext.java | 4 ++--
.../sling/scripting/sightly/render/RuntimeObjectModel.java | 2 +-
9 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 5445259..1b811f4 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-Apache Sling Scripting Sightly Java Compiler
-====
-The Apache Sling Scripting Sightly Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
+Apache Sling Scripting HTL Java Compiler
+========================================
+The Apache Sling Scripting HTL Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
[`org.apache.sling.scripting.sightly.compiler`](../compiler) module into Java source code.
diff --git a/pom.xml b/pom.xml
index 005effe..3d58d8c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,10 +34,10 @@
<version>0.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
- <name>Apache Sling Scripting Sightly Java Compiler</name>
+ <name>Apache Sling Scripting HTL Java Compiler</name>
<description>
- The Apache Sling Scripting Sightly Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
+ The Apache Sling Scripting HTL Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
org.apache.sling.scripting.sightly.compiler module into Java source code.
</description>
@@ -119,14 +119,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
- <groups>
- <group>
- <title>Apache Sling Scriptin Sightly Java Compiler</title>
- <packages>org.apache.sling.scripting.sightly.compiler.java</packages>
- </group>
- </groups>
- <doctitle>${project.name} Documentation (Version: ${project.version})</doctitle>
- <windowtitle>${project.name} Documentation (Version: ${project.version})</windowtitle>
+ <stylesheet>maven</stylesheet>
+ <excludePackageNames>*.impl:*.internal:${site.javadoc.exclude}</excludePackageNames>
</configuration>
</plugin>
</plugins>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/Record.java b/src/main/java/org/apache/sling/scripting/sightly/Record.java
index 0b27f0c..ead00db 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/Record.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/Record.java
@@ -24,7 +24,7 @@ import java.util.Set;
import aQute.bnd.annotation.ConsumerType;
/**
- * A {@code Record} is a key-value immutable object understood by the Sightly runtime, used for abstracting complex objects like Sightly
+ * A {@code Record} is a key-value immutable object understood by the HTL runtime, used for abstracting complex objects like Sightly
* templates (declared with the {@code data-sly-template} block element) or objects that need to be translated from Java to JavaScript
* and back.
*
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
index c14b95e..186495b 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
@@ -23,7 +23,7 @@ import org.apache.sling.scripting.sightly.render.RenderContext;
import aQute.bnd.annotation.ConsumerType;
/**
- * A {@code RuntimeExtension} represents a Sightly runtime construct that provides some processing capabilities for the various
+ * A {@code RuntimeExtension} represents a HTL runtime construct that provides some processing capabilities for the various
* {@code data-sly-*} block elements.
*/
@ConsumerType
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
index 0b68af3..d9f831c 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
@@ -70,13 +70,13 @@ public abstract class RenderUnit implements Record<RenderUnit> {
}
if (renderContext.getObjectModel().isPrimitive(templateObj)) {
throw new SightlyJavaCompilerException(
- "data-sly-call: primitive \"" + templateObj.toString() + "\" does not represent a Sightly template.");
+ "data-sly-call: primitive \"" + templateObj.toString() + "\" does not represent a HTL template.");
} else if (templateObj instanceof String) {
throw new SightlyJavaCompilerException(
- "data-sly-call: String '" + templateObj.toString() + "' does not represent a Sightly template.");
+ "data-sly-call: String '" + templateObj.toString() + "' does not represent a HTL template.");
}
throw new SightlyJavaCompilerException(
- "data-sly-call: " + templateObj.getClass().getName() + " does not represent a Sightly template.");
+ "data-sly-call: " + templateObj.getClass().getName() + " does not represent a HTL template.");
}
RenderUnit unit = (RenderUnit) templateObj;
Map<String, Object> argumentsMap = renderContext.getObjectModel().toMap(argsObj);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java
index 9b34322..7e2fb75 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java
@@ -18,7 +18,7 @@
package org.apache.sling.scripting.sightly.java.compiler.impl;
/**
- * The scope of a variable in a Sightly script
+ * The scope of a variable in a HTL script
*/
public enum VariableScope {
DYNAMIC, SCOPED, GLOBAL
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
index 48943f3..d4ec318 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
@@ -26,7 +26,7 @@ import aQute.bnd.annotation.ConsumerType;
* The <code>Use</code> interface can be implemented by Java objects which are instantiated as part of processing {@code data-sly-use}
* attributes.
*
- * @see <a href="https://github.com/Adobe-Marketing-Cloud/sightly-spec/blob/master/SPECIFICATION.md#221-use">Sightly Block Statements - Use</a>
+ * @see <a href="https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md#221-use">HTL Block Statements - Use</a>
*/
@ConsumerType
public interface Use {
@@ -36,7 +36,7 @@ public interface Use {
* Called to initialize the Java object with the current Java Scripting API bindings.
* </p>
* <p/>
- * This method is called only if the object has been instantiated by Sightly as part of processing the {@code data-sly-use}
+ * This method is called only if the object has been instantiated by HTL as part of processing the {@code data-sly-use}
* attribute. The Java Scripting API bindings provide all the global variables known to a script being executed.
* <p/>
*
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
index bb06812..d0a4390 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
@@ -23,7 +23,7 @@ import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
import aQute.bnd.annotation.ProviderType;
/**
- * The {@code RenderContext} defines the context for executing Sightly scripts.
+ * The {@code RenderContext} defines the context for executing HTL scripts.
*/
@ProviderType
public interface RenderContext {
@@ -36,7 +36,7 @@ public interface RenderContext {
RuntimeObjectModel getObjectModel();
/**
- * Returns the map of script bindings available to Sightly scripts.
+ * Returns the map of script bindings available to HTL scripts.
*
* @return the global bindings for a script
*/
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
index f45a8e9..2945402 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
@@ -23,7 +23,7 @@ import aQute.bnd.annotation.ProviderType;
/**
* The {@code RuntimeObjectModel} provides various utility object inspection & conversion methods that can be applied to runtime
- * objects when executing Sightly scripts.
+ * objects when executing HTL scripts.
*/
@ProviderType
public interface RuntimeObjectModel {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 14/50:
SLING-6094 - HTL can generate invalid Java code by using user-supplied
input
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 7fafafa94ff78ea745533179bc35eb2ce6a4b52f
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Oct 7 13:35:28 2016 +0000
SLING-6094 - HTL can generate invalid Java code by using user-supplied input
* added license headers to pass rat checks
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763761 13f79535-47bb-0310-9956-ffa450edef68
---
src/test/resources/SLING-6094.1.html | 4 ++--
src/test/resources/SLING-6094.1.output.html | 17 ++++++++++++++++-
src/test/resources/SLING-6094.2.html | 4 ++--
src/test/resources/SLING-6094.2.output.html | 17 ++++++++++++++++-
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/src/test/resources/SLING-6094.1.html b/src/test/resources/SLING-6094.1.html
index e2706e2..9e4c1e9 100644
--- a/src/test/resources/SLING-6094.1.html
+++ b/src/test/resources/SLING-6094.1.html
@@ -1,4 +1,4 @@
-<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
@@ -13,5 +13,5 @@
~ 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.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<img src="" v-bind:src="abc" data-sly-attribute="${img.attributes}" />
diff --git a/src/test/resources/SLING-6094.1.output.html b/src/test/resources/SLING-6094.1.output.html
index 2ce0be5..96744cf 100644
--- a/src/test/resources/SLING-6094.1.output.html
+++ b/src/test/resources/SLING-6094.1.output.html
@@ -1,2 +1,17 @@
-
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<img src="" v-bind:src="replaced"/>
diff --git a/src/test/resources/SLING-6094.2.html b/src/test/resources/SLING-6094.2.html
index fe07e01..2470e30 100644
--- a/src/test/resources/SLING-6094.2.html
+++ b/src/test/resources/SLING-6094.2.html
@@ -1,4 +1,4 @@
-<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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.
@@ -13,5 +13,5 @@
~ 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 data-sly-test.jcr:title="${1>0}">correctly escaped variable</div>
diff --git a/src/test/resources/SLING-6094.2.output.html b/src/test/resources/SLING-6094.2.output.html
index cad8097..90f0246 100644
--- a/src/test/resources/SLING-6094.2.output.html
+++ b/src/test/resources/SLING-6094.2.output.html
@@ -1,2 +1,17 @@
-
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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>correctly escaped variable</div>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 25/50:
releng: updated o.a.s.scripting.sightly.compiler dependency to 1.0.4
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 041a7dea0245620e1dad694413064de2044db93d
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Dec 15 14:07:03 2016 +0000
releng: updated o.a.s.scripting.sightly.compiler dependency to 1.0.4
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774451 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a492b2f..f0f4af3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,7 +156,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.0</version>
+ <version>1.0.4</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 39/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit f8b6077e235d391e3b5672c8c336c825f8ee9981
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri May 5 12:32:52 2017 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1794035 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index b69aa93..0176ee6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.10</version>
+ <version>1.0.11-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 50/50:
SLING-7205 - Generate import statements for data-sly-use Java use objects
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit cd39d0a5e2b2f685c793931b7e09b262de7fd19e
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Oct 18 16:00:09 2017 +0000
SLING-7205 - Generate import statements for data-sly-use Java use objects
* added support for generating the import statements for fully qualified Java
class names passed as identifiers to data-sly-resource; use objects stored in the
repository are ignored
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1812544 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 1 +
.../java/compiler/JavaClassBackendCompiler.java | 18 ++++++++++-
.../sightly/java/compiler/JavaImportsAnalyzer.java | 37 ++++++++++++++++++++++
.../sightly/java/compiler/impl/CodeGenVisitor.java | 4 +--
.../java/compiler/impl/JavaClassTemplate.java | 10 ++++--
.../scripting/sightly/java/compiler/impl/Type.java | 31 ++++++++++++------
.../sightly/java/compiler/impl/TypeInference.java | 30 ++++++++++++++----
.../sightly/java/compiler/impl/UnitBuilder.java | 17 ++++++++--
.../java/compiler/impl/VariableDescriptor.java | 2 +-
.../sightly/java/compiler/package-info.java | 2 +-
.../resources/templates/compiled_unit_template.txt | 2 ++
.../java/JavaClassBackendCompilerTest.java | 12 +++++++
src/test/resources/imports.html | 22 +++++++++++++
.../resources/imports.html.java} | 19 ++++++++---
14 files changed, 176 insertions(+), 31 deletions(-)
diff --git a/pom.xml b/pom.xml
index b891e9d..51b6c0a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
<properties>
<jacoco.maven.plugin.version>0.7.9</jacoco.maven.plugin.version>
+ <sling.java.version>8</sling.java.version>
</properties>
<!-- ======================================================================= -->
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java
index 87e9655..8069cb0 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java
@@ -38,7 +38,8 @@ public final class JavaClassBackendCompiler implements BackendCompiler {
private static final String mainTemplate;
private static final String childTemplate;
- private UnitBuilder unitBuilder = new UnitBuilder();
+ private UnitBuilder unitBuilder;
+ private final JavaImportsAnalyzer JAVA_IMPORTS_ANALYZER;
static {
try {
@@ -50,6 +51,14 @@ public final class JavaClassBackendCompiler implements BackendCompiler {
}
}
+ public JavaClassBackendCompiler() {
+ this(new JavaImportsAnalyzer() {});
+ }
+
+ public JavaClassBackendCompiler(JavaImportsAnalyzer javaImportsAnalyzer) {
+ JAVA_IMPORTS_ANALYZER = javaImportsAnalyzer;
+ unitBuilder = new UnitBuilder(JAVA_IMPORTS_ANALYZER);
+ }
@Override
public void handle(CommandStream stream) {
@@ -76,6 +85,13 @@ public final class JavaClassBackendCompiler implements BackendCompiler {
JavaClassTemplate mainTemplate = newMainTemplate();
mainTemplate.setPackageName(classInfo.getPackageName());
mainTemplate.setClassName(classInfo.getSimpleClassName());
+ StringBuilder imports = new StringBuilder();
+ for (String importClass : unitBuilder.getImports()) {
+ if (JAVA_IMPORTS_ANALYZER.allowImport(importClass)) {
+ imports.append("import ").append(importClass).append(";").append(System.lineSeparator());
+ }
+ }
+ mainTemplate.setImports(imports.toString());
processCompilationResult(compilationOutput, mainTemplate);
return mainTemplate.toString();
}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaImportsAnalyzer.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaImportsAnalyzer.java
new file mode 100644
index 0000000..23a94e4
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaImportsAnalyzer.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+/**
+ * The {@code JavaImportsAnalyzer} allows checking imports in generated HTL Java classes, in order to optimise dependencies.
+ */
+public interface JavaImportsAnalyzer {
+
+ /**
+ * Analyses the provided {@code importedClass} and decides if this class should be an explicit import or not in the generated HTL
+ * Java class.
+ *
+ * @param importedClass the import to analyse
+ * @return {@code true} if the import should be declared, {@code false} otherwise
+ */
+ default boolean allowImport(String importedClass) {
+ return true;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java
index a619ff6..629f9ac 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java
@@ -117,7 +117,7 @@ public class CodeGenVisitor implements CommandVisitor {
@Override
public void visit(VariableBinding.Start variableBinding) {
source.startBlock();
- TypeInfo typeInfo = TypeInference.inferTypes(variableBinding.getExpression(), analyzer);
+ TypeInfo typeInfo = TypeInference.inferTypes(variableBinding.getExpression(), analyzer, unitBuilder.getImports());
Type type = typeInfo.typeOf(variableBinding.getExpression());
String properName = declare(variableBinding.getVariableName(), type);
source.beginAssignment(properName, type.getNativeClass());
@@ -142,7 +142,7 @@ public class CodeGenVisitor implements CommandVisitor {
@Override
public void visit(VariableBinding.Global globalAssignment) {
- TypeInfo typeInfo = TypeInference.inferTypes(globalAssignment.getExpression(), analyzer);
+ TypeInfo typeInfo = TypeInference.inferTypes(globalAssignment.getExpression(), analyzer, unitBuilder.getImports());
VariableDescriptor descriptor = analyzer.declareGlobal(globalAssignment.getVariableName());
String name = descriptor.getAssignedName();
source.append(name).assign();
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java
index 34be88b..85a0236 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java
@@ -23,10 +23,10 @@ public class JavaClassTemplate {
private String classTemplate;
-
- private static final String MAIN_BODY = "MainBody";
- private static final String CLASS_NAME = "ClassName";
private static final String PACKAGE_NAME = "PackageName";
+ private static final String IMPORTS = "Imports";
+ private static final String CLASS_NAME = "ClassName";
+ private static final String MAIN_BODY = "MainBody";
private static final String TEMPLATE_INIT = "SubTemplateMapInit";
private static final String NAME = "Name";
@@ -52,6 +52,10 @@ public class JavaClassTemplate {
setPart(PACKAGE_NAME, name);
}
+ public void setImports(String imports) {
+ setPart(IMPORTS, imports);
+ }
+
@Override
public String toString() {
return insertPart(TEMPLATE_INIT, classTemplate, templateInitBuilder.toString());
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java
index e73d5e5..187c650 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java
@@ -20,27 +20,38 @@ package org.apache.sling.scripting.sightly.java.compiler.impl;
/**
* Type inferred for an expression
*/
-public enum Type {
- UNKNOWN("Object", false),
- STRING("String", false),
- LONG("long", true),
- DOUBLE("double", true),
- BOOLEAN("boolean", true),
- MAP("java.util.Map", false);
-
- private final String nativeClass;
+public class Type {
+
+ public static final Type UNKNOWN = new Type("Object", false, null);
+ public static final Type STRING = new Type("String", false, null);
+ public static final Type LONG = new Type("long", true, 0);
+ public static final Type DOUBLE = new Type("double", true, 0.0d);
+ public static final Type BOOLEAN = new Type("boolean", true, false);
+ public static final Type MAP = new Type("java.util.Map", false, null);
+
+ private String nativeClass;
private final boolean isPrimitive;
+ private final Object defaultValue;
- Type(String nativeClass, boolean isPrimitive) {
+ private Type(String nativeClass, boolean isPrimitive, Object defaultValue) {
this.nativeClass = nativeClass;
this.isPrimitive = isPrimitive;
+ this.defaultValue = defaultValue;
}
public String getNativeClass() {
return nativeClass;
}
+ public Object getDefaultValue() {
+ return defaultValue;
+ }
+
public boolean isPrimitive() {
return isPrimitive;
}
+
+ public static Type dynamic(String type) {
+ return new Type(type, false, null);
+ }
}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
index 39377b8..6511de3 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
@@ -19,10 +19,10 @@ package org.apache.sling.scripting.sightly.java.compiler.impl;
import java.util.IdentityHashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
-import org.apache.sling.scripting.sightly.java.compiler.impl.operator.BinaryOpGen;
-import org.apache.sling.scripting.sightly.java.compiler.impl.operator.Operators;
-import org.apache.sling.scripting.sightly.java.compiler.impl.operator.UnaryOpGen;
+import org.apache.sling.scripting.sightly.compiler.RuntimeFunction;
import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
import org.apache.sling.scripting.sightly.compiler.expression.NodeVisitor;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral;
@@ -37,6 +37,9 @@ import org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.TernaryOperator;
import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperation;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.BinaryOpGen;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.Operators;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.UnaryOpGen;
/**
* Expression translator which uses type information
@@ -44,17 +47,20 @@ import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperati
public final class TypeInference implements NodeVisitor<Type> {
private final VariableAnalyzer analyzer;
- private final Map<ExpressionNode, Type> inferMap = new IdentityHashMap<ExpressionNode, Type>();
+ private final Map<ExpressionNode, Type> inferMap = new IdentityHashMap<>();
+ private final Set<String> imports;
+ private static final Pattern FQCN_PATTERN = Pattern.compile("([[\\p{L}&&[^\\p{Lu}]]_$][\\p{L}\\p{N}_$]*\\.)+[\\p{Lu}_$][\\p{L}\\p{N}_$]*");
- public static TypeInfo inferTypes(ExpressionNode node, VariableAnalyzer analyzer) {
- TypeInference typeInference = new TypeInference(analyzer);
+ public static TypeInfo inferTypes(ExpressionNode node, VariableAnalyzer analyzer, Set<String> imports) {
+ TypeInference typeInference = new TypeInference(analyzer, imports);
typeInference.infer(node);
return new TypeInfo(typeInference.inferMap);
}
- private TypeInference(VariableAnalyzer analyzer) {
+ private TypeInference(VariableAnalyzer analyzer, Set<String> imports) {
this.analyzer = analyzer;
+ this.imports = imports;
}
@@ -128,6 +134,16 @@ public final class TypeInference implements NodeVisitor<Type> {
@Override
public Type evaluate(RuntimeCall runtimeCall) {
inferAll(runtimeCall.getArguments());
+ if (runtimeCall.getFunctionName().equals(RuntimeFunction.USE)) {
+ ExpressionNode identifier = runtimeCall.getArguments().get(0);
+ if (identifier instanceof StringConstant) {
+ String objectType = ((StringConstant) identifier).getText();
+ if (FQCN_PATTERN.matcher(objectType).matches()) {
+ imports.add(objectType);
+ return Type.dynamic(objectType);
+ }
+ }
+ }
return Type.UNKNOWN;
}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java
index 990bf8c..3a7678c 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java
@@ -19,10 +19,12 @@ package org.apache.sling.scripting.sightly.java.compiler.impl;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.sling.scripting.sightly.java.compiler.CompilationOutput;
+import org.apache.sling.scripting.sightly.java.compiler.JavaImportsAnalyzer;
/**
* Builder for compiled sources
@@ -32,9 +34,12 @@ public class UnitBuilder {
private final JavaSource source = new JavaSource();
private final Set<String> parameters;
private final Map<String, UnitBuilder> subTemplates = new HashMap<String, UnitBuilder>();
+ private Set<String> imports = new HashSet<>();
+ private JavaImportsAnalyzer javaImportsAnalyzer;
- public UnitBuilder() {
- this(Collections.<String>emptySet());
+ public UnitBuilder(JavaImportsAnalyzer javaImportsAnalyzer) {
+ this(Collections.emptySet());
+ this.javaImportsAnalyzer = javaImportsAnalyzer;
}
public UnitBuilder(Set<String> parameters) {
@@ -62,4 +67,12 @@ public class UnitBuilder {
}
return new CompilationOutputImpl(source.toString(), map);
}
+
+ public JavaImportsAnalyzer getJavaImportsAnalyzer() {
+ return javaImportsAnalyzer;
+ }
+
+ public Set<String> getImports() {
+ return imports;
+ }
}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java
index 51193d6..800a5bd 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java
@@ -78,7 +78,7 @@ public class VariableDescriptor {
}
/**
- * Get the inferred type fot this variable
+ * Get the inferred type for this variable
* @return - the class of the variable
*/
public Type getType() {
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
index 4502fd2..45ddcbe 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-@Version("1.1.0")
+@Version("1.2.0")
package org.apache.sling.scripting.sightly.java.compiler;
import org.osgi.annotation.versioning.Version;
diff --git a/src/main/resources/templates/compiled_unit_template.txt b/src/main/resources/templates/compiled_unit_template.txt
index a327d6a..3ce6585 100644
--- a/src/main/resources/templates/compiled_unit_template.txt
+++ b/src/main/resources/templates/compiled_unit_template.txt
@@ -25,6 +25,8 @@ import javax.script.Bindings;
import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
import org.apache.sling.scripting.sightly.render.RenderContext;
+##Imports##
+
public final class ##ClassName## extends RenderUnit {
@Override
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
index 3dd3c8c..924e519 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
@@ -93,6 +93,18 @@ public class JavaClassBackendCompilerTest {
assertEquals(expectedOutput, writer.toString());
}
+ @Test
+ public void generateImportStatements() throws Exception {
+ CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/imports.html");
+ JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
+ SightlyCompiler sightlyCompiler = new SightlyCompiler();
+ sightlyCompiler.compile(compilationUnit, backendCompiler);
+ ClassInfo classInfo = buildClassInfo("imports");
+ String source = backendCompiler.build(classInfo);
+ String expectedJavaOutput = IOUtils.toString(this.getClass().getResourceAsStream("/imports.html.java"), "UTF-8");
+ assertEquals(expectedJavaOutput, source);
+ }
+
private ClassInfo buildClassInfo(final String info) {
return new ClassInfo() {
@Override
diff --git a/src/test/resources/imports.html b/src/test/resources/imports.html
new file mode 100644
index 0000000..82d1905
--- /dev/null
+++ b/src/test/resources/imports.html
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+<div data-sly-use.slingSettings="org.apache.sling.settings.SlingSettingsService"
+ data-sly-use.js="script.js"
+ data-sly-use.pojo="Pojo"
+></div>
diff --git a/src/main/resources/templates/compiled_unit_template.txt b/src/test/resources/imports.html.java
similarity index 77%
copy from src/main/resources/templates/compiled_unit_template.txt
copy to src/test/resources/imports.html.java
index a327d6a..f80f7db 100644
--- a/src/main/resources/templates/compiled_unit_template.txt
+++ b/src/test/resources/imports.html.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-package ##PackageName##;
+package org.apache.sling.scripting.sightly.compiler.java;
import java.io.PrintWriter;
import java.util.Collection;
@@ -25,7 +25,10 @@ import javax.script.Bindings;
import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
import org.apache.sling.scripting.sightly.render.RenderContext;
-public final class ##ClassName## extends RenderUnit {
+import org.apache.sling.settings.SlingSettingsService;
+
+
+public final class Test_imports extends RenderUnit {
@Override
protected final void render(PrintWriter out,
@@ -34,7 +37,15 @@ public final class ##ClassName## extends RenderUnit {
RenderContext renderContext) {
// Main Template Body -----------------------------------------------------------------------------
-##MainBody##
+Object _global_slingsettings = null;
+Object _global_js = null;
+Object _global_pojo = null;
+out.write("\n");
+_global_slingsettings = renderContext.call("use", "org.apache.sling.settings.SlingSettingsService", obj());
+_global_js = renderContext.call("use", "script.js", obj());
+_global_pojo = renderContext.call("use", "Pojo", obj());
+out.write("<div></div>\n");
+
// End Of Main Template Body ----------------------------------------------------------------------
}
@@ -44,7 +55,7 @@ public final class ##ClassName## extends RenderUnit {
{
//Sub-Templates Initialization --------------------------------------------------------------------
-##SubTemplateMapInit##
+
//End of Sub-Templates Initialization -------------------------------------------------------------
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 06/50:
trivial: corrected JavaDoc
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit dc7c4d44b971f992b84a0a83f0cadc0c8d744b7a
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 11:50:53 2016 +0000
trivial: corrected JavaDoc
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759238 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 24 ----------------------
.../sightly/java/compiler/RenderUnit.java | 1 +
.../apache/sling/scripting/sightly/pojo/Use.java | 10 ++++-----
3 files changed, 6 insertions(+), 29 deletions(-)
diff --git a/pom.xml b/pom.xml
index e2a0ba2..54772a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,14 +82,6 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <stylesheet>maven</stylesheet>
- <excludePackageNames>*.impl:*.internal:${site.javadoc.exclude}</excludePackageNames>
- </configuration>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
@@ -111,22 +103,6 @@
</build>
<!-- ======================================================================= -->
- <!-- R E P O R T I N G -->
- <!-- ======================================================================= -->
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <stylesheet>maven</stylesheet>
- <excludePackageNames>*.impl:*.internal:${site.javadoc.exclude}</excludePackageNames>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
-
- <!-- ======================================================================= -->
<!-- D E P E N D E N C I E S -->
<!-- ======================================================================= -->
<dependencies>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
index d9f831c..76c0f3a 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
@@ -39,6 +39,7 @@ public abstract class RenderUnit implements Record<RenderUnit> {
/**
* Render the main script template
*
+ * @param out the {@link PrintWriter} to which the commands are written
* @param renderContext the rendering context
* @param arguments the arguments for this unit
*/
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
index 6765569..722b79a 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
@@ -33,12 +33,12 @@ public interface Use {
/**
* <p>
- * Called to initialize the Java object with the current Java Scripting API bindings.
+ * Called to initialize the Java object with the current Java Scripting API bindings.
+ * </p>
+ * <p>
+ * This method is called only if the object has been instantiated by HTL as part of processing the {@code data-sly-use}
+ * attribute. The Java Scripting API bindings provide all the global variables known to a script being executed.
* </p>
- * <p/>
- * This method is called only if the object has been instantiated by HTL as part of processing the {@code data-sly-use}
- * attribute. The Java Scripting API bindings provide all the global variables known to a script being executed.
- * <p/>
*
* @param bindings The Java Scripting API bindings.
*/
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 26/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.6
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 7d96e58619e0898122965cc90e52a9afdb8281e1
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Dec 15 14:07:38 2016 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.6
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774452 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index f0f4af3..175b966 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.5-SNAPSHOT</version>
+ <version>1.0.6</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 24/50:
SLING-6399 - Implement support for date and number formatting for HTL
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 9dd2698de3d62cdcdd4444afd465eaccbdd2cbc9
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Dec 15 14:01:44 2016 +0000
SLING-6399 - Implement support for date and number formatting for HTL
* bumped capabilities to 1.3, corresponding to version 1.3 of the HTL Template Language Specification
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774447 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 19168bc..a492b2f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,7 +74,8 @@
<Provide-Capability>
io.sightly.compiler.java; version:Version=1.0,
io.sightly.compiler.java; version:Version=1.1,
- io.sightly.compiler.java; version:Version=1.2
+ io.sightly.compiler.java; version:Version=1.2,
+ io.sightly.compiler.java; version:Version=1.3
</Provide-Capability>
</instructions>
</configuration>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 23/50:
SLING-6399 - Implement support for date and number formatting for HTL
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit d9fbfa11dce2a9cce0f48640e4f7da374e844753
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Dec 14 22:13:32 2016 +0000
SLING-6399 - Implement support for date and number formatting for HTL
* implemented support for the date and number formatting features from version 1.3
of the HTL Language Specification
* applied slightly modified patch submitted by Vlad Băilescu at https://github.com/apache/sling/pull/191
(Closes #191)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774351 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/render/AbstractRuntimeObjectModel.java | 23 ++++++++++++++++++++--
.../sightly/render/RuntimeObjectModel.java | 7 +++++++
.../scripting/sightly/render/package-info.java | 2 +-
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index a55b21f..e4f84b0 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -21,8 +21,10 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -48,7 +50,6 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
*/
public static final Set<Class<?>> PRIMITIVE_CLASSES = Collections.unmodifiableSet(new HashSet<Class<?>>() {{
add(Boolean.class);
- add(Boolean.class);
add(Character.class);
add(Byte.class);
add(Short.class);
@@ -67,6 +68,16 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
}
@Override
+ public boolean isDate(Object target) {
+ return (target instanceof Date || target instanceof Calendar);
+ }
+
+ @Override
+ public boolean isNumber(Object target) {
+ return (target instanceof Number);
+ }
+
+ @Override
public boolean isCollection(Object target) {
return (target instanceof Collection) || (target instanceof Object[]) || (target instanceof Iterable) ||
(target instanceof Iterator);
@@ -96,6 +107,15 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
return 0;
}
+ public Date toDate(Object object) {
+ if (object instanceof Date) {
+ return (Date)object;
+ } else if (object instanceof Calendar) {
+ return ((Calendar)object).getTime();
+ }
+ return new Date(0);
+ }
+
@Override
public String toString(Object target) {
return objectToString(target);
@@ -368,4 +388,3 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
}
}
-
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
index 7d3076f..6d8f6e0 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
@@ -17,6 +17,7 @@
package org.apache.sling.scripting.sightly.render;
import java.util.Collection;
+import java.util.Date;
import java.util.Map;
import org.osgi.annotation.versioning.ProviderType;
@@ -44,6 +45,10 @@ public interface RuntimeObjectModel {
*/
boolean isCollection(Object target);
+ boolean isNumber(Object target);
+
+ boolean isDate(Object target);
+
/**
* Resolve a property of a target object and return its value. The property can
* be either an index or a name
@@ -70,6 +75,8 @@ public interface RuntimeObjectModel {
*/
Number toNumber(Object object);
+ Date toDate(Object object);
+
/**
* Convert the given object to a string.
*
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
index 1e71397..a996756 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-@Version("2.0.0")
+@Version("2.1.0")
package org.apache.sling.scripting.sightly.render;
import org.osgi.annotation.versioning.Version;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 36/50:
SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler
bundles
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 8a82bef842d66152dc06dbec2c2febc9fc68bf08
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Mar 15 16:57:00 2017 +0000
SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler bundles
* moved SightlyException into the java-compiler, but made it extend directly RuntimeException
* moved ResourceResolution into the org.apache.sling.scripting.sightly.engine package
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1787079 13f79535-47bb-0310-9956-ffa450edef68
---
.../{package-info.java => SightlyException.java} | 23 +++++++++++++++++++---
.../sling/scripting/sightly/package-info.java | 2 +-
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/SightlyException.java
similarity index 71%
copy from src/main/java/org/apache/sling/scripting/sightly/package-info.java
copy to src/main/java/org/apache/sling/scripting/sightly/SightlyException.java
index 96dca47..16111ee 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/SightlyException.java
@@ -14,8 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-
-@Version("1.0.1")
package org.apache.sling.scripting.sightly;
-import org.osgi.annotation.versioning.Version;
+/**
+ * Exceptions caused by the HTL engine.
+ */
+public class SightlyException extends RuntimeException {
+
+ public SightlyException() {
+ }
+
+ public SightlyException(String message) {
+ super(message);
+ }
+
+ public SightlyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SightlyException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
index 96dca47..3a9028f 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
@@ -15,7 +15,7 @@
* limitations under the License.
******************************************************************************/
-@Version("1.0.1")
+@Version("1.1.0")
package org.apache.sling.scripting.sightly;
import org.osgi.annotation.versioning.Version;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 38/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.10
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit fc06b384a92cd03cbea3fe5f67c2d6f06606c089
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri May 5 12:32:37 2017 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.10
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1794033 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4b45310..b69aa93 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.9-SNAPSHOT</version>
+ <version>1.0.10</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.10</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 31/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.8
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 81e0e347cbb97977003440ff4ce753755c32143e
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Jan 13 11:17:37 2017 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.8
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1778543 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0a98b8e..5a6f9ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.7-SNAPSHOT</version>
+ <version>1.0.8</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.8</url>
</scm>
<properties>
@@ -156,7 +156,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.5-SNAPSHOT</version>
+ <version>1.0.4</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 40/50:
releng: updated Provide-Capability bundle headers for HTL modules
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 865fe2e3fc1fb510a5adb5bf9c142507c29967ec
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Aug 1 10:14:47 2017 +0000
releng: updated Provide-Capability bundle headers for HTL modules
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1803634 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0176ee6..3ec8e6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,7 +75,8 @@
io.sightly.compiler.java; version:Version=1.0,
io.sightly.compiler.java; version:Version=1.1,
io.sightly.compiler.java; version:Version=1.2,
- io.sightly.compiler.java; version:Version=1.3
+ io.sightly.compiler.java; version:Version=1.3,
+ io.sightly.compiler.java; version:Version=1.3.1
</Provide-Capability>
</instructions>
</configuration>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 20/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit abde4bd3e11b8b0c406267f17e3255a5a31fb8d3
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Oct 14 08:06:24 2016 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764830 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 18acf48..94f6571 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.4</version>
+ <version>1.0.5-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.4</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 45/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit e497ab36e71bf47b499e6d56b63190f95614d2c3
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Aug 29 11:09:40 2017 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1806563 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5f1f6d7..d1d4dcf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.12</version>
+ <version>1.0.13-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.12</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.12</version>
+ <version>1.0.13-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 05/50:
SLING-6033 - Update Sightly bundles to parent pom 28
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 495fb6d09cc9296c0e7336ea3b9e73c3fc9eb609
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 2 16:03:35 2016 +0000
SLING-6033 - Update Sightly bundles to parent pom 28
* switched from BND to OSGi annotations
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1758984 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 +---
src/main/java/org/apache/sling/scripting/sightly/Record.java | 2 +-
.../apache/sling/scripting/sightly/extension/RuntimeExtension.java | 2 +-
.../org/apache/sling/scripting/sightly/extension/package-info.java | 4 ++--
.../org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java | 2 +-
.../sling/scripting/sightly/java/compiler/CompilationOutput.java | 2 +-
.../apache/sling/scripting/sightly/java/compiler/package-info.java | 2 +-
src/main/java/org/apache/sling/scripting/sightly/package-info.java | 4 ++--
src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java | 2 +-
.../java/org/apache/sling/scripting/sightly/pojo/package-info.java | 4 ++--
.../java/org/apache/sling/scripting/sightly/render/RenderContext.java | 2 +-
.../org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java | 2 +-
.../java/org/apache/sling/scripting/sightly/render/package-info.java | 2 +-
src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java | 2 +-
.../java/org/apache/sling/scripting/sightly/use/package-info.java | 4 ++--
15 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3d58d8c..e2a0ba2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
+ <version>28</version>
<relativePath />
</parent>
@@ -163,7 +163,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -181,7 +180,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
- <version>1.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/Record.java b/src/main/java/org/apache/sling/scripting/sightly/Record.java
index ead00db..5c8be4a 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/Record.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/Record.java
@@ -21,7 +21,7 @@ package org.apache.sling.scripting.sightly;
import java.util.Set;
-import aQute.bnd.annotation.ConsumerType;
+import org.osgi.annotation.versioning.ConsumerType;
/**
* A {@code Record} is a key-value immutable object understood by the HTL runtime, used for abstracting complex objects like Sightly
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
index 186495b..e7b8afd 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
@@ -20,7 +20,7 @@ package org.apache.sling.scripting.sightly.extension;
import org.apache.sling.scripting.sightly.render.RenderContext;
-import aQute.bnd.annotation.ConsumerType;
+import org.osgi.annotation.versioning.ConsumerType;
/**
* A {@code RuntimeExtension} represents a HTL runtime construct that provides some processing capabilities for the various
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
index c1a6d5f..0bec18c 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-@Version("1.0.0")
+@Version("1.0.1")
package org.apache.sling.scripting.sightly.extension;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java
index 8a16d4e..3bd16b7 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java
@@ -17,7 +17,7 @@
package org.apache.sling.scripting.sightly.java.compiler;
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
/**
* This interface provides information about classes that will be generated by the {@link JavaClassBackendCompiler}.
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java
index b5b0b12..f177eb2 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java
@@ -18,7 +18,7 @@ package org.apache.sling.scripting.sightly.java.compiler;
import java.util.Map;
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
/**
* The {@code CompilationOutput} encapsulates the result of a compile operation as processed by the {@link JavaClassBackendCompiler}.
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
index dc548d9..8179757 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
@@ -17,4 +17,4 @@
@Version("1.0.0")
package org.apache.sling.scripting.sightly.java.compiler;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
index dacd4c5..96dca47 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
@@ -15,7 +15,7 @@
* limitations under the License.
******************************************************************************/
-@Version("1.0.0")
+@Version("1.0.1")
package org.apache.sling.scripting.sightly;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
index d4ec318..6765569 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
@@ -20,7 +20,7 @@ package org.apache.sling.scripting.sightly.pojo;
import javax.script.Bindings;
-import aQute.bnd.annotation.ConsumerType;
+import org.osgi.annotation.versioning.ConsumerType;
/**
* The <code>Use</code> interface can be implemented by Java objects which are instantiated as part of processing {@code data-sly-use}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
index f795d12..746ab8f 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-@Version("1.0.0")
+@Version("1.0.1")
package org.apache.sling.scripting.sightly.pojo;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
index d0a4390..c48895c 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
@@ -20,7 +20,7 @@ import javax.script.Bindings;
import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
/**
* The {@code RenderContext} defines the context for executing HTL scripts.
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
index 2945402..7d3076f 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
@@ -19,7 +19,7 @@ package org.apache.sling.scripting.sightly.render;
import java.util.Collection;
import java.util.Map;
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
/**
* The {@code RuntimeObjectModel} provides various utility object inspection & conversion methods that can be applied to runtime
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
index 85ac73d..1e71397 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
@@ -17,4 +17,4 @@
@Version("2.0.0")
package org.apache.sling.scripting.sightly.render;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
index 9c7b2b6..14a78ba 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
@@ -23,7 +23,7 @@ import javax.script.Bindings;
import org.apache.sling.scripting.sightly.render.RenderContext;
-import aQute.bnd.annotation.ConsumerType;
+import org.osgi.annotation.versioning.ConsumerType;
/**
* <p>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
index 2564bea..0dfe431 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-@Version("1.0.0")
+@Version("1.0.1")
package org.apache.sling.scripting.sightly.use;
-import aQute.bnd.annotation.Version;
+import org.osgi.annotation.versioning.Version;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 29/50:
SLING-6428 - DateFormat is printed when date-value is empty
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 1dd9a28fce49ff32f6f6ac6c11bd94951bab259d
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Jan 10 09:10:59 2017 +0000
SLING-6428 - DateFormat is printed when date-value is empty
* applied patch from Vlad Băilescu
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1778098 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/render/AbstractRuntimeObjectModel.java | 4 ++--
.../scripting/sightly/render/RuntimeObjectModel.java | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index e4f84b0..357d680 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -104,7 +104,7 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
if (object instanceof Number) {
return (Number) object;
}
- return 0;
+ return null;
}
public Date toDate(Object object) {
@@ -113,7 +113,7 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
} else if (object instanceof Calendar) {
return ((Calendar)object).getTime();
}
- return new Date(0);
+ return null;
}
@Override
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
index 6d8f6e0..f386634 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
@@ -45,8 +45,20 @@ public interface RuntimeObjectModel {
*/
boolean isCollection(Object target);
+ /**
+ * Checks if the provided object represents a number or not.
+ *
+ * @param target the target object
+ * @return {@code true} if the {@code target} is a number, {@code false} otherwise
+ */
boolean isNumber(Object target);
+ /**
+ * Checks if the provided object represents a date or calendar.
+ *
+ * @param target the target object
+ * @return {@code true} if the {@code target} is a date or calendar, {@code false} otherwise
+ */
boolean isDate(Object target);
/**
@@ -75,6 +87,12 @@ public interface RuntimeObjectModel {
*/
Number toNumber(Object object);
+ /**
+ * Convert the given object to a {@link Date} object
+ *
+ * @param object the target object
+ * @return the date represented by the {@code object}
+ */
Date toDate(Object object);
/**
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 10/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit efbad8b54e3443b1a6fdf51830fac0101d7f14f5
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 15:18:16 2016 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759291 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8103054..c763894 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 02/50:
trivial: added scm info + updated readme for sightly modules
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 25ffd026a4f1b925ab65ed9a973721377a8b9f61
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Jun 16 16:20:24 2016 +0000
trivial: added scm info + updated readme for sightly modules
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1748757 13f79535-47bb-0310-9956-ffa450edef68
---
README.md | 4 ++++
pom.xml | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5445259
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+Apache Sling Scripting Sightly Java Compiler
+====
+The Apache Sling Scripting Sightly Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
+[`org.apache.sling.scripting.sightly.compiler`](../compiler) module into Java source code.
diff --git a/pom.xml b/pom.xml
index 9ec9808..005effe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,17 @@
<name>Apache Sling Scripting Sightly Java Compiler</name>
+ <description>
+ The Apache Sling Scripting Sightly Java Compiler provides support for transpiling the Abstract Syntax Tree produced by the
+ org.apache.sling.scripting.sightly.compiler module into Java source code.
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ </scm>
+
<properties>
<sling.java.version>7</sling.java.version>
</properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 12/50:
SLING-6094 - HTL can generate invalid Java code by using user-supplied
input
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit c988fec676719adf40783d57a4816295b3c6d1ee
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Oct 6 16:44:00 2016 +0000
SLING-6094 - HTL can generate invalid Java code by using user-supplied input
* made sure that generated variables, even if they contain user-input, are correctly
and uniformly escaped
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763629 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/java/compiler/JavaEscapeUtils.java | 159 +++++++++++++++++++++
.../java/compiler/impl/VariableAnalyzer.java | 8 +-
.../java/compiler/impl/utils/JavaEscapeUtils.java | 95 ------------
.../sightly/java/compiler/package-info.java | 2 +-
4 files changed, 164 insertions(+), 100 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
new file mode 100644
index 0000000..3bc299c
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * The {@code JavaEscapeUtils} provides useful methods for escaping or transforming invalid Java tokens to valid ones that could be used in
+ * generated Java source code.
+ */
+public class JavaEscapeUtils {
+
+ private static final Set<String> javaKeywords = new HashSet<String>() {{
+ add("abstract");
+ add("assert");
+ add("boolean");
+ add("break");
+ add("byte");
+ add("case");
+ add("catch");
+ add("char");
+ add("class");
+ add("const");
+ add("continue");
+ add("default");
+ add("do");
+ add("double");
+ add("else");
+ add("enum");
+ add("extends");
+ add("final");
+ add("finally");
+ add("float");
+ add("for");
+ add("goto");
+ add("if");
+ add("implements");
+ add("import");
+ add("instanceof");
+ add("int");
+ add("interface");
+ add("long");
+ add("native");
+ add("new");
+ add("package");
+ add("private");
+ add("protected");
+ add("public");
+ add("return");
+ add("short");
+ add("static");
+ add("strictfp");
+ add("super");
+ add("switch");
+ add("synchronized");
+ add("this");
+ add("throw");
+ add("throws");
+ add("transient");
+ add("try");
+ add("void");
+ add("volatile");
+ add("while");
+ }};
+
+ /**
+ * Converts the given identifier to a legal Java identifier
+ *
+ * @param identifier the identifier to convert
+ * @return legal Java identifier corresponding to the given identifier
+ */
+ public static String makeJavaIdentifier(String identifier) {
+ StringBuilder modifiedIdentifier = new StringBuilder(identifier.length());
+ if (!Character.isJavaIdentifierStart(identifier.charAt(0))) {
+ modifiedIdentifier.append('_');
+ }
+ for (int i = 0; i < identifier.length(); i++) {
+ char ch = identifier.charAt(i);
+ if (Character.isJavaIdentifierPart(ch) && ch != '_') {
+ modifiedIdentifier.append(ch);
+ } else if (ch == '.') {
+ modifiedIdentifier.append('_');
+ } else {
+ modifiedIdentifier.append(mangleChar(ch));
+ }
+ }
+ if (isJavaKeyword(modifiedIdentifier.toString())) {
+ modifiedIdentifier.append('_');
+ }
+ return modifiedIdentifier.toString();
+ }
+
+ /**
+ * Mangle the specified character to create a legal Java class name.
+ *
+ * @param ch the character to mangle
+ * @return the mangled
+ */
+ public static String mangleChar(char ch) {
+ return String.format("__%04x__", (int) ch);
+ }
+
+ /**
+ * Provided a mangled string (obtained by calling {@link #mangleChar(char)}) it will will return the character that was mangled.
+ *
+ * @param mangled the mangled string
+ * @return the original character
+ */
+ public static char unmangle(String mangled) {
+ String toProcess = mangled.replaceAll("__", "");
+ return (char) Integer.parseInt(toProcess, 16);
+ }
+
+ /**
+ * Converts the given scriptName to a Java package or fully-qualified class name
+ *
+ * @param scriptName the scriptName to convert
+ * @return Java package corresponding to the given scriptName
+ */
+ public static String makeJavaPackage(String scriptName) {
+ String classNameComponents[] = StringUtils.split(scriptName, '/');
+ StringBuilder legalClassNames = new StringBuilder();
+ for (int i = 0; i < classNameComponents.length; i++) {
+ legalClassNames.append(makeJavaIdentifier(classNameComponents[i]));
+ if (i < classNameComponents.length - 1) {
+ legalClassNames.append('.');
+ }
+ }
+ return legalClassNames.toString();
+ }
+
+ /**
+ * Test whether the argument is a Java keyword.
+ *
+ * @param key the String to test
+ * @return {@code true} if the String is a Java keyword, {@code false} otherwise
+ */
+ public static boolean isJavaKeyword(String key) {
+ return javaKeywords.contains(key);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java
index 80aa5c7..b0fb3e3 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java
@@ -23,7 +23,7 @@ import java.util.HashMap;
import java.util.List;
import org.apache.sling.scripting.sightly.java.compiler.SightlyJavaCompilerException;
-import org.apache.sling.scripting.sightly.java.compiler.impl.utils.JavaEscapeUtils;
+import org.apache.sling.scripting.sightly.java.compiler.JavaEscapeUtils;
import org.apache.sling.scripting.sightly.compiler.util.VariableTracker;
/**
@@ -140,16 +140,16 @@ public class VariableAnalyzer {
}
private String findDynamicName(String original) {
- return DYNAMIC_PREFIX + JavaEscapeUtils.getEscapedToken(original);
+ return DYNAMIC_PREFIX + JavaEscapeUtils.makeJavaIdentifier(original);
}
private String findGlobalName(String original) {
- return GLOBAL_PREFIX + JavaEscapeUtils.getEscapedToken(original);
+ return GLOBAL_PREFIX + JavaEscapeUtils.makeJavaIdentifier(original);
}
private String findSafeName(String original) {
int occurrenceCount = tracker.getOccurrenceCount(original);
- String syntaxSafe = JavaEscapeUtils.getEscapedToken(original);
+ String syntaxSafe = JavaEscapeUtils.makeJavaIdentifier(original);
if (occurrenceCount == 0) {
return syntaxSafe; //no other declarations in scope. Use this very name
} else {
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java
deleted file mode 100644
index 91c10af..0000000
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * 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.java.compiler.impl.utils;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * The {@code JavaEscapeUtils} provides useful methods for escaping or transforming invalid Java tokens to valid ones that could be used in
- * generated Java source code.
- */
-public class JavaEscapeUtils {
-
- private static final Set<String> reservedKeywords = new HashSet<String>() {{
- add("abstract");
- add("assert");
- add("boolean");
- add("break");
- add("byte");
- add("case");
- add("catch");
- add("char");
- add("class");
- add("const");
- add("continue");
- add("default");
- add("do");
- add("double");
- add("else");
- add("enum");
- add("extends");
- add("final");
- add("finally");
- add("float");
- add("for");
- add("goto");
- add("if");
- add("implements");
- add("import");
- add("instanceof");
- add("int");
- add("interface");
- add("long");
- add("native");
- add("new");
- add("package");
- add("private");
- add("protected");
- add("public");
- add("return");
- add("short");
- add("static");
- add("strictfp");
- add("super");
- add("switch");
- add("synchronized");
- add("this");
- add("throw");
- add("throws");
- add("transient");
- add("try");
- add("void");
- add("volatile");
- add("while");
- }};
-
- /**
- * Escapes and / or transforms an invalid token (in case the token represents a reserved Java keyword) to provide a valid token.
- *
- * @param token the token to be transformed
- * @return a valid Java token
- */
- public static String getEscapedToken(String token) {
- String result = token;
- if (reservedKeywords.contains(result)) {
- result = "_" + result;
- }
- return result.replaceAll("-", "_");
- }
-
-}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
index 8179757..4502fd2 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-@Version("1.0.0")
+@Version("1.1.0")
package org.apache.sling.scripting.sightly.java.compiler;
import org.osgi.annotation.versioning.Version;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 35/50:
SLING-6633 - [HTL] NumberFormat should support String-properties with
number value
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit f6d17f4f36a9ab440cc80409f4f004ad3f5482b4
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Mar 13 13:45:20 2017 +0000
SLING-6633 - [HTL] NumberFormat should support String-properties with number value
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1786688 13f79535-47bb-0310-9956-ffa450edef68
---
.../scripting/sightly/render/AbstractRuntimeObjectModel.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index aae53e4..514ca48 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -79,6 +79,9 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
if (target == null) {
return false;
}
+ if (target instanceof Number) {
+ return true;
+ }
String value = toString(target);
return NumberUtils.isNumber(value);
}
@@ -107,6 +110,12 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
@Override
public Number toNumber(Object object) {
+ if (object == null) {
+ return null;
+ }
+ if (object instanceof Number) {
+ return (Number) object;
+ }
String stringValue = toString(object);
try {
return NumberUtils.createNumber(stringValue);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 37/50:
SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler
bundles
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 7e5aa10210020494c5f514c25c2d8347f467b939
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Mar 31 15:10:37 2017 +0000
SLING-6639 - Avoid split packages in the HTL Engine and HTL Java Compiler bundles
* increased exported package version to prevent incorrect OSGi wiring
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1789701 13f79535-47bb-0310-9956-ffa450edef68
---
src/main/java/org/apache/sling/scripting/sightly/package-info.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
index 3a9028f..f2af1f3 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/package-info.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
@@ -15,7 +15,7 @@
* limitations under the License.
******************************************************************************/
-@Version("1.1.0")
+@Version("2.0.0")
package org.apache.sling.scripting.sightly;
import org.osgi.annotation.versioning.Version;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 15/50:
SLING-6125 - Switch HTL to OSGi R6 annotations
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit bd046d07d7ee5cbd4ee0af2edf53d3103245929c
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Oct 10 15:39:09 2016 +0000
SLING-6125 - Switch HTL to OSGi R6 annotations
* removed maven-scr-plugin and configured maven-bundle-plugin to generate SCR metadata
* replaced Felix SCR annotations with OSGi Component + Metatype annotations
* removed unused dependencies
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764122 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 45 +++++++++++++--------------------------------
1 file changed, 13 insertions(+), 32 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5d3a09e..616e9ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,25 +58,23 @@
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>javax.jcr</groupId>
- <artifactId>jcr</artifactId>
- <version>2.0</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>scr-metadata</id>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
<configuration>
+ <exportScr>true</exportScr>
<instructions>
<Provide-Capability>
- io.sightly.java; version:Version=1.0,
- io.sightly.java; version:Version=1.1,
- io.sightly.java; version:Version=1.2
+ io.sightly.compiler.java; version:Version=1.0,
+ io.sightly.compiler.java; version:Version=1.1,
+ io.sightly.compiler.java; version:Version=1.2
</Provide-Capability>
</instructions>
</configuration>
@@ -120,7 +118,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.1-SNAPSHOT</version>
+ <version>1.0.0</version>
<scope>provided</scope>
</dependency>
@@ -151,23 +149,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.9.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
- <version>1.5.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 33/50: use
Sling Parent 30
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 370429bdb7073ce21618679afc3700e8e1e27608
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Mar 6 10:31:22 2017 +0000
use Sling Parent 30
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1785622 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 721e87f..4b45310 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>28</version>
+ <version>30</version>
<relativePath />
</parent>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 47/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 8f213646ed654a46ef9b434fcb2922e206c2c489
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 15 07:25:36 2017 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1808424 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3bc2432..3b5734c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.14</version>
+ <version>1.0.15-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 21/50:
SLING-6186 - Add support for checking code coverage with jacoco
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit ee08d997b1879fb1437f79db87748b707d5cdd15
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Oct 25 15:19:19 2016 +0000
SLING-6186 - Add support for checking code coverage with jacoco
* configured jacoco for all HTL modules that provide unit tests
* IT code coverage can be obtained from the testing module
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1766545 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/pom.xml b/pom.xml
index 94f6571..a522534 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,6 +110,43 @@
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>coverage-report</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.7.7.201606060606</version>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>org/apache/sling/scripting/sightly/**/*</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
<!-- ======================================================================= -->
<!-- D E P E N D E N C I E S -->
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 34/50:
SLING-6633 - [HTL] NumberFormat should support String-properties with
number value
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit c7b2445d00260e1a803985e28fc698b7f8fa9e46
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Mar 13 08:21:05 2017 +0000
SLING-6633 - [HTL] NumberFormat should support String-properties with number value
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1786639 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/render/AbstractRuntimeObjectModel.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index 4b512c3..aae53e4 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -35,6 +35,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
import org.apache.sling.scripting.sightly.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,7 +76,11 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
@Override
public boolean isNumber(Object target) {
- return (target instanceof Number);
+ if (target == null) {
+ return false;
+ }
+ String value = toString(target);
+ return NumberUtils.isNumber(value);
}
@Override
@@ -102,10 +107,12 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
@Override
public Number toNumber(Object object) {
- if (object instanceof Number) {
- return (Number) object;
+ String stringValue = toString(object);
+ try {
+ return NumberUtils.createNumber(stringValue);
+ } catch (NumberFormatException e) {
+ return null;
}
- return null;
}
public Date toDate(Object object) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 27/50:
[maven-release-plugin] prepare for next development iteration
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 1c0979301e318c51f41d14a53efc2ab6116b27d9
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Dec 15 14:07:53 2016 +0000
[maven-release-plugin] prepare for next development iteration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774454 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 175b966..c5a2e0a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.6</version>
+ <version>1.0.7-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.6</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 01/50:
SLING-5787 - Modularise the Sightly script engine
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit ccb2c053d0fad9e2fdfdce4b0c47323ff8315622
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Jun 16 16:07:57 2016 +0000
SLING-5787 - Modularise the Sightly script engine
* implemented front-end + back-end compilers
* added new dependency to the JavaScript + Sling Models use providers in order
to use version 2.0.0 of the org.apache.sling.scripting.sightly.render API package
* adapted tests
(closes #147)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1748750 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 184 +++++++
.../org/apache/sling/scripting/sightly/Record.java | 51 ++
.../sightly/extension/RuntimeExtension.java | 45 ++
.../scripting/sightly/extension/package-info.java | 22 +
.../scripting/sightly/java/compiler/ClassInfo.java | 48 ++
.../sightly/java/compiler/CompilationOutput.java | 42 ++
.../compiler/GlobalShadowCheckBackendCompiler.java | 49 ++
.../java/compiler/JavaClassBackendCompiler.java | 99 ++++
.../sightly/java/compiler/RenderUnit.java | 153 ++++++
.../compiler/SightlyJavaCompilerException.java | 40 ++
.../sightly/java/compiler/impl/CodeGenVisitor.java | 250 ++++++++++
.../java/compiler/impl/CommandVisitorHandler.java | 47 ++
.../java/compiler/impl/CompilationOutputImpl.java | 44 ++
.../java/compiler/impl/ExpressionTranslator.java | 182 +++++++
.../sightly/java/compiler/impl/GenHelper.java | 108 ++++
.../java/compiler/impl/GlobalShadowChecker.java | 74 +++
.../java/compiler/impl/JavaClassTemplate.java | 68 +++
.../sightly/java/compiler/impl/JavaSource.java | 266 ++++++++++
.../java/compiler/impl/SourceGenConstants.java | 59 +++
.../scripting/sightly/java/compiler/impl/Type.java | 46 ++
.../sightly/java/compiler/impl/TypeInference.java | 156 ++++++
.../sightly/java/compiler/impl/TypeInfo.java | 47 ++
.../sightly/java/compiler/impl/UnitBuilder.java | 65 +++
.../java/compiler/impl/VariableAnalyzer.java | 166 +++++++
.../java/compiler/impl/VariableDescriptor.java | 105 ++++
.../sightly/java/compiler/impl/VariableScope.java | 25 +
.../java/compiler/impl/operator/BinaryOpGen.java | 33 ++
.../compiler/impl/operator/ComparisonOpGen.java | 87 ++++
.../compiler/impl/operator/ConcatenateOpGen.java | 46 ++
.../compiler/impl/operator/EquivalenceOpGen.java | 88 ++++
.../compiler/impl/operator/IsWhiteSpaceGen.java | 49 ++
.../java/compiler/impl/operator/LengthOpGen.java | 46 ++
.../java/compiler/impl/operator/LogicalOpGen.java | 78 +++
.../java/compiler/impl/operator/LongOpGen.java | 35 ++
.../java/compiler/impl/operator/NotOpGen.java | 45 ++
.../java/compiler/impl/operator/NumericOpGen.java | 55 +++
.../java/compiler/impl/operator/OpHelper.java | 37 ++
.../java/compiler/impl/operator/Operators.java | 86 ++++
.../java/compiler/impl/operator/StrictEqGenOp.java | 54 ++
.../java/compiler/impl/operator/TypedNode.java | 42 ++
.../java/compiler/impl/operator/UnaryOpGen.java | 33 ++
.../java/compiler/impl/utils/JavaEscapeUtils.java | 95 ++++
.../sightly/java/compiler/package-info.java | 20 +
.../sling/scripting/sightly/package-info.java | 21 +
.../apache/sling/scripting/sightly/pojo/Use.java | 47 ++
.../sling/scripting/sightly/pojo/package-info.java | 22 +
.../sightly/render/AbstractRuntimeObjectModel.java | 369 ++++++++++++++
.../scripting/sightly/render/RenderContext.java | 53 ++
.../sightly/render/RuntimeObjectModel.java | 96 ++++
.../scripting/sightly/render/package-info.java | 20 +
.../scripting/sightly/use/ProviderOutcome.java | 133 +++++
.../sling/scripting/sightly/use/UseProvider.java | 46 ++
.../sling/scripting/sightly/use/package-info.java | 22 +
.../resources/templates/compiled_unit_template.txt | 53 ++
src/main/resources/templates/subtemplate.txt | 43 ++
.../java/JavaClassBackendCompilerTest.java | 93 ++++
.../java/utils/CharSequenceJavaCompiler.java | 550 +++++++++++++++++++++
.../utils/CharSequenceJavaCompilerException.java | 72 +++
.../sightly/compiler/java/utils/TestUtils.java | 43 ++
src/test/resources/test-output.html | 23 +
src/test/resources/test.html | 19 +
61 files changed, 5095 insertions(+)
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..9ec9808
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <!-- ======================================================================= -->
+ <!-- P A R E N T P R O J E C T -->
+ <!-- ======================================================================= -->
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>26</version>
+ <relativePath />
+ </parent>
+
+ <!-- ======================================================================= -->
+ <!-- P R O J E C T -->
+ <!-- ======================================================================= -->
+ <artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Scripting Sightly Java Compiler</name>
+
+ <properties>
+ <sling.java.version>7</sling.java.version>
+ </properties>
+
+ <!-- ======================================================================= -->
+ <!-- B U I L D -->
+ <!-- ======================================================================= -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Provide-Capability>
+ io.sightly.java; version:Version=1.0,
+ io.sightly.java; version:Version=1.1,
+ io.sightly.java; version:Version=1.2
+ </Provide-Capability>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <stylesheet>maven</stylesheet>
+ <excludePackageNames>*.impl:*.internal:${site.javadoc.exclude}</excludePackageNames>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>3.0.3</version>
+ <configuration>
+ <effort>Max</effort>
+ <xmlOutput>true</xmlOutput>
+ </configuration>
+ <executions>
+ <execution>
+ <id>find-bugs</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- ======================================================================= -->
+ <!-- R E P O R T I N G -->
+ <!-- ======================================================================= -->
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <groups>
+ <group>
+ <title>Apache Sling Scriptin Sightly Java Compiler</title>
+ <packages>org.apache.sling.scripting.sightly.compiler.java</packages>
+ </group>
+ </groups>
+ <doctitle>${project.name} Documentation (Version: ${project.version})</doctitle>
+ <windowtitle>${project.name} Documentation (Version: ${project.version})</windowtitle>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <!-- ======================================================================= -->
+ <!-- D E P E N D E N C I E S -->
+ <!-- ======================================================================= -->
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Apache Commons -->
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.5.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/Record.java b/src/main/java/org/apache/sling/scripting/sightly/Record.java
new file mode 100644
index 0000000..0b27f0c
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/Record.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.Set;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * A {@code Record} is a key-value immutable object understood by the Sightly runtime, used for abstracting complex objects like Sightly
+ * templates (declared with the {@code data-sly-template} block element) or objects that need to be translated from Java to JavaScript
+ * and back.
+ *
+ * @param <T> the type of values for this record
+ */
+@ConsumerType
+public interface Record<T> {
+
+ /**
+ * Gets the value of a specified property.
+ *
+ * @param name the name of the property
+ * @return the value of the property or {@code null} if this record does not have the specified property
+ */
+ T getProperty(String name);
+
+ /**
+ * Gets the set of names for this record's properties.
+ *
+ * @return this record's properties' names
+ */
+ Set<String> getPropertyNames();
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
new file mode 100644
index 0000000..c14b95e
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/extension/RuntimeExtension.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.extension;
+
+import org.apache.sling.scripting.sightly.render.RenderContext;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * A {@code RuntimeExtension} represents a Sightly runtime construct that provides some processing capabilities for the various
+ * {@code data-sly-*} block elements.
+ */
+@ConsumerType
+public interface RuntimeExtension {
+
+ /**
+ * For OSGi environments this is the name of the service registration property indicating the {@code RuntimeExtension} name.
+ */
+ String NAME = "org.apache.sling.scripting.sightly.extension.name";
+
+ /**
+ * Call the {@code RuntimeExtension}
+ *
+ * @param renderContext the runtime context
+ * @param arguments the call arguments
+ * @return an extension instance
+ */
+ Object call(RenderContext renderContext, Object... arguments);
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/extension/package-info.java
new file mode 100644
index 0000000..c1a6d5f
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/extension/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.extension;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java
new file mode 100644
index 0000000..8a16d4e
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/ClassInfo.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * This interface provides information about classes that will be generated by the {@link JavaClassBackendCompiler}.
+ */
+@ProviderType
+public interface ClassInfo {
+
+ /**
+ * Returns the class simple name.
+ *
+ * @return the class simple name
+ */
+ String getSimpleClassName();
+
+ /**
+ * Returns the class' package name.
+ *
+ * @return the class' package name
+ */
+ String getPackageName();
+
+ /**
+ * Returns the fully qualified class name.
+ *
+ * @return the fully qualified class name
+ */
+ String getFullyQualifiedClassName();
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java
new file mode 100644
index 0000000..b5b0b12
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/CompilationOutput.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import java.util.Map;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The {@code CompilationOutput} encapsulates the result of a compile operation as processed by the {@link JavaClassBackendCompiler}.
+ */
+@ProviderType
+public interface CompilationOutput {
+
+ /**
+ * Provides the generated class' main body section.
+ *
+ * @return the generated class' main body section
+ */
+ String getMainBody();
+
+ /**
+ * Provides the sub-templates ({@code data-sly-template}) code sections.
+ *
+ * @return the sub-templates ({@code data-sly-template}) code sections
+ */
+ Map<String, CompilationOutput> getSubTemplates();
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/GlobalShadowCheckBackendCompiler.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/GlobalShadowCheckBackendCompiler.java
new file mode 100644
index 0000000..5806229
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/GlobalShadowCheckBackendCompiler.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import java.util.Set;
+
+import org.apache.sling.scripting.sightly.compiler.backend.BackendCompiler;
+import org.apache.sling.scripting.sightly.compiler.commands.CommandStream;
+import org.apache.sling.scripting.sightly.java.compiler.impl.CommandVisitorHandler;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GlobalShadowChecker;
+
+/**
+ * Wrapping {@link BackendCompiler} that checks for global bindings shadowing.
+ */
+public final class GlobalShadowCheckBackendCompiler implements BackendCompiler {
+
+ private final BackendCompiler baseBackend;
+ private final Set<String> globals;
+
+ public GlobalShadowCheckBackendCompiler(BackendCompiler baseBackend, Set<String> globals) {
+ this.baseBackend = baseBackend;
+ this.globals = globals;
+ }
+
+ @Override
+ public void handle(CommandStream stream) {
+ stream.addHandler(new CommandVisitorHandler(new GlobalShadowChecker(globals)));
+ baseBackend.handle(stream);
+ }
+
+ public CompilationOutput build(ClassInfo classInfo) {
+ return null;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java
new file mode 100644
index 0000000..87e9655
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaClassBackendCompiler.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.scripting.sightly.compiler.backend.BackendCompiler;
+import org.apache.sling.scripting.sightly.compiler.commands.CommandStream;
+import org.apache.sling.scripting.sightly.compiler.commands.StatefulVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.impl.CodeGenVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.impl.CommandVisitorHandler;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaClassTemplate;
+import org.apache.sling.scripting.sightly.java.compiler.impl.UnitBuilder;
+
+/**
+ * {@link BackendCompiler} that generates a Java class.
+ */
+public final class JavaClassBackendCompiler implements BackendCompiler {
+
+ private static final String COMPILED_UNIT_TEMPLATE = "templates/compiled_unit_template.txt";
+ private static final String SUBTEMPLATE = "templates/subtemplate.txt";
+ private static final String mainTemplate;
+ private static final String childTemplate;
+
+ private UnitBuilder unitBuilder = new UnitBuilder();
+
+ static {
+ try {
+ mainTemplate = IOUtils
+ .toString(JavaClassTemplate.class.getClassLoader().getResourceAsStream(COMPILED_UNIT_TEMPLATE), "UTF-8");
+ childTemplate = IOUtils.toString(JavaClassTemplate.class.getClassLoader().getResourceAsStream(SUBTEMPLATE), "UTF-8");
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+
+ @Override
+ public void handle(CommandStream stream) {
+ StatefulVisitor statefulVisitor = new StatefulVisitor();
+ final CodeGenVisitor visitor = new CodeGenVisitor(unitBuilder, statefulVisitor.getControl());
+ statefulVisitor.initializeWith(visitor);
+ stream.addHandler(new CommandVisitorHandler(statefulVisitor) {
+ @Override
+ public void onDone() {
+ super.onDone();
+ visitor.finish();
+ }
+ });
+ }
+
+ /**
+ * Provided the class information, this method will build the source code for the generated Java class.
+ *
+ * @param classInfo the class information
+ * @return the generated Java class' source code
+ */
+ public String build(ClassInfo classInfo) {
+ CompilationOutput compilationOutput = unitBuilder.build();
+ JavaClassTemplate mainTemplate = newMainTemplate();
+ mainTemplate.setPackageName(classInfo.getPackageName());
+ mainTemplate.setClassName(classInfo.getSimpleClassName());
+ processCompilationResult(compilationOutput, mainTemplate);
+ return mainTemplate.toString();
+ }
+
+ private void processCompilationResult(CompilationOutput result, JavaClassTemplate mainTemplate) {
+ mainTemplate.writeMainBody(result.getMainBody());
+ for (Map.Entry<String, CompilationOutput> entry : result.getSubTemplates().entrySet()) {
+ JavaClassTemplate childTemplate = newChildTemplate();
+ processCompilationResult(entry.getValue(), childTemplate);
+ mainTemplate.writeSubTemplate(entry.getKey(), childTemplate.toString());
+ }
+ }
+
+ private JavaClassTemplate newMainTemplate() {
+ return new JavaClassTemplate(mainTemplate);
+ }
+
+ private JavaClassTemplate newChildTemplate() {
+ return new JavaClassTemplate(childTemplate);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
new file mode 100644
index 0000000..0b68af3
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/RenderUnit.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+
+import org.apache.sling.scripting.sightly.Record;
+import org.apache.sling.scripting.sightly.render.RenderContext;
+
+/**
+ * Basic unit of rendering. This also extends the record interface. The properties for a unit are the sub-units.
+ */
+public abstract class RenderUnit implements Record<RenderUnit> {
+
+ private final Map<String, RenderUnit> subTemplates = new HashMap<>();
+
+ private Map<String, RenderUnit> siblings;
+
+ /**
+ * Render the main script template
+ *
+ * @param renderContext the rendering context
+ * @param arguments the arguments for this unit
+ */
+ public final void render(PrintWriter out, RenderContext renderContext, Bindings arguments) {
+ Bindings globalBindings = renderContext.getBindings();
+ render(out, buildGlobalScope(globalBindings), new CaseInsensitiveBindings(arguments), renderContext);
+ }
+
+ @Override
+ public RenderUnit getProperty(String name) {
+ return subTemplates.get(name.toLowerCase());
+ }
+
+ @Override
+ public Set<String> getPropertyNames() {
+ return subTemplates.keySet();
+ }
+
+ protected abstract void render(PrintWriter out,
+ Bindings bindings,
+ Bindings arguments,
+ RenderContext renderContext);
+
+ @SuppressWarnings({"unused", "unchecked"})
+ protected void callUnit(PrintWriter out, RenderContext renderContext, Object templateObj, Object argsObj) {
+ if (!(templateObj instanceof RenderUnit)) {
+ if (templateObj == null) {
+ throw new SightlyJavaCompilerException("data-sly-call: expression evaluates to null.");
+ }
+ if (renderContext.getObjectModel().isPrimitive(templateObj)) {
+ throw new SightlyJavaCompilerException(
+ "data-sly-call: primitive \"" + templateObj.toString() + "\" does not represent a Sightly template.");
+ } else if (templateObj instanceof String) {
+ throw new SightlyJavaCompilerException(
+ "data-sly-call: String '" + templateObj.toString() + "' does not represent a Sightly template.");
+ }
+ throw new SightlyJavaCompilerException(
+ "data-sly-call: " + templateObj.getClass().getName() + " does not represent a Sightly template.");
+ }
+ RenderUnit unit = (RenderUnit) templateObj;
+ Map<String, Object> argumentsMap = renderContext.getObjectModel().toMap(argsObj);
+ Bindings arguments = new SimpleBindings(Collections.unmodifiableMap(argumentsMap));
+ unit.render(out, renderContext, arguments);
+ }
+
+ @SuppressWarnings("UnusedDeclaration")
+ protected FluentMap obj() {
+ return new FluentMap();
+ }
+
+ @SuppressWarnings("unused")
+ protected final void addSubTemplate(String name, RenderUnit renderUnit) {
+ renderUnit.setSiblings(subTemplates);
+ subTemplates.put(name.toLowerCase(), renderUnit);
+ }
+
+ private void setSiblings(Map<String, RenderUnit> siblings) {
+ this.siblings = siblings;
+ }
+
+ private Bindings buildGlobalScope(Bindings bindings) {
+ SimpleBindings simpleBindings = new SimpleBindings(bindings);
+ simpleBindings.putAll(bindings);
+ if (siblings != null) {
+ simpleBindings.putAll(siblings);
+ }
+ simpleBindings.putAll(subTemplates);
+ return new CaseInsensitiveBindings(simpleBindings);
+ }
+
+ protected static class FluentMap extends HashMap<String, Object> {
+
+ /**
+ * Fluent variant of put.
+ *
+ * @param name the name of the property
+ * @param value the value of the property
+ * @return this instance
+ */
+ public FluentMap with(String name, Object value) {
+ put(name, value);
+ return this;
+ }
+
+ }
+
+ private static final class CaseInsensitiveBindings extends SimpleBindings {
+
+ private CaseInsensitiveBindings(Map<String, Object> m) {
+ for (Map.Entry<String, Object> entry : m.entrySet()) {
+ put(entry.getKey().toLowerCase(), entry.getValue());
+ }
+ }
+
+ @Override
+ public Object get(Object key) {
+ if (!(key instanceof String)) {
+ throw new ClassCastException("key should be a String");
+ }
+ return super.get(((String) key).toLowerCase());
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ if (!(key instanceof String)) {
+ throw new ClassCastException("key should be a String");
+ }
+ return super.containsKey(((String) key).toLowerCase());
+ }
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/SightlyJavaCompilerException.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/SightlyJavaCompilerException.java
new file mode 100644
index 0000000..7c55278
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/SightlyJavaCompilerException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+public class SightlyJavaCompilerException extends RuntimeException {
+
+ public SightlyJavaCompilerException() {
+ super();
+ }
+
+ public SightlyJavaCompilerException(String message) {
+ super(message);
+ }
+
+ public SightlyJavaCompilerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SightlyJavaCompilerException(Throwable cause) {
+ super(cause);
+ }
+
+ protected SightlyJavaCompilerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java
new file mode 100644
index 0000000..a619ff6
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CodeGenVisitor.java
@@ -0,0 +1,250 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.sling.scripting.sightly.compiler.commands.CommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.commands.Conditional;
+import org.apache.sling.scripting.sightly.compiler.commands.Loop;
+import org.apache.sling.scripting.sightly.compiler.commands.OutText;
+import org.apache.sling.scripting.sightly.compiler.commands.OutputVariable;
+import org.apache.sling.scripting.sightly.compiler.commands.Procedure;
+import org.apache.sling.scripting.sightly.compiler.commands.StatefulVisitor;
+import org.apache.sling.scripting.sightly.compiler.commands.VariableBinding;
+
+/**
+ * Java code generator
+ */
+public class CodeGenVisitor implements CommandVisitor {
+
+ private final JavaSource source;
+ private final UnitBuilder unitBuilder;
+ private final Stack<String> loopStatusStack = new Stack<>();
+ private final VariableAnalyzer analyzer = new VariableAnalyzer();
+ private final StatefulVisitor.StateControl control;
+ private final Set<String> unitParameters;
+
+ public CodeGenVisitor(UnitBuilder unitBuilder, StatefulVisitor.StateControl control) {
+ this.unitBuilder = unitBuilder;
+ this.source = unitBuilder.getSource();
+ this.control = control;
+ this.unitParameters = new HashSet<>();
+ for (String param : unitBuilder.getParameters()) {
+ this.unitParameters.add(param.toLowerCase());
+ }
+ }
+
+ /**
+ * Complete building the source
+ */
+ public void finish() {
+ source.prepend(initializations());
+ }
+
+ private String initializations() {
+ JavaSource initSource = new JavaSource();
+ for (VariableDescriptor descriptor : analyzer.allVariables()) {
+ initVariable(descriptor, initSource);
+ }
+ return initSource.toString();
+ }
+
+ private void initVariable(VariableDescriptor descriptor, JavaSource initSource) {
+ VariableScope scope = descriptor.getScope();
+ if (scope == VariableScope.DYNAMIC) {
+ initSource.beginAssignment(descriptor.getAssignedName());
+ if (descriptor.isTemplateVariable()) {
+ initSource.startCall(SourceGenConstants.RECORD_GET_VALUE);
+ } else if (unitParameters.contains(descriptor.getOriginalName().toLowerCase())) {
+ initSource.startMethodCall(SourceGenConstants.ARGUMENTS_FIELD, SourceGenConstants.BINDINGS_GET_METHOD);
+ } else {
+ initSource.startMethodCall(SourceGenConstants.BINDINGS_FIELD, SourceGenConstants.BINDINGS_GET_METHOD);
+ }
+ initSource.stringLiteral(descriptor.getOriginalName())
+ .endCall()
+ .endStatement();
+ } else if (scope == VariableScope.GLOBAL) {
+ initSource.beginAssignment(descriptor.getAssignedName())
+ .nullLiteral()
+ .endStatement();
+ }
+ String listCoercionVar = descriptor.getListCoercion();
+ if (listCoercionVar != null) {
+ //need to initialize the list coercion to null
+ initSource.beginAssignment(listCoercionVar, SourceGenConstants.COLLECTION_TYPE)
+ .nullLiteral().endStatement();
+ }
+ }
+
+ @Override
+ public void visit(Conditional.Start conditional) {
+ VariableDescriptor descriptor = analyzer.descriptor(conditional.getVariable());
+ boolean negate = !conditional.getExpectedTruthValue();
+ source.beginIf();
+ if (negate) {
+ source.negation();
+ }
+ if (descriptor.getType() == Type.BOOLEAN) {
+ source.append(descriptor.getAssignedName());
+ } else {
+ source.objectModel().startCall(SourceGenConstants.ROM_TO_BOOLEAN, true).append(descriptor.getAssignedName()).endCall();
+ }
+ source.completeIf();
+ }
+
+ @Override
+ public void visit(Conditional.End conditionalEnd) {
+ source.endIf();
+ }
+
+ @Override
+ public void visit(VariableBinding.Start variableBinding) {
+ source.startBlock();
+ TypeInfo typeInfo = TypeInference.inferTypes(variableBinding.getExpression(), analyzer);
+ Type type = typeInfo.typeOf(variableBinding.getExpression());
+ String properName = declare(variableBinding.getVariableName(), type);
+ source.beginAssignment(properName, type.getNativeClass());
+ ExpressionTranslator.buildExpression(
+ variableBinding.getExpression(),
+ source,
+ analyzer,
+ typeInfo);
+ source.endStatement();
+ }
+
+ @Override
+ public void visit(VariableBinding.End variableBindingEnd) {
+ VariableDescriptor descriptor = analyzer.endVariable();
+ String listCoercionVar = descriptor.getListCoercion();
+ if (listCoercionVar != null) {
+ //this variable was coerced to list at some point
+ generateCoercionClearing(listCoercionVar);
+ }
+ source.endBlock();
+ }
+
+ @Override
+ public void visit(VariableBinding.Global globalAssignment) {
+ TypeInfo typeInfo = TypeInference.inferTypes(globalAssignment.getExpression(), analyzer);
+ VariableDescriptor descriptor = analyzer.declareGlobal(globalAssignment.getVariableName());
+ String name = descriptor.getAssignedName();
+ source.append(name).assign();
+ ExpressionTranslator.buildExpression(
+ globalAssignment.getExpression(),
+ source,
+ analyzer,
+ typeInfo);
+ source.endStatement();
+ String listCoercionVar = descriptor.getListCoercion();
+ if (listCoercionVar != null) {
+ //variable was used for list coercion. Generating a coercion clearing
+ generateCoercionClearing(listCoercionVar);
+ }
+ }
+
+ @Override
+ public void visit(OutputVariable outputVariable) {
+ String variable = analyzer.assignedName(outputVariable.getVariableName());
+ source.startStatement()
+ .startMethodCall(SourceGenConstants.OUT_BUFFER, SourceGenConstants.WRITE_METHOD)
+ .objectModel().startCall(SourceGenConstants.ROM_TO_STRING, true)
+ .append(variable)
+ .endCall()
+ .endCall()
+ .endStatement();
+ }
+
+ @Override
+ public void visit(OutText outText) {
+ source.startStatement()
+ .startMethodCall(SourceGenConstants.OUT_BUFFER, SourceGenConstants.WRITE_METHOD)
+ .stringLiteral(outText.getText())
+ .endCall()
+ .endStatement();
+ }
+
+ @Override
+ public void visit(Loop.Start loop) {
+ VariableDescriptor descriptor = analyzer.descriptor(loop.getListVariable());
+ String listVariable = descriptor.getAssignedName();
+ String collectionVar = descriptor.requireListCoercion();
+ source.beginIf().append(collectionVar).equality().nullLiteral().completeIf()
+ .startStatement()
+ .append(collectionVar)
+ .assign()
+ .objectModel().startCall(SourceGenConstants.ROM_TO_COLLECTION, true)
+ .append(listVariable)
+ .endCall()
+ .endStatement()
+ .endIf();
+ String indexVar = declare(loop.getIndexVariable(), Type.LONG);
+ source.beginAssignment(indexVar, Type.LONG.getNativeClass()).number(0).endStatement();
+ String itemVar = declare(loop.getItemVariable(), Type.UNKNOWN);
+ source.beginFor(itemVar, collectionVar);
+ loopStatusStack.push(indexVar);
+ }
+
+ @Override
+ public void visit(Loop.End loopEnd) {
+ String indexVar = loopStatusStack.pop();
+ source.startStatement().append(indexVar).increment().endStatement();
+ source.endFor();
+ analyzer.endVariable();
+ analyzer.endVariable();
+ }
+
+ @Override
+ public void visit(Procedure.Start startProcedure) {
+ UnitBuilder subTemplateUnit = unitBuilder.newSubBuilder(startProcedure.getName(), startProcedure.getParameters());
+ analyzer.declareTemplate(startProcedure.getName());
+ control.push(new CodeGenVisitor(subTemplateUnit, control));
+ }
+
+ @Override
+ public void visit(Procedure.End endProcedure) {
+ CodeGenVisitor previous = (CodeGenVisitor) control.pop();
+ previous.finish();
+ }
+
+ @Override
+ public void visit(Procedure.Call procedureCall) {
+ String templateVar = analyzer.assignedName(procedureCall.getTemplateVariable());
+ String argVar = analyzer.assignedName(procedureCall.getArgumentsVariable());
+ source.startStatement()
+ .startCall(SourceGenConstants.CALL_UNIT_METHOD, false)
+ .append(SourceGenConstants.OUT_BUFFER)
+ .separateArgument()
+ .append(SourceGenConstants.RENDER_CONTEXT_INSTANCE)
+ .separateArgument()
+ .append(templateVar)
+ .separateArgument()
+ .append(argVar)
+ .endCall()
+ .endStatement();
+ }
+
+ private String declare(String originalName, Type type) {
+ return analyzer.declareVariable(originalName, type).getAssignedName();
+ }
+
+ private void generateCoercionClearing(String coercionVariableName) {
+ source.startStatement().append(coercionVariableName).assign().nullLiteral().endStatement();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CommandVisitorHandler.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CommandVisitorHandler.java
new file mode 100644
index 0000000..8683512
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CommandVisitorHandler.java
@@ -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.
+ ******************************************************************************/
+
+package org.apache.sling.scripting.sightly.java.compiler.impl;
+
+import org.apache.sling.scripting.sightly.compiler.commands.Command;
+import org.apache.sling.scripting.sightly.compiler.commands.CommandHandler;
+import org.apache.sling.scripting.sightly.compiler.commands.CommandVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.SightlyJavaCompilerException;
+
+public class CommandVisitorHandler implements CommandHandler {
+
+ private CommandVisitor commandVisitor;
+
+ public CommandVisitorHandler(CommandVisitor commandVisitor) {
+ this.commandVisitor = commandVisitor;
+ }
+
+ @Override
+ public void onEmit(Command command) {
+ command.accept(commandVisitor);
+ }
+
+ @Override
+ public void onError(String errorMessage) {
+ throw new SightlyJavaCompilerException(errorMessage);
+ }
+
+ @Override
+ public void onDone() {
+ // do nothing
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CompilationOutputImpl.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CompilationOutputImpl.java
new file mode 100644
index 0000000..8aedeaa
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/CompilationOutputImpl.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.java.compiler.CompilationOutput;
+
+public final class CompilationOutputImpl implements CompilationOutput {
+
+ private final String mainBody;
+ private final Map<String, CompilationOutput> subTemplates;
+
+
+ public CompilationOutputImpl(String mainBody, Map<String, CompilationOutput> subTemplates) {
+ this.mainBody = mainBody;
+ this.subTemplates = subTemplates;
+ }
+
+ @Override
+ public String getMainBody() {
+ return mainBody;
+ }
+
+ @Override
+ public Map<String, CompilationOutput> getSubTemplates() {
+ return subTemplates;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java
new file mode 100644
index 0000000..6108c8b
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/ExpressionTranslator.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperation;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BooleanConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.NullLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.NumericConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.PropertyAccess;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.TernaryOperator;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperation;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.BinaryOpGen;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.Operators;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.UnaryOpGen;
+
+/**
+ * Builds expressions within a sling source file.
+ */
+public final class ExpressionTranslator extends SideEffectVisitor {
+
+ private final JavaSource source;
+ private final VariableAnalyzer analyzer;
+ private final TypeInfo typeInfo;
+
+ private ExpressionTranslator(JavaSource source, VariableAnalyzer analyzer, TypeInfo typeInfo) {
+ this.source = source;
+ this.analyzer = analyzer;
+ this.typeInfo= typeInfo;
+ }
+
+ public static void buildExpression(ExpressionNode node,
+ JavaSource source,
+ VariableAnalyzer analyzer,
+ TypeInfo typeInfo) {
+ ExpressionTranslator builder = new ExpressionTranslator(source, analyzer, typeInfo);
+ builder.traverse(node);
+ }
+
+ public void traverse(ExpressionNode node) {
+ visit(node);
+ }
+
+ private void visit(ExpressionNode node) {
+ node.accept(this);
+ }
+
+ @Override
+ public void visit(PropertyAccess propertyAccess) {
+ if (typeInfo.typeOf(propertyAccess.getTarget()) == Type.MAP) {
+ //Special optimization for maps
+ visit(propertyAccess.getTarget());
+ source.startCall(SourceGenConstants.MAP_GET, true);
+ visit(propertyAccess.getProperty());
+ source.endCall();
+ } else {
+ source.objectModel().startCall(SourceGenConstants.ROM_RESOLVE_PROPERTY, true);
+ visit(propertyAccess.getTarget());
+ source.separateArgument();
+ visit(propertyAccess.getProperty());
+ source.endCall();
+ }
+ }
+
+ @Override
+ public void visit(Identifier identifier) {
+ String safeName = analyzer.assignedName(identifier.getName());
+ source.append(safeName);
+ }
+
+ @Override
+ public void visit(StringConstant text) {
+ source.stringLiteral(text.getText());
+ }
+
+ @Override
+ public void visit(BinaryOperation binaryOperation) {
+ BinaryOpGen opGen = Operators.generatorFor(binaryOperation.getOperator());
+ source.startExpression();
+ opGen.generate(source, this,
+ typeInfo.getTyped(binaryOperation.getLeftOperand()),
+ typeInfo.getTyped(binaryOperation.getRightOperand()));
+ source.endExpression();
+ }
+
+ @Override
+ public void visit(BooleanConstant booleanConstant) {
+ source.append(Boolean.toString(booleanConstant.getValue()));
+ }
+
+ @Override
+ public void visit(NumericConstant numericConstant) {
+ source.append(numericConstant.getValue().toString()); //todo: check correctness
+ }
+
+ @Override
+ public void visit(UnaryOperation unaryOperation) {
+ UnaryOperator operator = unaryOperation.getOperator();
+ ExpressionNode operand = unaryOperation.getTarget();
+ UnaryOpGen unaryOpGen = Operators.generatorFor(operator);
+ source.startExpression();
+ unaryOpGen.generate(source, this, typeInfo.getTyped(operand));
+ source.endExpression();
+ }
+
+ @Override
+ public void visit(TernaryOperator ternaryOperator) {
+ GenHelper.generateTernary(source, this,
+ typeInfo.getTyped(ternaryOperator.getCondition()),
+ typeInfo.getTyped(ternaryOperator.getThenBranch()),
+ typeInfo.getTyped(ternaryOperator.getElseBranch()));
+ }
+
+ @Override
+ public void visit(RuntimeCall runtimeCall) {
+ source.startMethodCall(SourceGenConstants.RENDER_CONTEXT_INSTANCE, SourceGenConstants.RUNTIME_CALL_METHOD)
+ .stringLiteral(runtimeCall.getFunctionName());
+ for (ExpressionNode arg : runtimeCall.getArguments()) {
+ source.separateArgument();
+ visit(arg);
+ }
+ source.endCall();
+ }
+
+ @Override
+ public void visit(MapLiteral mapLiteral) {
+ source.startCall(SourceGenConstants.START_MAP_METHOD).endCall();
+ for (Map.Entry<String, ExpressionNode> entry : mapLiteral.getMap().entrySet()) {
+ source.startCall(SourceGenConstants.MAP_TYPE_ADD, true)
+ .stringLiteral(entry.getKey())
+ .separateArgument();
+ visit(entry.getValue());
+ source.endCall();
+ }
+ }
+
+ @Override
+ public void visit(ArrayLiteral arrayLiteral) {
+ source.startExpression().startArray();
+ boolean needsComma = false;
+ for (ExpressionNode node : arrayLiteral.getItems()) {
+ if (needsComma) {
+ source.separateArgument();
+ }
+ visit(node);
+ needsComma = true;
+ }
+ source.endArray().endExpression();
+ }
+
+ @Override
+ public void visit(NullLiteral nullLiteral) {
+ source.nullLiteral();
+ }
+
+ public VariableAnalyzer getAnalyzer() {
+ return analyzer;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GenHelper.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GenHelper.java
new file mode 100644
index 0000000..6f00eee
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GenHelper.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.TypedNode;
+
+/**
+ * Helper for code generation
+ */
+public class GenHelper {
+
+ public static void generateTernary(JavaSource source, SideEffectVisitor visitor,
+ TypedNode condition, TypedNode thenBranch, TypedNode elseBranch) {
+ source.startExpression();
+ typeCoercion(source, visitor, condition, Type.BOOLEAN);
+ source.conditional();
+ thenBranch.getNode().accept(visitor);
+ source.conditionalBranchSep();
+ elseBranch.getNode().accept(visitor);
+ source.endExpression();
+ }
+
+ public static void typeCoercion(JavaSource source, SideEffectVisitor visitor, TypedNode node, Type type) {
+ if (type == node.getType() || type == Type.UNKNOWN) {
+ node.getNode().accept(visitor);
+ } else if (type == Type.LONG && node.getType() == Type.DOUBLE) {
+ callLongCoercion(source, visitor, node.getNode());
+ } else {
+ String coercionMethod = dynamicCoercions.get(type);
+ if (coercionMethod == null) {
+ throw new UnsupportedOperationException("Cannot generate coercion to type " + type);
+ }
+ callDynamicCoercion(source, visitor, node.getNode(), dynamicCoercions.get(type));
+ }
+ }
+
+ public static void listCoercion(JavaSource source, ExpressionTranslator visitor, TypedNode typedNode) {
+ ExpressionNode node = typedNode.getNode();
+ if (node instanceof Identifier) {
+ //using list coercion caching optimization
+ VariableDescriptor descriptor = visitor.getAnalyzer().descriptor(((Identifier) node).getName());
+ String listCoercionVar = descriptor.requireListCoercion();
+ source.startExpression()
+ .append(listCoercionVar)
+ .equality()
+ .nullLiteral()
+ .conditional()
+ .startExpression()
+ .append(listCoercionVar)
+ .assign()
+ .objectModel().startCall(SourceGenConstants.ROM_TO_COLLECTION, true);
+ node.accept(visitor);
+ source
+ .endCall()
+ .endExpression()
+ .conditionalBranchSep()
+ .append(listCoercionVar)
+ .endExpression();
+ } else {
+ source.objectModel().startCall(SourceGenConstants.ROM_TO_COLLECTION, true);
+ typedNode.getNode().accept(visitor);
+ source.endCall();
+ }
+ }
+
+ private static void callLongCoercion(JavaSource source, SideEffectVisitor visitor, ExpressionNode node) {
+ source.cast(Type.LONG.getNativeClass());
+ source.startExpression();
+ node.accept(visitor);
+ source.endExpression();
+ }
+
+ private static void callDynamicCoercion(JavaSource source, SideEffectVisitor visitor, ExpressionNode node, String methodName) {
+ source.objectModel().startCall(methodName, true);
+ node.accept(visitor);
+ source.endCall();
+ }
+
+ private static final Map<Type, String> dynamicCoercions = new HashMap<>();
+
+ static {
+ dynamicCoercions.put(Type.STRING, SourceGenConstants.ROM_TO_STRING);
+ dynamicCoercions.put(Type.BOOLEAN, SourceGenConstants.ROM_TO_BOOLEAN);
+ dynamicCoercions.put(Type.LONG, SourceGenConstants.ROM_TO_NUMBER);
+ dynamicCoercions.put(Type.DOUBLE, SourceGenConstants.ROM_TO_NUMBER);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GlobalShadowChecker.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GlobalShadowChecker.java
new file mode 100644
index 0000000..f3b8fd0
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/GlobalShadowChecker.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.scripting.sightly.compiler.commands.AbstractCommandVisitor;
+import org.apache.sling.scripting.sightly.compiler.commands.Loop;
+import org.apache.sling.scripting.sightly.compiler.commands.Procedure;
+import org.apache.sling.scripting.sightly.compiler.commands.VariableBinding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Checks whether variable declarations shadow global bindings
+ */
+public class GlobalShadowChecker extends AbstractCommandVisitor {
+
+ private static final Logger log = LoggerFactory.getLogger(GlobalShadowChecker.class);
+ private final Map<String, String> globals;
+
+ public GlobalShadowChecker(Set<String> globals) {
+ this.globals = new HashMap<>();
+ for (String global : globals) {
+ this.globals.put(global.toLowerCase(), global);
+ }
+ }
+
+ @Override
+ public void visit(VariableBinding.Start variableBindingStart) {
+ checkVariable(variableBindingStart.getVariableName());
+ }
+
+ @Override
+ public void visit(VariableBinding.Global globalAssignment) {
+ checkVariable(globalAssignment.getVariableName());
+ }
+
+ @Override
+ public void visit(Loop.Start loopStart) {
+ checkVariable(loopStart.getItemVariable());
+ checkVariable(loopStart.getIndexVariable());
+ }
+
+ @Override
+ public void visit(Procedure.Start startProcedure) {
+ checkVariable(startProcedure.getName());
+ }
+
+ private void checkVariable(String variableName) {
+ variableName = variableName.toLowerCase();
+ if (globals.containsKey(variableName)) {
+ String originalName = globals.get(variableName);
+ log.warn("Global variable '{}' is being overridden in template", originalName);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java
new file mode 100644
index 0000000..34be88b
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaClassTemplate.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+/**
+ * Template for generated Java classes.
+ */
+public class JavaClassTemplate {
+
+
+ private String classTemplate;
+
+ private static final String MAIN_BODY = "MainBody";
+ private static final String CLASS_NAME = "ClassName";
+ private static final String PACKAGE_NAME = "PackageName";
+ private static final String TEMPLATE_INIT = "SubTemplateMapInit";
+ private static final String NAME = "Name";
+
+ private StringBuilder templateInitBuilder = new StringBuilder();
+
+ public JavaClassTemplate(String template) {
+ this.classTemplate = template;
+ }
+
+ public void writeMainBody(String content) {
+ setPart(MAIN_BODY, content);
+ }
+
+ public void writeSubTemplate(String name, String content) {
+ templateInitBuilder.append(insertPart(NAME, content, name));
+ }
+
+ public void setClassName(String name) {
+ setPart(CLASS_NAME, name);
+ }
+
+ public void setPackageName(String name) {
+ setPart(PACKAGE_NAME, name);
+ }
+
+ @Override
+ public String toString() {
+ return insertPart(TEMPLATE_INIT, classTemplate, templateInitBuilder.toString());
+ }
+
+ private void setPart(String partName, String content) {
+ classTemplate = insertPart(partName, classTemplate, content);
+ }
+
+ private String insertPart(String partName, String original, String content) {
+ String id = "##" + partName + "##";
+ return original.replace(id, content);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java
new file mode 100644
index 0000000..db67cf9
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java
@@ -0,0 +1,266 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+/**
+ * Builder object for a Java class printing method.
+ */
+public class JavaSource {
+
+ private static final String INDENT = " ";
+
+ private int indentLevel;
+ private final StringBuilder builder = new StringBuilder();
+
+ public JavaSource prepend(String str) {
+ builder.insert(0, str);
+ return this;
+ }
+
+ public JavaSource beginIf() {
+ indent().append("if (");
+ return this;
+ }
+
+ public JavaSource completeIf() {
+ append(") {\n");
+ incIndent();
+ return this;
+ }
+
+ public JavaSource endBlock() {
+ decIndent();
+ indent().append("}\n");
+ return this;
+ }
+
+ public JavaSource comment(String text) {
+ indent().append("//").append(text).append("\n");
+ return this;
+ }
+
+ public JavaSource assign() {
+ return append(" = ");
+ }
+
+ public JavaSource number(int value) {
+ return append(Integer.toString(value));
+ }
+
+ public JavaSource increment() {
+ return append("++");
+ }
+
+ public JavaSource beginAssignment(String variable, String type) {
+ return declare(variable, type).assign();
+ }
+
+ public JavaSource beginAssignment(String variable) {
+ return beginAssignment(variable, "Object");
+ }
+
+ public JavaSource declare(String variable, String type) {
+ return startStatement().append(type).append(" ").append(variable);
+ }
+
+ public JavaSource declare(String variable) {
+ return declare(variable, "Object");
+ }
+
+ public JavaSource equality() {
+ return append(" == ");
+ }
+
+ public JavaSource startCall(String methodName, boolean useDot) {
+ if (useDot) {
+ builder.append('.');
+ }
+ builder.append(methodName).append('(');
+ return this;
+ }
+
+ public JavaSource startCall(String methodName) {
+ return startCall(methodName, false);
+ }
+
+ public JavaSource startMethodCall(String target, String method) {
+ return append(target).startCall(method, true);
+ }
+
+ public JavaSource startArray() {
+ return append("new Object[] {");
+ }
+
+ public JavaSource endArray() {
+ return append("}");
+ }
+
+ public JavaSource startStatement() {
+ indent();
+ return this;
+ }
+
+ public JavaSource nullLiteral() {
+ return append("null");
+ }
+
+ public JavaSource separateArgument() {
+ builder.append(", ");
+ return this;
+ }
+
+ public JavaSource stringLiteral(String text) {
+ builder.append('"')
+ .append(StringEscapeUtils.escapeJava(text))
+ .append('"');
+ return this;
+ }
+
+ public JavaSource startExpression() {
+ builder.append('(');
+ return this;
+ }
+
+ public JavaSource endExpression() {
+ builder.append(')');
+ return this;
+ }
+
+ public JavaSource endCall() {
+ builder.append(')');
+ return this;
+ }
+
+ public JavaSource startBlock() {
+ indent().append("{\n");
+ incIndent();
+ return this;
+ }
+
+ public JavaSource beginFor(String itemVariable, String listVariable) {
+ startStatement()
+ .append("for (Object ")
+ .append(itemVariable)
+ .append(" : ")
+ .append(listVariable)
+ .append(") {\n");
+ incIndent();
+ return this;
+ }
+
+ public JavaSource endFor() {
+ return endBlock();
+ }
+
+ public JavaSource endIf() {
+ return endBlock();
+ }
+
+ public JavaSource beginNewInstanceCall(String className) {
+ return append("new ").append(className).append("(");
+ }
+
+ public JavaSource append(String str) {
+ builder.append(str);
+ return this;
+ }
+
+ public JavaSource endStatement() {
+ builder.append(";\n");
+ return this;
+ }
+
+ public JavaSource cast(String type) {
+ return append("(").append(type).append(")");
+ }
+
+ public JavaSource operator(String op) {
+ return append(" ").append(op).append(" ");
+ }
+
+ public JavaSource beginAnonymousInstance(String className) {
+ append("new ").append(className).append("() {\n");
+ incIndent();
+ return this;
+ }
+
+ public JavaSource endAnonymousInstance() {
+ decIndent();
+ append("}");
+ return this;
+ }
+
+ public JavaSource beginMethod(String name, String returnType) {
+ return startStatement().append("public ").append(returnType).append(" ").append(name).append("(");
+ }
+
+ public JavaSource methodParameter(String name, String type) {
+ return append(type).append(" ").append(name);
+ }
+
+ public JavaSource completeMethodSignature() {
+ append(") {\n");
+ incIndent();
+ return this;
+ }
+
+ public JavaSource endMethod() {
+ return endBlock();
+ }
+
+ public JavaSource conditional() {
+ return append(" ? ");
+ }
+
+ public JavaSource conditionalBranchSep() {
+ return append(" : ");
+ }
+
+ public JavaSource negation() {
+ return append("!");
+ }
+
+ public JavaSource newLine() {
+ return append("\n");
+ }
+
+ public JavaSource objectModel() {
+ return startMethodCall(SourceGenConstants.RENDER_CONTEXT_INSTANCE, SourceGenConstants.RENDER_CONTEXT_GET_OBJECT_MODEL).endCall();
+ }
+
+ private StringBuilder indent() {
+ for (int i = 0; i < indentLevel; i++) {
+ builder.append(INDENT);
+ }
+ return builder;
+ }
+
+ private void incIndent() {
+ indentLevel++;
+ }
+
+ private void decIndent() {
+ indentLevel--;
+ }
+
+ @Override
+ public String toString() {
+ return builder.toString();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/SourceGenConstants.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/SourceGenConstants.java
new file mode 100644
index 0000000..758dfd8
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/SourceGenConstants.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+/**
+ * Names related to Java source generation.
+ */
+public final class SourceGenConstants {
+
+ public static final String OUT_BUFFER = "out";
+
+ public static final String WRITE_METHOD = "write";
+
+ public static final String COLLECTION_TYPE = "Collection";
+
+ public static final String BINDINGS_FIELD = "bindings";
+
+ public static final String BINDINGS_GET_METHOD = "get";
+
+ public static final String START_MAP_METHOD = "obj";
+
+ public static final String MAP_TYPE_ADD = "with";
+
+ public static final String CALL_UNIT_METHOD = "callUnit";
+
+ public static final String RENDER_CONTEXT_INSTANCE = "renderContext";
+ public static final String RENDER_CONTEXT_GET_OBJECT_MODEL = "getObjectModel";
+ public static final String RUNTIME_OBJECT_MODEL = "AbstractRuntimeObjectModel";
+ public static final String ROM_RESOLVE_PROPERTY = "resolveProperty";
+ public static final String ROM_TO_BOOLEAN = "toBoolean";
+ public static final String ROM_TO_COLLECTION = "toCollection";
+ public static final String ROM_TO_MAP = "toMap";
+ public static final String ROM_TO_STRING = "toString";
+ public static final String ROM_TO_NUMBER = "toNumber";
+
+ public static final String RUNTIME_CALL_METHOD = "call";
+
+ public static final String COLLECTION_LENGTH_METHOD = "size";
+
+ public static final String MAP_GET = "get";
+ public static final String TRIM_METHOD = "trim";
+ public static final String STRING_EMPTY = "isEmpty";
+ public static final String RECORD_GET_VALUE = "getProperty";
+ public static final String ARGUMENTS_FIELD = "arguments";
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.java
new file mode 100644
index 0000000..e73d5e5
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/Type.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.java.compiler.impl;
+
+/**
+ * Type inferred for an expression
+ */
+public enum Type {
+ UNKNOWN("Object", false),
+ STRING("String", false),
+ LONG("long", true),
+ DOUBLE("double", true),
+ BOOLEAN("boolean", true),
+ MAP("java.util.Map", false);
+
+ private final String nativeClass;
+ private final boolean isPrimitive;
+
+ Type(String nativeClass, boolean isPrimitive) {
+ this.nativeClass = nativeClass;
+ this.isPrimitive = isPrimitive;
+ }
+
+ public String getNativeClass() {
+ return nativeClass;
+ }
+
+ public boolean isPrimitive() {
+ return isPrimitive;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
new file mode 100644
index 0000000..39377b8
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInference.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.BinaryOpGen;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.Operators;
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.UnaryOpGen;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.expression.NodeVisitor;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.ArrayLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperation;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BooleanConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.Identifier;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.NullLiteral;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.NumericConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.PropertyAccess;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.RuntimeCall;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.StringConstant;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.TernaryOperator;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperation;
+
+/**
+ * Expression translator which uses type information
+ */
+public final class TypeInference implements NodeVisitor<Type> {
+
+ private final VariableAnalyzer analyzer;
+ private final Map<ExpressionNode, Type> inferMap = new IdentityHashMap<ExpressionNode, Type>();
+
+
+ public static TypeInfo inferTypes(ExpressionNode node, VariableAnalyzer analyzer) {
+ TypeInference typeInference = new TypeInference(analyzer);
+ typeInference.infer(node);
+ return new TypeInfo(typeInference.inferMap);
+ }
+
+ private TypeInference(VariableAnalyzer analyzer) {
+ this.analyzer = analyzer;
+ }
+
+
+
+ private Type infer(ExpressionNode node) {
+ Type type = node.accept(this);
+ inferMap.put(node, type);
+ return type;
+ }
+
+ @Override
+ public Type evaluate(PropertyAccess propertyAccess) {
+ infer(propertyAccess.getTarget());
+ infer(propertyAccess.getProperty());
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public Type evaluate(Identifier identifier) {
+ return analyzer.descriptor(identifier.getName()).getType();
+ }
+
+ @Override
+ public Type evaluate(StringConstant text) {
+ return Type.STRING;
+ }
+
+ @Override
+ public Type evaluate(BinaryOperation binaryOperation) {
+ Type leftType = infer(binaryOperation.getLeftOperand());
+ Type rightType = infer(binaryOperation.getRightOperand());
+ BinaryOpGen opGen = Operators.generatorFor(binaryOperation.getOperator());
+ return opGen.returnType(leftType, rightType);
+ }
+
+ @Override
+ public Type evaluate(BooleanConstant booleanConstant) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public Type evaluate(NumericConstant numericConstant) {
+ Number number = numericConstant.getValue();
+ if (number instanceof Integer || number instanceof Long) {
+ return Type.LONG;
+ }
+ if (number instanceof Float || number instanceof Double) {
+ return Type.DOUBLE;
+ }
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public Type evaluate(UnaryOperation unaryOperation) {
+ infer(unaryOperation.getTarget());
+ UnaryOpGen opGen = Operators.generatorFor(unaryOperation.getOperator());
+ return opGen.returnType(infer(unaryOperation.getTarget()));
+ }
+
+ @Override
+ public Type evaluate(TernaryOperator ternaryOperator) {
+ infer(ternaryOperator.getCondition());
+ Type thenType = infer(ternaryOperator.getThenBranch());
+ Type elseType = infer(ternaryOperator.getElseBranch());
+ if (thenType.equals(elseType)) {
+ return thenType;
+ }
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public Type evaluate(RuntimeCall runtimeCall) {
+ inferAll(runtimeCall.getArguments());
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public Type evaluate(MapLiteral mapLiteral) {
+ inferAll(mapLiteral.getMap().values());
+ return Type.MAP;
+ }
+
+ @Override
+ public Type evaluate(ArrayLiteral arrayLiteral) {
+ inferAll(arrayLiteral.getItems());
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public Type evaluate(NullLiteral nullLiteral) {
+ return Type.UNKNOWN;
+ }
+
+ private void inferAll(Iterable<ExpressionNode> nodes) {
+ for (ExpressionNode node : nodes) {
+ infer(node);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInfo.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInfo.java
new file mode 100644
index 0000000..3d0ee13
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/TypeInfo.java
@@ -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.
+ ******************************************************************************/
+
+package org.apache.sling.scripting.sightly.java.compiler.impl;
+
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.operator.TypedNode;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+
+/**
+ * Provide type information for expressions
+ */
+public class TypeInfo {
+
+ private final Map<ExpressionNode, Type> typeMap;
+
+ public TypeInfo(Map<ExpressionNode, Type> typeMap) {
+ this.typeMap = typeMap;
+ }
+
+ public Type typeOf(ExpressionNode node) {
+ Type type = typeMap.get(node);
+ if (type == null) {
+ return Type.UNKNOWN;
+ }
+ return type;
+ }
+
+ public TypedNode getTyped(ExpressionNode expressionNode) {
+ return new TypedNode(expressionNode, typeOf(expressionNode));
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java
new file mode 100644
index 0000000..990bf8c
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/UnitBuilder.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.scripting.sightly.java.compiler.CompilationOutput;
+
+/**
+ * Builder for compiled sources
+ */
+public class UnitBuilder {
+
+ private final JavaSource source = new JavaSource();
+ private final Set<String> parameters;
+ private final Map<String, UnitBuilder> subTemplates = new HashMap<String, UnitBuilder>();
+
+ public UnitBuilder() {
+ this(Collections.<String>emptySet());
+ }
+
+ public UnitBuilder(Set<String> parameters) {
+ this.parameters = parameters;
+ }
+
+ public UnitBuilder newSubBuilder(String name, Set<String> parameters) {
+ UnitBuilder unitBuilder = new UnitBuilder(parameters);
+ subTemplates.put(name, unitBuilder);
+ return unitBuilder;
+ }
+
+ public JavaSource getSource() {
+ return source;
+ }
+
+ public Set<String> getParameters() {
+ return parameters;
+ }
+
+ public CompilationOutput build() {
+ Map<String, CompilationOutput> map = new HashMap<>();
+ for (Map.Entry<String, UnitBuilder> entry : subTemplates.entrySet()) {
+ map.put(entry.getKey(), entry.getValue().build());
+ }
+ return new CompilationOutputImpl(source.toString(), map);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java
new file mode 100644
index 0000000..80aa5c7
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableAnalyzer.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.sling.scripting.sightly.java.compiler.SightlyJavaCompilerException;
+import org.apache.sling.scripting.sightly.java.compiler.impl.utils.JavaEscapeUtils;
+import org.apache.sling.scripting.sightly.compiler.util.VariableTracker;
+
+/**
+ * Data structure used in the analysis of variables
+ * during the compilation process
+ */
+public class VariableAnalyzer {
+
+ private final VariableTracker<VariableDescriptor> tracker = new VariableTracker<>();
+ private final List<VariableDescriptor> variables = new ArrayList<>();
+ private final HashMap<String, VariableDescriptor> dynamicVariables = new HashMap<>();
+ private final HashMap<String, VariableDescriptor> staticVariables = new HashMap<>();
+ private static final String DYNAMIC_PREFIX = "_dynamic_";
+ private static final String GLOBAL_PREFIX = "_global_";
+
+ /**
+ * Mark the declaration of a variable in the Java code
+ * @param originalName the original name of the variable
+ * @param type the variable's type
+ * @return - a variable descriptor uniquely assigned to this variable
+ */
+ public VariableDescriptor declareVariable(String originalName, Type type) {
+ originalName = originalName.toLowerCase();
+ String assignedName = findSafeName(originalName);
+ VariableDescriptor descriptor = new VariableDescriptor(originalName, assignedName, type, VariableScope.SCOPED);
+ tracker.pushVariable(originalName, descriptor);
+ variables.add(descriptor);
+ return descriptor;
+ }
+
+ /**
+ * Declare a global variable. Redundant declarations are ignored
+ * @param originalName the original name of the variable
+ * @return a variable descriptor
+ */
+ public VariableDescriptor declareGlobal(String originalName) {
+ originalName = originalName.toLowerCase();
+ VariableDescriptor descriptor = staticVariables.get(originalName);
+ if (descriptor == null) {
+ String assignedName = findGlobalName(originalName);
+ descriptor = new VariableDescriptor(originalName, assignedName, Type.UNKNOWN, VariableScope.GLOBAL);
+ variables.add(descriptor);
+ staticVariables.put(originalName, descriptor);
+ }
+ return descriptor;
+ }
+
+ /**
+ * Mark this variable as a template
+ * @param originalName the original name of the variable
+ * @return a variable descriptor
+ */
+ public VariableDescriptor declareTemplate(String originalName) {
+ originalName = originalName.toLowerCase();
+ VariableDescriptor descriptor = dynamicDescriptor(originalName);
+ descriptor.markAsTemplate();
+ return descriptor;
+ }
+
+ /**
+ * Mark the end of a variable scope
+ */
+ public VariableDescriptor endVariable() {
+ VariableDescriptor descriptor = tracker.peek().getValue();
+ tracker.popVariable();
+ return descriptor;
+ }
+
+ /**
+ * Get a the descriptor for the given variable
+ * @param name the original lowerName of the variable
+ * @return the variable descriptor. If the variable is not in scope,
+ * then a dynamic variable descriptor is provided
+ */
+ public VariableDescriptor descriptor(String name) {
+ String lowerName = name.toLowerCase();
+ VariableDescriptor descriptor = tracker.get(lowerName);
+ if (descriptor == null) {
+ descriptor = staticVariables.get(lowerName);
+ }
+ if (descriptor == null) {
+ descriptor = dynamicDescriptor(lowerName);
+ }
+ return descriptor;
+ }
+
+ /**
+ * Get the collection of all the variables encountered so far
+ * @return an unmodifiable list of all the variables tracked by this analyzer
+ */
+ public Collection<VariableDescriptor> allVariables() {
+ return Collections.unmodifiableList(variables);
+ }
+
+ /**
+ * Shortcut method that returns the assigned name for the given
+ * variable
+ * @param original the original variable name
+ * @return the assigned name for this compilation process
+ */
+ public String assignedName(String original) {
+ return descriptor(original).getAssignedName();
+ }
+
+ private VariableDescriptor dynamicDescriptor(String original) {
+ VariableDescriptor descriptor = dynamicVariables.get(original);
+ if (descriptor == null) {
+ String dynamicName = findDynamicName(validName(original));
+ descriptor = new VariableDescriptor(original, dynamicName, Type.UNKNOWN, VariableScope.DYNAMIC);
+ dynamicVariables.put(original, descriptor);
+ variables.add(descriptor);
+ }
+ return descriptor;
+ }
+
+ private String findDynamicName(String original) {
+ return DYNAMIC_PREFIX + JavaEscapeUtils.getEscapedToken(original);
+ }
+
+ private String findGlobalName(String original) {
+ return GLOBAL_PREFIX + JavaEscapeUtils.getEscapedToken(original);
+ }
+
+ private String findSafeName(String original) {
+ int occurrenceCount = tracker.getOccurrenceCount(original);
+ String syntaxSafe = JavaEscapeUtils.getEscapedToken(original);
+ if (occurrenceCount == 0) {
+ return syntaxSafe; //no other declarations in scope. Use this very name
+ } else {
+ return original + "_" + occurrenceCount;
+ }
+ }
+
+ private String validName(String name) {
+ if (name == null || name.contains("-")) {
+ throw new SightlyJavaCompilerException("Unsupported identifier name: " + name);
+ }
+ return name.toLowerCase();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java
new file mode 100644
index 0000000..51193d6
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableDescriptor.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.java.compiler.impl;
+
+/**
+ * Information about a variable during the compilation process
+ */
+public class VariableDescriptor {
+
+ private final String originalName;
+ private final String assignedName;
+ private VariableScope scope;
+ private String listCoercion;
+ private final Type type;
+ private boolean templateVariable;
+
+ public VariableDescriptor(String originalName, String assignedName, Type type, VariableScope scope) {
+ this.originalName = originalName;
+ this.assignedName = assignedName;
+ this.scope = scope;
+ this.type = type;
+ }
+
+ /**
+ * The name of the list coercion variable
+ * @return - the variable that will hold the list coercion
+ */
+ public String requireListCoercion() {
+ if (listCoercion == null) {
+ listCoercion = assignedName + "_list_coerced$";
+ }
+ return listCoercion;
+ }
+
+ public String getListCoercion() {
+ return listCoercion;
+ }
+
+ /**
+ * Get the original name of the variable, as it was provided
+ * by the command that introduced the variable
+ * @return - the original variable name
+ */
+ public String getOriginalName() {
+ return originalName;
+ }
+
+ /**
+ * Get the assigned name for the variable - the name that will
+ * actually be used during compilation
+ * @return - the assigned variable name
+ */
+ public String getAssignedName() {
+ return assignedName;
+ }
+
+ /**
+ * Get the scope of this variable
+ * @return the variable scope
+ */
+ public VariableScope getScope() {
+ return scope;
+ }
+
+ /**
+ * Get the inferred type fot this variable
+ * @return - the class of the variable
+ */
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * Check whether this is a template variable
+ * @return true if it is a template variable
+ */
+ public boolean isTemplateVariable() {
+ return templateVariable;
+ }
+
+ /**
+ * Signal that this variable stands for a template
+ */
+ public void markAsTemplate() {
+ if (scope != VariableScope.DYNAMIC) {
+ throw new UnsupportedOperationException("Only dynamic variables can be marked as templates");
+ }
+ templateVariable = true;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java
new file mode 100644
index 0000000..9b34322
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/VariableScope.java
@@ -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 org.apache.sling.scripting.sightly.java.compiler.impl;
+
+/**
+ * The scope of a variable in a Sightly script
+ */
+public enum VariableScope {
+ DYNAMIC, SCOPED, GLOBAL
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/BinaryOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/BinaryOpGen.java
new file mode 100644
index 0000000..3fc0d90
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/BinaryOpGen.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for a binary operator
+ */
+public interface BinaryOpGen {
+
+ Type returnType(Type leftType, Type rightType);
+
+ void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right);
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ComparisonOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ComparisonOpGen.java
new file mode 100644
index 0000000..9590c6e
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ComparisonOpGen.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator;
+
+/**
+ * Generator for logical operators
+ */
+public class ComparisonOpGen implements BinaryOpGen {
+
+ private final String javaOperator;
+ private final boolean inverted;
+ private final String runtimeMethod;
+
+ private static final String METHOD_LEQ = "leq";
+ private static final String METHOD_LT = "lt";
+
+ private static final String OBJECT_NAME = BinaryOperator.class.getName();
+
+ public ComparisonOpGen(BinaryOperator operator) {
+ switch (operator) {
+ case LT: runtimeMethod = METHOD_LT; inverted = false; javaOperator = "<"; break;
+ case GT: runtimeMethod = METHOD_LEQ; inverted = true; javaOperator = ">"; break;
+ case LEQ: runtimeMethod = METHOD_LEQ; inverted = false; javaOperator = "<="; break;
+ case GEQ: runtimeMethod = METHOD_LT; inverted = true; javaOperator = ">="; break;
+ default: throw new IllegalArgumentException("Operator is not a comparison operator: " + operator);
+ }
+ }
+
+ @Override
+ public Type returnType(Type left, Type right) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ Type type = OpHelper.sameType(left, right);
+ if (OpHelper.isNumericType(type)) {
+ generateWithOperator(source, visitor, left.getNode(), right.getNode());
+ } else {
+ generateGeneric(source, visitor, left.getNode(), right.getNode());
+ }
+ }
+
+ private void generateGeneric(JavaSource source, SideEffectVisitor visitor, ExpressionNode leftNode, ExpressionNode rightNode) {
+ if (inverted) {
+ source.negation().startExpression();
+ }
+ source.startMethodCall(OBJECT_NAME, runtimeMethod);
+ leftNode.accept(visitor);
+ source.separateArgument();
+ rightNode.accept(visitor);
+ source.endCall();
+ if (inverted) {
+ source.endExpression();
+ }
+ }
+
+ private void generateWithOperator(JavaSource source, SideEffectVisitor visitor,
+ ExpressionNode leftNode, ExpressionNode rightNode) {
+ leftNode.accept(visitor);
+ source.append(javaOperator);
+ rightNode.accept(visitor);
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ConcatenateOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ConcatenateOpGen.java
new file mode 100644
index 0000000..0470037
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/ConcatenateOpGen.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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Concatenation operator generation
+ */
+public final class ConcatenateOpGen implements BinaryOpGen {
+
+ public static final ConcatenateOpGen INSTANCE = new ConcatenateOpGen();
+
+ private ConcatenateOpGen() {
+ }
+
+ @Override
+ public Type returnType(Type leftType, Type rightType) {
+ return Type.STRING;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ GenHelper.typeCoercion(source, visitor, left, Type.STRING);
+ source.append("+");
+ GenHelper.typeCoercion(source, visitor, right, Type.STRING);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/EquivalenceOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/EquivalenceOpGen.java
new file mode 100644
index 0000000..33aa34d
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/EquivalenceOpGen.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+
+/**
+ * Generator for logical operators
+ */
+public class EquivalenceOpGen implements BinaryOpGen {
+
+ private final boolean negated;
+
+ public EquivalenceOpGen(boolean negated) {
+ this.negated = negated;
+ }
+
+ @Override
+ public Type returnType(Type left, Type right) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ Type type = OpHelper.sameType(left, right);
+ if (type != null && OpHelper.isNumericType(type) || type == Type.BOOLEAN || type == Type.UNKNOWN) {
+ generateEqualsOperator(source, visitor, left.getNode(), right.getNode());
+ } else if (type != Type.UNKNOWN) {
+ generateEqualsMethod(source, visitor, left, right);
+ }
+ }
+
+ private void generateCheckedEquals(JavaSource source, SideEffectVisitor visitor, TypedNode leftNode, TypedNode rightNode) {
+ source.startExpression();
+ leftNode.getNode().accept(visitor);
+ source.equality().nullLiteral().conditional();
+ rightNode.getNode().accept(visitor);
+ source.equality().nullLiteral();
+ source.conditionalBranchSep();
+ generateEqualsMethod(source, visitor, leftNode, rightNode);
+ source.endExpression();
+ }
+
+ private void generateEqualsMethod(JavaSource source, SideEffectVisitor visitor, TypedNode leftNode, TypedNode rightNode) {
+ boolean performCast = leftNode.getType().isPrimitive();
+ if (performCast) {
+ source.startExpression();
+ source.cast(Type.UNKNOWN.getNativeClass());
+ }
+ leftNode.getNode().accept(visitor);
+ if (performCast) {
+ source.endExpression();
+ }
+ source.startCall("equals", true);
+ rightNode.getNode().accept(visitor);
+ source.endCall();
+ }
+
+ private void generateEqualsOperator(JavaSource source, SideEffectVisitor visitor, ExpressionNode leftNode, ExpressionNode rightNode) {
+ leftNode.accept(visitor);
+ source.append(operator());
+ rightNode.accept(visitor);
+ }
+
+ private String operator() {
+ return (negated) ? "!=" : "==";
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/IsWhiteSpaceGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/IsWhiteSpaceGen.java
new file mode 100644
index 0000000..0be2035
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/IsWhiteSpaceGen.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.SourceGenConstants;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for IS_WHITESPACE operator
+ */
+public final class IsWhiteSpaceGen implements UnaryOpGen {
+
+ public static final IsWhiteSpaceGen INSTANCE = new IsWhiteSpaceGen();
+
+ private IsWhiteSpaceGen() {
+ }
+
+ @Override
+ public Type returnType(Type operandType) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode typedNode) {
+ GenHelper.typeCoercion(source, visitor, typedNode, Type.STRING);
+ source.startCall(SourceGenConstants.TRIM_METHOD, true)
+ .endCall()
+ .startCall(SourceGenConstants.STRING_EMPTY, true)
+ .endCall();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LengthOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LengthOpGen.java
new file mode 100644
index 0000000..35f2cf6
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LengthOpGen.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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.SourceGenConstants;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for the collection length operator
+ */
+public final class LengthOpGen implements UnaryOpGen {
+
+ public static final LengthOpGen INSTANCE = new LengthOpGen();
+
+ private LengthOpGen() {
+ }
+
+ @Override
+ public Type returnType(Type operandType) {
+ return Type.LONG;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode typedNode) {
+ GenHelper.listCoercion(source, visitor, typedNode);
+ source.startCall(SourceGenConstants.COLLECTION_LENGTH_METHOD, true).endCall();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LogicalOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LogicalOpGen.java
new file mode 100644
index 0000000..328175b
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LogicalOpGen.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.compiler.expression.SideEffectVisitor;
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+
+/**
+ * Generator for logical operators
+ */
+public abstract class LogicalOpGen implements BinaryOpGen {
+
+ private final String javaOperator;
+
+ protected LogicalOpGen(String javaOperator) {
+ this.javaOperator = javaOperator;
+ }
+
+ public static final LogicalOpGen AND = new LogicalOpGen("&&") {
+ @Override
+ protected void generateGeneric(JavaSource source, SideEffectVisitor visitor, TypedNode left, TypedNode right) {
+ GenHelper.generateTernary(source, visitor, left, right, left);
+ }
+ };
+
+ public static final LogicalOpGen OR = new LogicalOpGen("||") {
+ @Override
+ protected void generateGeneric(JavaSource source, SideEffectVisitor visitor, TypedNode left, TypedNode right) {
+ GenHelper.generateTernary(source, visitor, left, left, right);
+ }
+ };
+
+ @Override
+ public Type returnType(Type leftType, Type rightType) {
+ if (leftType == rightType) {
+ return leftType;
+ }
+ return Type.UNKNOWN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ if (OpHelper.sameType(left, right) == Type.BOOLEAN) {
+ generateWithOperator(source, visitor, left.getNode(), right.getNode());
+ } else {
+ generateGeneric(source, visitor, left, right);
+ }
+ }
+
+ protected abstract void generateGeneric(JavaSource source, SideEffectVisitor visitor,
+ TypedNode left, TypedNode right);
+
+ private void generateWithOperator(JavaSource source, SideEffectVisitor visitor,
+ ExpressionNode leftNode, ExpressionNode rightNode) {
+ leftNode.accept(visitor);
+ source.append(javaOperator);
+ rightNode.accept(visitor);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LongOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LongOpGen.java
new file mode 100644
index 0000000..a2b2502
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/LongOpGen.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for long numeric operators
+ */
+public class LongOpGen extends NumericOpGen {
+
+ public LongOpGen(String javaOperator) {
+ super(javaOperator);
+ }
+
+ @Override
+ protected Type commonType(Type leftType, Type rightType) {
+ return Type.LONG;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NotOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NotOpGen.java
new file mode 100644
index 0000000..a9ec52a
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NotOpGen.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for the not operator
+ */
+public final class NotOpGen implements UnaryOpGen {
+
+ public static final NotOpGen INSTANCE = new NotOpGen();
+
+ private NotOpGen() {
+ }
+
+ @Override
+ public Type returnType(Type operandType) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode typedNode) {
+ source.negation();
+ GenHelper.typeCoercion(source, visitor, typedNode, Type.BOOLEAN);
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NumericOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NumericOpGen.java
new file mode 100644
index 0000000..120b2b2
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/NumericOpGen.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.GenHelper;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Generator for numeric value
+ */
+public class NumericOpGen implements BinaryOpGen {
+
+ private final String javaOperator;
+
+ public NumericOpGen(String javaOperator) {
+ this.javaOperator = javaOperator;
+ }
+
+ @Override
+ public Type returnType(Type leftType, Type rightType) {
+ return commonType(leftType, rightType);
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ Type commonType = commonType(left.getType(), right.getType());
+ GenHelper.typeCoercion(source, visitor, left, commonType);
+ source.append(javaOperator);
+ GenHelper.typeCoercion(source, visitor, right, commonType);
+ }
+
+ protected Type commonType(Type leftType, Type rightType) {
+ if (leftType == rightType && leftType == Type.LONG) {
+ return Type.LONG;
+ }
+ return Type.DOUBLE;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/OpHelper.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/OpHelper.java
new file mode 100644
index 0000000..ba90dce
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/OpHelper.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Helper class for operator generation
+ */
+public class OpHelper {
+
+ public static Type sameType(TypedNode left, TypedNode right) {
+ if (left.getType().equals(right.getType())) {
+ return left.getType();
+ }
+ return null;
+ }
+
+ public static boolean isNumericType(Type type) {
+ return type == Type.LONG || type == Type.DOUBLE;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/Operators.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/Operators.java
new file mode 100644
index 0000000..a90e332
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/Operators.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.UnaryOperator;
+
+/**
+ * Provides mappings from operators to generators
+ */
+public class Operators {
+ private static final Map<BinaryOperator, BinaryOpGen> representationMap =
+ new EnumMap<BinaryOperator, BinaryOpGen>(BinaryOperator.class);
+
+ private static final Map<UnaryOperator, UnaryOpGen> unaryMapping =
+ new EnumMap<UnaryOperator, UnaryOpGen>(UnaryOperator.class);
+
+ static {
+ representationMap.put(BinaryOperator.AND, LogicalOpGen.AND);
+ representationMap.put(BinaryOperator.OR, LogicalOpGen.OR);
+ representationMap.put(BinaryOperator.CONCATENATE, ConcatenateOpGen.INSTANCE);
+ representationMap.put(BinaryOperator.ADD, new NumericOpGen("+"));
+ representationMap.put(BinaryOperator.SUB, new NumericOpGen("-"));
+ representationMap.put(BinaryOperator.MUL, new NumericOpGen("*"));
+ representationMap.put(BinaryOperator.I_DIV, new LongOpGen("/"));
+ representationMap.put(BinaryOperator.REM, new LongOpGen("%"));
+ representationMap.put(BinaryOperator.DIV, new NumericOpGen("/"));
+ representationMap.put(BinaryOperator.EQ, new EquivalenceOpGen(false));
+ representationMap.put(BinaryOperator.NEQ, new EquivalenceOpGen(true));
+ representationMap.put(BinaryOperator.LT, new ComparisonOpGen(BinaryOperator.LT));
+ representationMap.put(BinaryOperator.LEQ, new ComparisonOpGen(BinaryOperator.LEQ));
+ representationMap.put(BinaryOperator.GT, new ComparisonOpGen(BinaryOperator.GT));
+ representationMap.put(BinaryOperator.GEQ, new ComparisonOpGen(BinaryOperator.GEQ));
+ representationMap.put(BinaryOperator.STRICT_EQ, new StrictEqGenOp(false));
+ representationMap.put(BinaryOperator.STRICT_NEQ, new StrictEqGenOp(true));
+
+ unaryMapping.put(UnaryOperator.LENGTH, LengthOpGen.INSTANCE);
+ unaryMapping.put(UnaryOperator.IS_WHITESPACE, IsWhiteSpaceGen.INSTANCE);
+ unaryMapping.put(UnaryOperator.NOT, NotOpGen.INSTANCE);
+ }
+
+
+ /**
+ * Provide the signature of the given operator
+ * @param operator - the operator
+ * @return - the signature for the operator
+ */
+ public static BinaryOpGen generatorFor(BinaryOperator operator) {
+ return provide(representationMap, operator);
+ }
+
+ /**
+ * Provide the signature of the given operator
+ * @param operator - the operator
+ * @return - the signature for the operator
+ */
+ public static UnaryOpGen generatorFor(UnaryOperator operator) {
+ return provide(unaryMapping, operator);
+ }
+
+ private static <K, V> V provide(Map<K, V> map, K key) {
+ V v = map.get(key);
+ if (v == null) {
+ throw new UnsupportedOperationException("Cannot find generator for operator: " + key);
+ }
+ return v;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/StrictEqGenOp.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/StrictEqGenOp.java
new file mode 100644
index 0000000..f024f7b
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/StrictEqGenOp.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+import org.apache.sling.scripting.sightly.compiler.expression.nodes.BinaryOperator;
+
+/**
+ * Generator for strict equality
+ */
+public class StrictEqGenOp implements BinaryOpGen {
+
+ private final boolean negated;
+ private static final String OBJECT_NAME = BinaryOperator.class.getName();
+ private static final String METHOD_STRICT_EQ = "strictEq";
+
+ public StrictEqGenOp(boolean negated) {
+ this.negated = negated;
+ }
+
+ @Override
+ public Type returnType(Type leftType, Type rightType) {
+ return Type.BOOLEAN;
+ }
+
+ @Override
+ public void generate(JavaSource source, ExpressionTranslator visitor, TypedNode left, TypedNode right) {
+ if (negated) {
+ source.negation();
+ }
+ source.startMethodCall(OBJECT_NAME, METHOD_STRICT_EQ);
+ left.getNode().accept(visitor);
+ source.separateArgument();
+ right.getNode().accept(visitor);
+ source.endCall();
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/TypedNode.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/TypedNode.java
new file mode 100644
index 0000000..0b27fa7
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/TypedNode.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+import org.apache.sling.scripting.sightly.compiler.expression.ExpressionNode;
+
+/**
+ * Expression nodes with type information
+ */
+public class TypedNode {
+ private final ExpressionNode node;
+ private final Type type;
+
+ public TypedNode(ExpressionNode node, Type type) {
+ this.node = node;
+ this.type = type;
+ }
+
+ public ExpressionNode getNode() {
+ return node;
+ }
+
+ public Type getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java
new file mode 100644
index 0000000..0cfa9ee
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.operator;
+
+import org.apache.sling.scripting.sightly.java.compiler.impl.ExpressionTranslator;
+import org.apache.sling.scripting.sightly.java.compiler.impl.JavaSource;
+import org.apache.sling.scripting.sightly.java.compiler.impl.Type;
+
+/**
+ * Interface for generators of unary operators
+ */
+public interface UnaryOpGen {
+
+ Type returnType(Type operandType);
+
+ void generate(JavaSource source, ExpressionTranslator visitor, TypedNode typedNode);
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java
new file mode 100644
index 0000000..91c10af
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.java.compiler.impl.utils;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The {@code JavaEscapeUtils} provides useful methods for escaping or transforming invalid Java tokens to valid ones that could be used in
+ * generated Java source code.
+ */
+public class JavaEscapeUtils {
+
+ private static final Set<String> reservedKeywords = new HashSet<String>() {{
+ add("abstract");
+ add("assert");
+ add("boolean");
+ add("break");
+ add("byte");
+ add("case");
+ add("catch");
+ add("char");
+ add("class");
+ add("const");
+ add("continue");
+ add("default");
+ add("do");
+ add("double");
+ add("else");
+ add("enum");
+ add("extends");
+ add("final");
+ add("finally");
+ add("float");
+ add("for");
+ add("goto");
+ add("if");
+ add("implements");
+ add("import");
+ add("instanceof");
+ add("int");
+ add("interface");
+ add("long");
+ add("native");
+ add("new");
+ add("package");
+ add("private");
+ add("protected");
+ add("public");
+ add("return");
+ add("short");
+ add("static");
+ add("strictfp");
+ add("super");
+ add("switch");
+ add("synchronized");
+ add("this");
+ add("throw");
+ add("throws");
+ add("transient");
+ add("try");
+ add("void");
+ add("volatile");
+ add("while");
+ }};
+
+ /**
+ * Escapes and / or transforms an invalid token (in case the token represents a reserved Java keyword) to provide a valid token.
+ *
+ * @param token the token to be transformed
+ * @return a valid Java token
+ */
+ public static String getEscapedToken(String token) {
+ String result = token;
+ if (reservedKeywords.contains(result)) {
+ result = "_" + result;
+ }
+ return result.replaceAll("-", "_");
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
new file mode 100644
index 0000000..dc548d9
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.java.compiler;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
new file mode 100644
index 0000000..dacd4c5
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/package-info.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * 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;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
new file mode 100644
index 0000000..48943f3
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java
@@ -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.
+ ******************************************************************************/
+package org.apache.sling.scripting.sightly.pojo;
+
+import javax.script.Bindings;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * The <code>Use</code> interface can be implemented by Java objects which are instantiated as part of processing {@code data-sly-use}
+ * attributes.
+ *
+ * @see <a href="https://github.com/Adobe-Marketing-Cloud/sightly-spec/blob/master/SPECIFICATION.md#221-use">Sightly Block Statements - Use</a>
+ */
+@ConsumerType
+public interface Use {
+
+ /**
+ * <p>
+ * Called to initialize the Java object with the current Java Scripting API bindings.
+ * </p>
+ * <p/>
+ * This method is called only if the object has been instantiated by Sightly as part of processing the {@code data-sly-use}
+ * attribute. The Java Scripting API bindings provide all the global variables known to a script being executed.
+ * <p/>
+ *
+ * @param bindings The Java Scripting API bindings.
+ */
+ void init(Bindings bindings);
+
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java
new file mode 100644
index 0000000..f795d12
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/pojo/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.pojo;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
new file mode 100644
index 0000000..aa42104
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -0,0 +1,369 @@
+/*******************************************************************************
+ * 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.render;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sling.scripting.sightly.Record;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default abstract implementation of {@link RuntimeObjectModel}.
+ */
+public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRuntimeObjectModel.class);
+
+ /**
+ * A {@link Set} that stores all the supported primitive classes.
+ */
+ public static final Set<Class<?>> PRIMITIVE_CLASSES = Collections.unmodifiableSet(new HashSet<Class<?>>() {{
+ add(Boolean.class);
+ add(Boolean.class);
+ add(Character.class);
+ add(Byte.class);
+ add(Short.class);
+ add(Integer.class);
+ add(Long.class);
+ add(Float.class);
+ add(Double.class);
+ add(Void.class);
+ }});
+
+ public static final String TO_STRING_METHOD = "toString";
+
+ @Override
+ public boolean isPrimitive(Object obj) {
+ return PRIMITIVE_CLASSES.contains(obj.getClass());
+ }
+
+ @Override
+ public boolean isCollection(Object target) {
+ return (target instanceof Collection) || (target instanceof Object[]) || (target instanceof Iterable) ||
+ (target instanceof Iterator);
+ }
+
+ @Override
+ public Object resolveProperty(Object target, Object property) {
+ Object resolved;
+ if (property instanceof Number) {
+ resolved = getIndex(target, ((Number) property).intValue());
+ } else {
+ resolved = getProperty(target, property);
+ }
+ return resolved;
+ }
+
+ @Override
+ public boolean toBoolean(Object object) {
+ return toBooleanInternal(object);
+ }
+
+ @Override
+ public Number toNumber(Object object) {
+ if (object instanceof Number) {
+ return (Number) object;
+ }
+ return 0;
+ }
+
+ @Override
+ public String toString(Object target) {
+ return objectToString(target);
+ }
+
+ @Override
+ public Collection<Object> toCollection(Object object) {
+ return obtainCollection(object);
+ }
+
+ @Override
+ public Map toMap(Object object) {
+ if (object instanceof Map) {
+ return (Map) object;
+ } else if (object instanceof Record) {
+ Map<String, Object> map = new HashMap<>();
+ Record record = (Record) object;
+ @SuppressWarnings("unchecked")
+ Set<String> properties = record.getPropertyNames();
+ for (String property : properties) {
+ map.put(property, record.getProperty(property));
+ }
+ return map;
+ }
+ return Collections.emptyMap();
+ }
+
+ protected String objectToString(Object obj) {
+ String output = "";
+ if (obj != null) {
+ if (obj instanceof String) {
+ output = (String) obj;
+ } else if (isPrimitive(obj)) {
+ output = obj.toString();
+ } else {
+ Collection<?> col = obtainCollection(obj);
+ if (col != null) {
+ output = collectionToString(col);
+ }
+ }
+ }
+ return output;
+ }
+
+ protected Object getProperty(Object target, Object propertyObj) {
+ String property = toString(propertyObj);
+ if (StringUtils.isEmpty(property)) {
+ throw new IllegalArgumentException("Invalid property name");
+ }
+ if (target == null) {
+ return null;
+ }
+ Object result = null;
+ if (target instanceof Map) {
+ result = getMapProperty((Map) target, property);
+ }
+ if (result == null && target instanceof Record) {
+ result = ((Record) target).getProperty(property);
+ }
+ if (result == null) {
+ result = getObjectProperty(target, property);
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Collection<Object> obtainCollection(Object obj) {
+ if (obj == null) {
+ return Collections.emptyList();
+ }
+ if (obj instanceof Object[]) {
+ return Arrays.asList((Object[]) obj);
+ }
+ if (obj instanceof Collection) {
+ return (Collection<Object>) obj;
+ }
+ if (obj instanceof Map) {
+ return ((Map) obj).keySet();
+ }
+ if (obj instanceof Record) {
+ return ((Record) obj).getPropertyNames();
+ }
+ if (obj instanceof Enumeration) {
+ return Collections.list((Enumeration<Object>) obj);
+ }
+ if (obj instanceof Iterator) {
+ return fromIterator((Iterator<Object>) obj);
+ }
+ if (obj instanceof Iterable) {
+ Iterable iterable = (Iterable) obj;
+ return fromIterator(iterable.iterator());
+ }
+ if (obj instanceof String || obj instanceof Number) {
+ Collection list = new ArrayList();
+ list.add(obj);
+ return list;
+ }
+ return Collections.emptyList();
+ }
+
+ protected String collectionToString(Collection<?> col) {
+ StringBuilder builder = new StringBuilder();
+ String prefix = "";
+ for (Object o : col) {
+ builder.append(prefix).append(objectToString(o));
+ prefix = ",";
+ }
+ return builder.toString();
+ }
+
+ protected Collection<Object> fromIterator(Iterator<Object> iterator) {
+ ArrayList<Object> result = new ArrayList<>();
+ while (iterator.hasNext()) {
+ result.add(iterator.next());
+ }
+ return result;
+ }
+
+ protected boolean toBooleanInternal(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ if (obj instanceof Number) {
+ Number number = (Number) obj;
+ return !(number.doubleValue() == 0.0);
+ }
+
+ String s = obj.toString().trim();
+ if ("".equals(s)) {
+ return false;
+ } else if ("true".equalsIgnoreCase(s) || "false".equalsIgnoreCase(s)) {
+ return Boolean.parseBoolean(s);
+ }
+
+ if (obj instanceof Collection) {
+ return ((Collection) obj).size() > 0;
+ }
+
+ if (obj instanceof Map) {
+ return ((Map) obj).size() > 0;
+ }
+
+ if (obj instanceof Iterable<?>) {
+ return ((Iterable<?>) obj).iterator().hasNext();
+ }
+
+ if (obj instanceof Iterator<?>) {
+ return ((Iterator<?>) obj).hasNext();
+ }
+
+ return !(obj instanceof Object[]) || ((Object[]) obj).length > 0;
+ }
+
+ protected Object getIndex(Object obj, int index) {
+ if (obj instanceof Map) {
+ Map map = (Map) obj;
+ if (map.containsKey(index)) {
+ return map.get(index);
+ }
+ }
+ Collection collection = toCollection(obj);
+ if (collection instanceof List) {
+ return getIndexSafe((List) collection, index);
+ }
+ return null;
+ }
+
+ protected Object getIndexSafe(List list, int index) {
+ if (index < 0 || index >= list.size()) {
+ return null;
+ }
+ return list.get(index);
+ }
+
+ protected Object getMapProperty(Map map, String property) {
+ return map.get(property);
+ }
+
+ protected Object getObjectProperty(Object obj, String property) {
+ Object result = getObjectNoArgMethod(obj, property);
+ if (result == null) {
+ result = getField(obj, property);
+ }
+ return result;
+ }
+
+ protected static Object getField(Object obj, String property) {
+ if (obj instanceof Object[] && "length".equals(property)) {
+ // Working around this limitation: http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getFields%28%29
+ return ((Object[]) obj).length;
+ }
+ Class<?> cls = obj.getClass();
+ try {
+ Field field = cls.getDeclaredField(property);
+ return field.get(obj);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ protected Object getObjectNoArgMethod(Object obj, String property) {
+ Class<?> cls = obj.getClass();
+ Method method = findMethod(cls, property);
+ if (method != null) {
+ method = extractMethodInheritanceChain(cls, method);
+ try {
+ return method.invoke(obj);
+ } catch (Exception e) {
+ LOGGER.error("Cannot access method " + property + " on object " + obj.toString(), e);
+ }
+ }
+ return null;
+ }
+
+ protected static Method findMethod(Class<?> cls, String baseName) {
+ Method[] publicMethods = cls.getMethods();
+ String capitalized = StringUtils.capitalize(baseName);
+ for (Method m : publicMethods) {
+ if (m.getParameterTypes().length == 0) {
+ String methodName = m.getName();
+ if (baseName.equals(methodName) || ("get" + capitalized).equals(methodName) || ("is" + capitalized).equals(methodName)) {
+ // this method is good, check whether allowed
+ if (isMethodAllowed(m)) {
+ return m;
+ }
+ // method would match but is not allowed, abort
+ break;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected static boolean isMethodAllowed(Method method) {
+ Class<?> declaringClass = method.getDeclaringClass();
+ //methods of the Object.class are forbidden (except toString, which is allowed)
+ return declaringClass != Object.class || TO_STRING_METHOD.equals(method.getName());
+ }
+
+ protected Method extractMethodInheritanceChain(Class type, Method m) {
+ if (m == null || Modifier.isPublic(type.getModifiers())) {
+ return m;
+ }
+ Class[] iFaces = type.getInterfaces();
+ Method mp;
+ for (Class<?> iFace : iFaces) {
+ mp = getClassMethod(iFace, m);
+ if (mp != null) {
+ return mp;
+ }
+ }
+ return getClassMethod(type.getSuperclass(), m);
+ }
+
+ protected Method getClassMethod(Class<?> clazz, Method m) {
+ Method mp;
+ try {
+ mp = clazz.getMethod(m.getName(), m.getParameterTypes());
+ mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp);
+ if (mp != null) {
+ return mp;
+ }
+ } catch (NoSuchMethodException e) {
+ // do nothing
+ }
+ return null;
+ }
+
+}
+
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
new file mode 100644
index 0000000..bb06812
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.render;
+
+import javax.script.Bindings;
+
+import org.apache.sling.scripting.sightly.extension.RuntimeExtension;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The {@code RenderContext} defines the context for executing Sightly scripts.
+ */
+@ProviderType
+public interface RenderContext {
+
+ /**
+ * Provides the {@link RuntimeObjectModel} that will be used for resolving objects' properties or type conversion / coercion.
+ *
+ * @return the RuntimeObjectModel
+ */
+ RuntimeObjectModel getObjectModel();
+
+ /**
+ * Returns the map of script bindings available to Sightly scripts.
+ *
+ * @return the global bindings for a script
+ */
+ Bindings getBindings();
+
+ /**
+ * Call one of the registered {@link RuntimeExtension}s.
+ *
+ * @param functionName the name under which the extension is registered
+ * @param arguments the extension's arguments
+ * @return the {@link RuntimeExtension}'s result
+ */
+ Object call(String functionName, Object... arguments);
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
new file mode 100644
index 0000000..f45a8e9
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.render;
+
+import java.util.Collection;
+import java.util.Map;
+
+import aQute.bnd.annotation.ProviderType;
+
+/**
+ * The {@code RuntimeObjectModel} provides various utility object inspection & conversion methods that can be applied to runtime
+ * objects when executing Sightly scripts.
+ */
+@ProviderType
+public interface RuntimeObjectModel {
+
+ /**
+ * Checks if the provided object represents a primitive data type or not.
+ *
+ * @param obj the target object
+ * @return {@code true} if the {@code target} is a primitive, {@code false} otherwise
+ */
+ boolean isPrimitive(Object obj);
+
+ /**
+ * Checks if an object is a {@link Collection} or is backed by one.
+ *
+ * @param target the target object
+ * @return {@code true} if the {@code target} is a collection or is backed by one, {@code false} otherwise
+ */
+ boolean isCollection(Object target);
+
+ /**
+ * Resolve a property of a target object and return its value. The property can
+ * be either an index or a name
+ *
+ * @param target the target object
+ * @param property the property to be resolved
+ * @return the value of the property
+ */
+ Object resolveProperty(Object target, Object property);
+
+ /**
+ * Convert the given object to a boolean value
+ *
+ * @param object the target object
+ * @return the boolean representation of that object
+ */
+ boolean toBoolean(Object object);
+
+ /**
+ * Coerce the object to a numeric value
+ *
+ * @param object the target object
+ * @return the numeric representation
+ */
+ Number toNumber(Object object);
+
+ /**
+ * Convert the given object to a string.
+ *
+ * @param target the target object
+ * @return the string representation of the object
+ */
+ String toString(Object target);
+
+ /**
+ * Force the conversion of the object to a collection
+ *
+ * @param object the target object
+ * @return the collection representation of the object
+ */
+ Collection<Object> toCollection(Object object);
+
+ /**
+ * Force the conversion of the target object to a map
+ *
+ * @param object the target object
+ * @return a map representation of the object. Default is an empty map
+ */
+ Map toMap(Object object);
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
new file mode 100644
index 0000000..85ac73d
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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("2.0.0")
+package org.apache.sling.scripting.sightly.render;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java b/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java
new file mode 100644
index 0000000..83fb379
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * 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.use;
+
+/**
+ * Result returned by a {@link UseProvider}.
+ */
+public final class ProviderOutcome {
+
+ // a generic failure without a cause returned by #failure()
+ private static final ProviderOutcome GENERIC_FAILURE = new ProviderOutcome(false, null, null);
+
+ // whether this is a success or failure
+ private final boolean success;
+
+ // the result value in case of success (may be null)
+ private final Object result;
+
+ // the reason for failure in case of failure (may be null)
+ private final Throwable cause;
+
+ /**
+ * Creates an outcome instance
+ *
+ * @param success {@code true} to indicate success or {@code false} to indicate failure
+ * @param result optional result value in case of success, may be {@code null}
+ * @param cause optional cause in case of failure, may be {@code null}
+ */
+ private ProviderOutcome(boolean success, Object result, Throwable cause) {
+ this.success = success;
+ this.result = result;
+ this.cause = cause;
+ }
+
+ /**
+ * Create a successful outcome
+ *
+ * @param result the result
+ * @return a successful result
+ */
+ public static ProviderOutcome success(Object result) {
+ return new ProviderOutcome(true, result, null);
+ }
+
+ /**
+ * Create a failed outcome without a specific {@link #getCause() cause}. This method must be used for creating outcomes that don't
+ * signal an error but rather the fact that the {@link UseProvider} is not capable of fulfilling the request.
+ *
+ * @return a failed outcome
+ */
+ public static ProviderOutcome failure() {
+ return GENERIC_FAILURE;
+ }
+
+ /**
+ * Create a failed outcome with the given {@link #getCause() cause}. This method must be used when the {@link UseProvider} is
+ * capable of fulfilling the request but an error condition prevents the provider from doing so.
+ *
+ * @param cause The reason for this failure, which may be {@code null}
+ * @return a failed outcome
+ */
+ public static ProviderOutcome failure(Throwable cause) {
+ return new ProviderOutcome(false, null, cause);
+ }
+
+ /**
+ * If the given obj is not {@code null} return a {@link #success(Object) successful outcome}, with the given result. Otherwise, return
+ * {@link #failure()}.
+ *
+ * @param obj the result
+ * @return an outcome based on whether the parameter is null or not
+ */
+ public static ProviderOutcome notNullOrFailure(Object obj) {
+ return (obj == null) ? failure() : success(obj);
+ }
+
+ /**
+ * Check if the outcome has been successful
+ *
+ * @return the outcome success status
+ */
+ public boolean isSuccess() {
+ return success;
+ }
+
+ /**
+ * Check whether the outcome is a failure
+ *
+ * @return the outcome failure status
+ */
+ public boolean isFailure() {
+ return !isSuccess();
+ }
+
+ /**
+ * Get the result in this outcome.
+ *
+ * @return the result of the container
+ * @throws IllegalStateException if the outcome is a failure
+ */
+ public Object getResult() {
+ if (!success) {
+ throw new IllegalStateException("Outcome has not been successful");
+ }
+ return result;
+ }
+
+ /**
+ * Returns the cause for this failure outcome or {@code null} if this outcome is a success or no cause has been defined with the
+ * {@link #failure(Throwable)} method.
+ *
+ * @return the cause for this failure outcome.
+ */
+ public Throwable getCause() {
+ return cause;
+ }
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java
new file mode 100644
index 0000000..9c7b2b6
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.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.use;
+
+import javax.script.Bindings;
+
+import org.apache.sling.scripting.sightly.render.RenderContext;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * <p>
+ * A {@code UseProvider} instantiates objects for the Use-API.
+ * </p>
+ */
+@ConsumerType
+public interface UseProvider {
+
+ /**
+ * Provide an instance based on the given identifier
+ *
+ * @param identifier the identifier of the dependency
+ * @param renderContext the current rendering context
+ * @param arguments specific arguments provided by the use plugin
+ * @return a container with the instance that corresponds to the identifier; if the identifier cannot be
+ * handled by this provider, a failed outcome is returned.
+ */
+ ProviderOutcome provide(String identifier, RenderContext renderContext, Bindings arguments);
+}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java b/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java
new file mode 100644
index 0000000..2564bea
--- /dev/null
+++ b/src/main/java/org/apache/sling/scripting/sightly/use/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.use;
+
+import aQute.bnd.annotation.Version;
diff --git a/src/main/resources/templates/compiled_unit_template.txt b/src/main/resources/templates/compiled_unit_template.txt
new file mode 100644
index 0000000..a327d6a
--- /dev/null
+++ b/src/main/resources/templates/compiled_unit_template.txt
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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 ##PackageName##;
+
+import java.io.PrintWriter;
+import java.util.Collection;
+import javax.script.Bindings;
+
+import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
+import org.apache.sling.scripting.sightly.render.RenderContext;
+
+public final class ##ClassName## extends RenderUnit {
+
+ @Override
+ protected final void render(PrintWriter out,
+ Bindings bindings,
+ Bindings arguments,
+ RenderContext renderContext) {
+// Main Template Body -----------------------------------------------------------------------------
+
+##MainBody##
+
+// End Of Main Template Body ----------------------------------------------------------------------
+ }
+
+
+
+ {
+//Sub-Templates Initialization --------------------------------------------------------------------
+
+##SubTemplateMapInit##
+
+//End of Sub-Templates Initialization -------------------------------------------------------------
+ }
+
+}
+
diff --git a/src/main/resources/templates/subtemplate.txt b/src/main/resources/templates/subtemplate.txt
new file mode 100644
index 0000000..459e4bf
--- /dev/null
+++ b/src/main/resources/templates/subtemplate.txt
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+addSubTemplate("##Name##", new RenderUnit() {
+
+ @Override
+ protected final void render(PrintWriter out,
+ Bindings bindings,
+ Bindings arguments,
+ RenderContext renderContext) {
+// Main Sub-Template Body -------------------------------------------------------------------------
+
+##MainBody##
+
+// End Of Main Sub-Template Body ------------------------------------------------------------------
+ }
+
+
+
+ {
+//Sub-Sub-Templates Initialization ----------------------------------------------------------------
+
+##SubTemplateMapInit##
+
+//End of Sub-Sub-Templates Initialization ---------------------------------------------------------
+ }
+
+});
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
new file mode 100644
index 0000000..83bfac7
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.compiler.java;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.scripting.sightly.compiler.CompilationUnit;
+import org.apache.sling.scripting.sightly.compiler.SightlyCompiler;
+import org.apache.sling.scripting.sightly.compiler.java.utils.CharSequenceJavaCompiler;
+import org.apache.sling.scripting.sightly.compiler.java.utils.TestUtils;
+import org.apache.sling.scripting.sightly.java.compiler.ClassInfo;
+import org.apache.sling.scripting.sightly.java.compiler.JavaClassBackendCompiler;
+import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
+import org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel;
+import org.apache.sling.scripting.sightly.render.RenderContext;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class JavaClassBackendCompilerTest {
+
+ @Test
+ public void testScript() throws Exception {
+ CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/test.html");
+ JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
+ SightlyCompiler sightlyCompiler = new SightlyCompiler();
+ sightlyCompiler.compile(compilationUnit, backendCompiler);
+ ClassInfo classInfo = new ClassInfo() {
+ @Override
+ public String getSimpleClassName() {
+ return "Test";
+ }
+
+ @Override
+ public String getPackageName() {
+ return "org.example.test";
+ }
+
+ @Override
+ public String getFullyQualifiedClassName() {
+ return "org.example.test.Test";
+ }
+ };
+ String source = backendCompiler.build(classInfo);
+ ClassLoader classLoader = JavaClassBackendCompilerTest.class.getClassLoader();
+ CharSequenceJavaCompiler<RenderUnit> compiler = new CharSequenceJavaCompiler<>(classLoader, null);
+ Class<RenderUnit> newClass = compiler.compile(classInfo.getFullyQualifiedClassName(), source, new Class<?>[]{});
+ RenderUnit renderUnit = newClass.newInstance();
+ StringWriter writer = new StringWriter();
+ PrintWriter printWriter = new PrintWriter(writer);
+ RenderContext renderContext = new RenderContext() {
+ @Override
+ public AbstractRuntimeObjectModel getObjectModel() {
+ return new AbstractRuntimeObjectModel() {};
+ }
+
+ @Override
+ public Bindings getBindings() {
+ return new SimpleBindings();
+ }
+
+ @Override
+ public Object call(String functionName, Object... arguments) {
+ assert arguments.length == 2;
+ // for this test case only the xss runtime function will be called; return the unfiltered input
+ return arguments[0];
+ }
+ };
+ renderUnit.render(printWriter, renderContext, new SimpleBindings());
+ String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/test-output.html"), "UTF-8");
+ assertEquals(expectedOutput, writer.toString());
+
+ }
+}
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java
new file mode 100644
index 0000000..f3b1d3a
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java
@@ -0,0 +1,550 @@
+/*******************************************************************************
+ * 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.compiler.java.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import javax.tools.DiagnosticCollector;
+import javax.tools.FileObject;
+import javax.tools.ForwardingJavaFileManager;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.JavaFileObject.Kind;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+/**
+ * This compiler is a slightly simplified version of the CharSequenceCompiler described at
+ * http://www.ibm.com/developerworks/java/library/j-jcomp/index.html.
+ */
+public class CharSequenceJavaCompiler<T> {
+ // Compiler requires source files with a ".java" extension:
+ static final String JAVA_EXTENSION = ".java";
+
+ private final ClassLoaderImpl classLoader;
+
+ // The compiler instance that this facade uses.
+ private final JavaCompiler compiler;
+
+ // The compiler options (such as "-target" "1.5").
+ private final List<String> options;
+
+ // collect compiler diagnostics in this instance.
+ private DiagnosticCollector<JavaFileObject> diagnostics;
+
+ // The FileManager which will store source and class "files".
+ private final FileManagerImpl javaFileManager;
+
+ /**
+ * Construct a new instance which delegates to the named class loader.
+ *
+ * @param loader
+ * the application ClassLoader. The compiler will look through to
+ * this // class loader for dependent classes
+ * @param options
+ * The compiler options (such as "-target" "1.5"). See the usage
+ * for javac
+ * @throws IllegalStateException
+ * if the Java compiler cannot be loaded.
+ */
+ public CharSequenceJavaCompiler(ClassLoader loader, Iterable<String> options) {
+ compiler = ToolProvider.getSystemJavaCompiler();
+ if (compiler == null) {
+ throw new IllegalStateException("Cannot find the system Java compiler. "
+ + "Check that your class path includes tools.jar");
+ }
+ classLoader = new ClassLoaderImpl(loader);
+ diagnostics = new DiagnosticCollector<>();
+ final JavaFileManager fileManager = compiler.getStandardFileManager(diagnostics,
+ null, null);
+ // create our FileManager which chains to the default file manager
+ // and our ClassLoader
+ javaFileManager = new FileManagerImpl(fileManager, classLoader);
+ this.options = new ArrayList<>();
+ if (options != null) { // make a save copy of input options
+ for (String option : options) {
+ this.options.add(option);
+ }
+ }
+ }
+
+ /**
+ * Compile Java source in <var>javaSource</name> and return the resulting
+ * class.
+ * <p>
+ * Thread safety: this method is thread safe if the <var>javaSource</var>
+ * and <var>diagnosticsList</var> are isolated to this thread.
+ *
+ * @param qualifiedClassName
+ * The fully qualified class name.
+ * @param javaSource
+ * Complete java source, including a package statement and a class,
+ * interface, or annotation declaration.
+ * @param types
+ * zero or more Class objects representing classes or interfaces
+ * that the resulting class must be assignable (castable) to.
+ * @return a Class which is generated by compiling the source
+ * @throws CharSequenceJavaCompilerException
+ * if the source cannot be compiled - for example, if it contains
+ * syntax or semantic errors or if dependent classes cannot be
+ * found.
+ * @throws ClassCastException
+ * if the generated class is not assignable to all the optional
+ * <var>types</var>.
+ */
+ public synchronized Class<T> compile(final String qualifiedClassName,
+ final CharSequence javaSource,
+ final Class<?>... types) throws CharSequenceJavaCompilerException,
+ ClassCastException {
+ Map<String, CharSequence> classes = new HashMap<>(1);
+ classes.put(qualifiedClassName, javaSource);
+ Map<String, Class<T>> compiled = compile(classes);
+ Class<T> newClass = compiled.get(qualifiedClassName);
+ return castable(newClass, types);
+ }
+
+ /**
+ * Compile multiple Java source strings and return a Map containing the
+ * resulting classes.
+ * <p>
+ * Thread safety: this method is thread safe if the <var>classes</var> and
+ * <var>diagnosticsList</var> are isolated to this thread.
+ *
+ * @param classes
+ * A Map whose keys are qualified class names and whose values are
+ * the Java source strings containing the definition of the class.
+ * A map value may be null, indicating that compiled class is
+ * expected, although no source exists for it (it may be a
+ * non-public class contained in one of the other strings.)
+ * @return A mapping of qualified class names to their corresponding classes.
+ * The map has the same keys as the input <var>classes</var>; the
+ * values are the corresponding Class objects.
+ * @throws CharSequenceJavaCompilerException
+ * if the source cannot be compiled
+ */
+ public synchronized Map<String, Class<T>> compile(final Map<String, CharSequence> classes) throws CharSequenceJavaCompilerException {
+ List<JavaFileObject> sources = new ArrayList<>();
+ for (Entry<String, CharSequence> entry : classes.entrySet()) {
+ String qualifiedClassName = entry.getKey();
+ CharSequence javaSource = entry.getValue();
+ if (javaSource != null) {
+ final int dotPos = qualifiedClassName.lastIndexOf('.');
+ final String className = dotPos == -1 ? qualifiedClassName
+ : qualifiedClassName.substring(dotPos + 1);
+ final String packageName = dotPos == -1 ? "" : qualifiedClassName
+ .substring(0, dotPos);
+ final JavaFileObjectImpl source = new JavaFileObjectImpl(className,
+ javaSource);
+ sources.add(source);
+ // Store the source file in the FileManager via package/class
+ // name.
+ // For source files, we add a .java extension
+ javaFileManager.putFileForInput(StandardLocation.SOURCE_PATH, packageName,
+ className + JAVA_EXTENSION, source);
+ }
+ }
+ // Get a CompliationTask from the compiler and compile the sources
+ final CompilationTask task = compiler.getTask(null, javaFileManager, diagnostics,
+ options, null, sources);
+ final Boolean result = task.call();
+ if (result == null || !result) {
+ throw new CharSequenceJavaCompilerException("Compilation failed.", classes
+ .keySet(), diagnostics);
+ }
+ try {
+ // For each class name in the inpput map, get its compiled
+ // class and put it in the output map
+ Map<String, Class<T>> compiled = new HashMap<>();
+ for (String qualifiedClassName : classes.keySet()) {
+ final Class<T> newClass = loadClass(qualifiedClassName);
+ compiled.put(qualifiedClassName, newClass);
+ }
+ return compiled;
+ } catch (ClassNotFoundException e) {
+ throw new CharSequenceJavaCompilerException(classes.keySet(), e, diagnostics);
+ }
+ }
+
+ /**
+ * Load a class that was generated by this instance or accessible from its
+ * parent class loader. Use this method if you need access to additional
+ * classes compiled by
+ * {@link #compile(String, CharSequence, Class...) compile()},
+ * for example if the primary class contained nested classes or additional
+ * non-public classes.
+ *
+ * @param qualifiedClassName
+ * the name of the compiled class you wish to load
+ * @return a Class instance named by <var>qualifiedClassName</var>
+ * @throws ClassNotFoundException
+ * if no such class is found.
+ */
+ @SuppressWarnings("unchecked")
+ public Class<T> loadClass(final String qualifiedClassName)
+ throws ClassNotFoundException {
+ return (Class<T>) classLoader.loadClass(qualifiedClassName);
+ }
+
+ /**
+ * Check that the <var>newClass</var> is a subtype of all the type
+ * parameters and throw a ClassCastException if not.
+ *
+ * @param types
+ * zero of more classes or interfaces that the <var>newClass</var>
+ * must be castable to.
+ * @return <var>newClass</var> if it is castable to all the types
+ * @throws ClassCastException
+ * if <var>newClass</var> is not castable to all the types.
+ */
+ private Class<T> castable(Class<T> newClass, Class<?>... types)
+ throws ClassCastException {
+ for (Class<?> type : types)
+ if (!type.isAssignableFrom(newClass)) {
+ throw new ClassCastException(type.getName());
+ }
+ return newClass;
+ }
+
+ /**
+ * Converts a String to a URI.
+ *
+ * @param name
+ * a file name
+ * @return a URI
+ */
+ static URI toURI(String name) {
+ try {
+ return new URI(name);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
+
+/**
+ * A JavaFileManager which manages Java source and classes. This FileManager
+ * delegates to the JavaFileManager and the ClassLoaderImpl provided in the
+ * constructor. The sources are all in memory CharSequence instances and the
+ * classes are all in memory byte arrays.
+ */
+final class FileManagerImpl extends ForwardingJavaFileManager<JavaFileManager> {
+ // the delegating class loader (passed to the constructor)
+ private final ClassLoaderImpl classLoader;
+
+ // Internal map of filename URIs to JavaFileObjects.
+ private final Map<URI, JavaFileObject> fileObjects = new HashMap<>();
+
+ /**
+ * Construct a new FileManager which forwards to the <var>fileManager</var>
+ * for source and to the <var>classLoader</var> for classes
+ *
+ * @param fileManager
+ * another FileManager that this instance delegates to for
+ * additional source.
+ * @param classLoader
+ * a ClassLoader which contains dependent classes that the compiled
+ * classes will require when compiling them.
+ */
+ public FileManagerImpl(JavaFileManager fileManager, ClassLoaderImpl classLoader) {
+ super(fileManager);
+ this.classLoader = classLoader;
+ }
+
+ /**
+ * For a given file <var>location</var>, return a FileObject from which the
+ * compiler can obtain source or byte code.
+ *
+ * @param location
+ * an abstract file location
+ * @param packageName
+ * the package name for the file
+ * @param relativeName
+ * the file's relative name
+ * @return a FileObject from this or the delegated FileManager
+ * @see javax.tools.ForwardingJavaFileManager#getFileForInput(javax.tools.JavaFileManager.Location,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public FileObject getFileForInput(Location location, String packageName,
+ String relativeName) throws IOException {
+ FileObject o = fileObjects.get(uri(location, packageName, relativeName));
+ if (o != null)
+ return o;
+ return super.getFileForInput(location, packageName, relativeName);
+ }
+
+ /**
+ * Store a file that may be retrieved later with
+ * {@link #getFileForInput(javax.tools.JavaFileManager.Location, String, String)}
+ *
+ * @param location
+ * the file location
+ * @param packageName
+ * the Java class' package name
+ * @param relativeName
+ * the relative name
+ * @param file
+ * the file object to store for later retrieval
+ */
+ public void putFileForInput(StandardLocation location, String packageName,
+ String relativeName, JavaFileObject file) {
+ fileObjects.put(uri(location, packageName, relativeName), file);
+ }
+
+ /**
+ * Convert a location and class name to a URI
+ */
+ private URI uri(Location location, String packageName, String relativeName) {
+ return CharSequenceJavaCompiler.toURI(location.getName() + '/' + packageName + '/'
+ + relativeName);
+ }
+
+ /**
+ * Create a JavaFileImpl for an output class file and store it in the
+ * classloader.
+ *
+ * @see javax.tools.ForwardingJavaFileManager#getJavaFileForOutput(javax.tools.JavaFileManager.Location,
+ * java.lang.String, javax.tools.JavaFileObject.Kind,
+ * javax.tools.FileObject)
+ */
+ @Override
+ public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName,
+ Kind kind, FileObject outputFile) throws IOException {
+ JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
+ classLoader.add(qualifiedName, file);
+ return file;
+ }
+
+ @Override
+ public ClassLoader getClassLoader(JavaFileManager.Location location) {
+ return classLoader;
+ }
+
+ @Override
+ public String inferBinaryName(Location loc, JavaFileObject file) {
+ String result;
+ // For our JavaFileImpl instances, return the file's name, else
+ // simply run the default implementation
+ if (file instanceof JavaFileObjectImpl)
+ result = file.getName();
+ else
+ result = super.inferBinaryName(loc, file);
+ return result;
+ }
+
+ @Override
+ public Iterable<JavaFileObject> list(Location location, String packageName,
+ Set<Kind> kinds, boolean recurse) throws IOException {
+ Iterable<JavaFileObject> result = super.list(location, packageName, kinds,
+ recurse);
+ ArrayList<JavaFileObject> files = new ArrayList<>();
+ if (location == StandardLocation.CLASS_PATH
+ && kinds.contains(JavaFileObject.Kind.CLASS)) {
+ for (JavaFileObject file : fileObjects.values()) {
+ if (file.getKind() == Kind.CLASS && file.getName().startsWith(packageName))
+ files.add(file);
+ }
+ files.addAll(classLoader.files());
+ } else if (location == StandardLocation.SOURCE_PATH
+ && kinds.contains(JavaFileObject.Kind.SOURCE)) {
+ for (JavaFileObject file : fileObjects.values()) {
+ if (file.getKind() == Kind.SOURCE && file.getName().startsWith(packageName))
+ files.add(file);
+ }
+ }
+ for (JavaFileObject file : result) {
+ files.add(file);
+ }
+ return files;
+ }
+}
+
+/**
+ * A JavaFileObject which contains either the source text or the compiler
+ * generated class. This class is used in two cases.
+ * <ol>
+ * <li>This instance uses it to store the source which is passed to the
+ * compiler. This uses the
+ * {@link JavaFileObjectImpl#JavaFileObjectImpl(String, CharSequence)}
+ * constructor.
+ * <li>The Java compiler also creates instances (indirectly through the
+ * FileManagerImplFileManager) when it wants to create a JavaFileObject for the
+ * .class output. This uses the
+ * {@link JavaFileObjectImpl#JavaFileObjectImpl(String, JavaFileObject.Kind)}
+ * constructor.
+ * </ol>
+ * This class does not attempt to reuse instances (there does not seem to be a
+ * need, as it would require adding a Map for the purpose, and this would also
+ * prevent garbage collection of class byte code.)
+ */
+final class JavaFileObjectImpl extends SimpleJavaFileObject {
+ // If kind == CLASS, this stores byte code from openOutputStream
+ private ByteArrayOutputStream byteCode;
+
+ // if kind == SOURCE, this contains the source text
+ private final CharSequence source;
+
+ /**
+ * Construct a new instance which stores source
+ *
+ * @param baseName
+ * the base name
+ * @param source
+ * the source code
+ */
+ JavaFileObjectImpl(final String baseName, final CharSequence source) {
+ super(CharSequenceJavaCompiler.toURI(baseName + CharSequenceJavaCompiler.JAVA_EXTENSION),
+ Kind.SOURCE);
+ this.source = source;
+ }
+
+ /**
+ * Construct a new instance
+ *
+ * @param name
+ * the file name
+ * @param kind
+ * the kind of file
+ */
+ JavaFileObjectImpl(final String name, final Kind kind) {
+ super(CharSequenceJavaCompiler.toURI(name), kind);
+ source = null;
+ }
+
+ /**
+ * Return the source code content
+ *
+ * @see javax.tools.SimpleJavaFileObject#getCharContent(boolean)
+ */
+ @Override
+ public CharSequence getCharContent(final boolean ignoreEncodingErrors)
+ throws UnsupportedOperationException {
+ if (source == null)
+ throw new UnsupportedOperationException("getCharContent()");
+ return source;
+ }
+
+ /**
+ * Return an input stream for reading the byte code
+ *
+ * @see javax.tools.SimpleJavaFileObject#openInputStream()
+ */
+ @Override
+ public InputStream openInputStream() {
+ return new ByteArrayInputStream(getByteCode());
+ }
+
+ /**
+ * Return an output stream for writing the bytecode
+ *
+ * @see javax.tools.SimpleJavaFileObject#openOutputStream()
+ */
+ @Override
+ public OutputStream openOutputStream() {
+ byteCode = new ByteArrayOutputStream();
+ return byteCode;
+ }
+
+ /**
+ * @return the byte code generated by the compiler
+ */
+ byte[] getByteCode() {
+ return byteCode.toByteArray();
+ }
+}
+
+/**
+ * A custom ClassLoader which maps class names to JavaFileObjectImpl instances.
+ */
+final class ClassLoaderImpl extends ClassLoader {
+ private final Map<String, JavaFileObject> classes = new HashMap<>();
+
+ ClassLoaderImpl(final ClassLoader parentClassLoader) {
+ super(parentClassLoader);
+ }
+
+ /**
+ * @return An collection of JavaFileObject instances for the classes in the
+ * class loader.
+ */
+ Collection<JavaFileObject> files() {
+ return Collections.unmodifiableCollection(classes.values());
+ }
+
+ @Override
+ protected Class<?> findClass(final String qualifiedClassName)
+ throws ClassNotFoundException {
+ JavaFileObject file = classes.get(qualifiedClassName);
+ if (file != null) {
+ byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
+ return defineClass(qualifiedClassName, bytes, 0, bytes.length);
+ }
+ try {
+ return Class.forName(qualifiedClassName);
+ } catch (ClassNotFoundException nf) {
+ // Ignore and fall through
+ }
+ return super.findClass(qualifiedClassName);
+ }
+
+ /**
+ * Add a class name/JavaFileObject mapping
+ *
+ * @param qualifiedClassName
+ * the name
+ * @param javaFile
+ * the file associated with the name
+ */
+ void add(final String qualifiedClassName, final JavaFileObject javaFile) {
+ classes.put(qualifiedClassName, javaFile);
+ }
+
+ @Override
+ protected synchronized Class<?> loadClass(final String name, final boolean resolve)
+ throws ClassNotFoundException {
+ return super.loadClass(name, resolve);
+ }
+
+ @Override
+ public InputStream getResourceAsStream(final String name) {
+ if (name.endsWith(".class")) {
+ String qualifiedClassName = name.substring(0,
+ name.length() - ".class".length()).replace('/', '.');
+ JavaFileObjectImpl file = (JavaFileObjectImpl) classes.get(qualifiedClassName);
+ if (file != null) {
+ return new ByteArrayInputStream(file.getByteCode());
+ }
+ }
+ return super.getResourceAsStream(name);
+ }
+}
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java
new file mode 100644
index 0000000..a5d421a
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.compiler.java.utils;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaFileObject;
+
+
+public class CharSequenceJavaCompilerException extends Exception {
+
+ private Set<String> classNames;
+ transient private DiagnosticCollector<JavaFileObject> diagnostics;
+
+ public CharSequenceJavaCompilerException(String message,
+ Set<String> qualifiedClassNames,
+ DiagnosticCollector<JavaFileObject> diagnostics) {
+ super(message);
+ setClassNames(qualifiedClassNames);
+ setDiagnostics(diagnostics);
+ }
+
+ public CharSequenceJavaCompilerException(Set<String> qualifiedClassNames,
+ Throwable cause, DiagnosticCollector<JavaFileObject> diagnostics) {
+ super(cause);
+ setClassNames(qualifiedClassNames);
+ setDiagnostics(diagnostics);
+ }
+
+ private void setClassNames(Set<String> qualifiedClassNames) {
+ classNames = new HashSet<>(qualifiedClassNames);
+ }
+
+ private void setDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
+ this.diagnostics = diagnostics;
+ }
+
+ /**
+ * Gets the diagnostics collected by this exception.
+ *
+ * @return this exception's diagnostics
+ */
+ public DiagnosticCollector<JavaFileObject> getDiagnostics() {
+ return diagnostics;
+ }
+
+ /**
+ * @return The name of the classes whose compilation caused the compile
+ * exception
+ */
+ public Collection<String> getClassNames() {
+ return Collections.unmodifiableSet(classNames);
+ }
+}
+
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java
new file mode 100644
index 0000000..f735e9e
--- /dev/null
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.compiler.java.utils;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.sling.scripting.sightly.compiler.CompilationUnit;
+
+public class TestUtils {
+
+ public static CompilationUnit readScriptFromClasspath(final String scriptResource) {
+ InputStream stream = TestUtils.class.getResourceAsStream(scriptResource);
+ final Reader reader = new InputStreamReader(stream);
+ return new CompilationUnit() {
+ @Override
+ public String getScriptName() {
+ return scriptResource;
+ }
+
+ @Override
+ public Reader getScriptReader() {
+ return reader;
+ }
+ };
+ }
+}
diff --git a/src/test/resources/test-output.html b/src/test/resources/test-output.html
new file mode 100644
index 0000000..6fad289
--- /dev/null
+++ b/src/test/resources/test-output.html
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<ul>
+ <li>1</li>
+
+ <li>2</li>
+
+ <li>3</li>
+</ul>
diff --git a/src/test/resources/test.html b/src/test/resources/test.html
new file mode 100644
index 0000000..d4024c1
--- /dev/null
+++ b/src/test/resources/test.html
@@ -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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<ul data-sly-list="${[1, 2, 3]}">
+ <li>${item}</li>
+</ul>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 18/50:
SLING-6146 - SourceIdentifier should not mangle underscore characters
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit a4081db4528fda8c322815cd568baa97b8b6a2ff
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Oct 13 19:50:19 2016 +0000
SLING-6146 - SourceIdentifier should not mangle underscore characters
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764774 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
index 3bc299c..6e2aad7 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
@@ -93,7 +93,7 @@ public class JavaEscapeUtils {
}
for (int i = 0; i < identifier.length(); i++) {
char ch = identifier.charAt(i);
- if (Character.isJavaIdentifierPart(ch) && ch != '_') {
+ if (Character.isJavaIdentifierPart(ch)) {
modifiedIdentifier.append(ch);
} else if (ch == '.') {
modifiedIdentifier.append('_');
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 41/50:
SLING-7040 : Update commons lang 2.x to 3.5
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit bd4eb8e12b10f9c1b9f2c98dd0b33e559a2537d4
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Aug 9 16:18:56 2017 +0000
SLING-7040 : Update commons lang 2.x to 3.5
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804573 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
.../sling/scripting/sightly/java/compiler/JavaEscapeUtils.java | 2 +-
.../sling/scripting/sightly/java/compiler/impl/JavaSource.java | 2 +-
.../scripting/sightly/render/AbstractRuntimeObjectModel.java | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3ec8e6a..389b82c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.4</version>
+ <version>1.0.11-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -170,9 +170,9 @@
<!-- Apache Commons -->
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.5</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.5</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
index 6e2aad7..08b4669 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/JavaEscapeUtils.java
@@ -19,7 +19,7 @@ package org.apache.sling.scripting.sightly.java.compiler;
import java.util.HashSet;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
/**
* The {@code JavaEscapeUtils} provides useful methods for escaping or transforming invalid Java tokens to valid ones that could be used in
diff --git a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java
index db67cf9..f5aefd5 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/JavaSource.java
@@ -16,7 +16,7 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.java.compiler.impl;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
/**
* Builder object for a Java class printing method.
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index 514ca48..2fa4314 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -34,8 +34,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
import org.apache.sling.scripting.sightly.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 09/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.0
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit f84baa1f248aeb887b76d33733d07f2963a93581
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 15:18:02 2016 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.0
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759289 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index d12d816..8103054 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <version>1.0.0</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.0</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 13/50:
SLING-6094 - HTL can generate invalid Java code by using user-supplied
input
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 087d83c317917eefb0be4756ef93cc06b79b0df4
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Oct 7 10:36:32 2016 +0000
SLING-6094 - HTL can generate invalid Java code by using user-supplied input
* added tests
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763732 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/JavaClassBackendCompilerTest.java | 88 +++++++++++++++++-----
src/test/resources/SLING-6094.1.html | 17 +++++
src/test/resources/SLING-6094.1.output.html | 2 +
src/test/resources/SLING-6094.2.html | 17 +++++
src/test/resources/SLING-6094.2.output.html | 2 +
5 files changed, 107 insertions(+), 19 deletions(-)
diff --git a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
index 83bfac7..3dd3c8c 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
@@ -18,6 +18,7 @@ package org.apache.sling.scripting.sightly.compiler.java;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.HashMap;
import javax.script.Bindings;
import javax.script.SimpleBindings;
@@ -32,6 +33,7 @@ import org.apache.sling.scripting.sightly.java.compiler.JavaClassBackendCompiler
import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
import org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel;
import org.apache.sling.scripting.sightly.render.RenderContext;
+import org.apache.sling.scripting.sightly.render.RuntimeObjectModel;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
@@ -44,50 +46,98 @@ public class JavaClassBackendCompilerTest {
JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
SightlyCompiler sightlyCompiler = new SightlyCompiler();
sightlyCompiler.compile(compilationUnit, backendCompiler);
- ClassInfo classInfo = new ClassInfo() {
+ ClassInfo classInfo = buildClassInfo("testScript");
+ String source = backendCompiler.build(classInfo);
+ StringWriter writer = new StringWriter();
+ Bindings bindings = new SimpleBindings();
+ RenderContext renderContext = buildRenderContext(bindings);
+ render(writer, classInfo, source, renderContext, new SimpleBindings());
+ String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/test-output.html"), "UTF-8");
+ assertEquals(expectedOutput, writer.toString());
+ }
+
+ @Test
+ public void sling_6094_1() throws Exception {
+ CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/SLING-6094.1.html");
+ JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
+ SightlyCompiler sightlyCompiler = new SightlyCompiler();
+ sightlyCompiler.compile(compilationUnit, backendCompiler);
+ ClassInfo classInfo = buildClassInfo("sling_6094_1");
+ String source = backendCompiler.build(classInfo);
+ StringWriter writer = new StringWriter();
+ Bindings bindings = new SimpleBindings();
+ bindings.put("img", new HashMap<String, Object>(){{
+ put("attributes", new HashMap<String, String>() {{
+ put("v-bind:src", "replaced");
+ }});
+ }});
+ RenderContext renderContext = buildRenderContext(bindings);
+ render(writer, classInfo, source, renderContext, new SimpleBindings());
+ String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/SLING-6094.1.output.html"), "UTF-8");
+ assertEquals(expectedOutput, writer.toString());
+ }
+
+ @Test
+ public void sling_6094_2() throws Exception {
+ CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/SLING-6094.2.html");
+ JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
+ SightlyCompiler sightlyCompiler = new SightlyCompiler();
+ sightlyCompiler.compile(compilationUnit, backendCompiler);
+ ClassInfo classInfo = buildClassInfo("sling_6094_2");
+ String source = backendCompiler.build(classInfo);
+ StringWriter writer = new StringWriter();
+ Bindings bindings = new SimpleBindings();
+ RenderContext renderContext = buildRenderContext(bindings);
+ render(writer, classInfo, source, renderContext, new SimpleBindings());
+ String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/SLING-6094.2.output.html"), "UTF-8");
+ assertEquals(expectedOutput, writer.toString());
+ }
+
+ private ClassInfo buildClassInfo(final String info) {
+ return new ClassInfo() {
@Override
public String getSimpleClassName() {
- return "Test";
+ return "Test_" + info;
}
@Override
public String getPackageName() {
- return "org.example.test";
+ return "org.apache.sling.scripting.sightly.compiler.java";
}
@Override
public String getFullyQualifiedClassName() {
- return "org.example.test.Test";
+ return "org.apache.sling.scripting.sightly.compiler.java.Test_" + info;
}
};
- String source = backendCompiler.build(classInfo);
- ClassLoader classLoader = JavaClassBackendCompilerTest.class.getClassLoader();
- CharSequenceJavaCompiler<RenderUnit> compiler = new CharSequenceJavaCompiler<>(classLoader, null);
- Class<RenderUnit> newClass = compiler.compile(classInfo.getFullyQualifiedClassName(), source, new Class<?>[]{});
- RenderUnit renderUnit = newClass.newInstance();
- StringWriter writer = new StringWriter();
- PrintWriter printWriter = new PrintWriter(writer);
- RenderContext renderContext = new RenderContext() {
+ }
+
+ private RenderContext buildRenderContext(final Bindings bindings) {
+ return new RenderContext() {
@Override
- public AbstractRuntimeObjectModel getObjectModel() {
+ public RuntimeObjectModel getObjectModel() {
return new AbstractRuntimeObjectModel() {};
}
@Override
public Bindings getBindings() {
- return new SimpleBindings();
+ return bindings;
}
@Override
public Object call(String functionName, Object... arguments) {
- assert arguments.length == 2;
- // for this test case only the xss runtime function will be called; return the unfiltered input
return arguments[0];
}
};
- renderUnit.render(printWriter, renderContext, new SimpleBindings());
- String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/test-output.html"), "UTF-8");
- assertEquals(expectedOutput, writer.toString());
+ }
+ private void render(StringWriter writer, ClassInfo classInfo, String source, RenderContext renderContext, Bindings arguments) throws
+ Exception {
+ ClassLoader classLoader = JavaClassBackendCompilerTest.class.getClassLoader();
+ CharSequenceJavaCompiler<RenderUnit> compiler = new CharSequenceJavaCompiler<>(classLoader, null);
+ Class<RenderUnit> newClass = compiler.compile(classInfo.getFullyQualifiedClassName(), source);
+ RenderUnit renderUnit = newClass.newInstance();
+ PrintWriter printWriter = new PrintWriter(writer);
+ renderUnit.render(printWriter, renderContext, arguments);
}
}
diff --git a/src/test/resources/SLING-6094.1.html b/src/test/resources/SLING-6094.1.html
new file mode 100644
index 0000000..e2706e2
--- /dev/null
+++ b/src/test/resources/SLING-6094.1.html
@@ -0,0 +1,17 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+<img src="" v-bind:src="abc" data-sly-attribute="${img.attributes}" />
diff --git a/src/test/resources/SLING-6094.1.output.html b/src/test/resources/SLING-6094.1.output.html
new file mode 100644
index 0000000..2ce0be5
--- /dev/null
+++ b/src/test/resources/SLING-6094.1.output.html
@@ -0,0 +1,2 @@
+
+<img src="" v-bind:src="replaced"/>
diff --git a/src/test/resources/SLING-6094.2.html b/src/test/resources/SLING-6094.2.html
new file mode 100644
index 0000000..fe07e01
--- /dev/null
+++ b/src/test/resources/SLING-6094.2.html
@@ -0,0 +1,17 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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 data-sly-test.jcr:title="${1>0}">correctly escaped variable</div>
diff --git a/src/test/resources/SLING-6094.2.output.html b/src/test/resources/SLING-6094.2.output.html
new file mode 100644
index 0000000..cad8097
--- /dev/null
+++ b/src/test/resources/SLING-6094.2.output.html
@@ -0,0 +1,2 @@
+
+<div>correctly escaped variable</div>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 08/50:
releng: updated dependency
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit ff134196a2154b6a6bccebff95444ead5afc8d7d
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Sep 5 15:17:27 2016 +0000
releng: updated dependency
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1759288 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ab66fd9..d12d816 100644
--- a/pom.xml
+++ b/pom.xml
@@ -120,7 +120,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>0.0.1-SNAPSHOT</version>
+ <version>1.0.0</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 43/50:
SLING-7085 - Reduce code duplication
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 4f0b70d81f317cc3e88ae8075d4b4ff494d3b9ed
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Aug 25 12:50:08 2017 +0000
SLING-7085 - Reduce code duplication
* exported org.apache.sling.scripting.sightly.compiler.util.ObjectModel
* delegated calls from org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel to ObjectModel
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1806167 13f79535-47bb-0310-9956-ffa450edef68
---
.../sightly/render/AbstractRuntimeObjectModel.java | 326 ++++++---------------
1 file changed, 93 insertions(+), 233 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index 2fa4314..3518f55 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -16,57 +16,36 @@
******************************************************************************/
package org.apache.sling.scripting.sightly.render;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.sling.scripting.sightly.Record;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.sling.scripting.sightly.compiler.util.ObjectModel;
/**
* Default abstract implementation of {@link RuntimeObjectModel}.
*/
public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
- private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRuntimeObjectModel.class);
-
/**
* A {@link Set} that stores all the supported primitive classes.
*/
- public static final Set<Class<?>> PRIMITIVE_CLASSES = Collections.unmodifiableSet(new HashSet<Class<?>>() {{
- add(Boolean.class);
- add(Character.class);
- add(Byte.class);
- add(Short.class);
- add(Integer.class);
- add(Long.class);
- add(Float.class);
- add(Double.class);
- add(Void.class);
- }});
+ public static final Set<Class<?>> PRIMITIVE_CLASSES = ObjectModel.PRIMITIVE_CLASSES;
public static final String TO_STRING_METHOD = "toString";
@Override
public boolean isPrimitive(Object obj) {
- return PRIMITIVE_CLASSES.contains(obj.getClass());
+ return ObjectModel.isPrimitive(obj);
}
@Override
@@ -83,7 +62,7 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
return true;
}
String value = toString(target);
- return NumberUtils.isNumber(value);
+ return NumberUtils.isCreatable(value);
}
@Override
@@ -96,7 +75,7 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
public Object resolveProperty(Object target, Object property) {
Object resolved;
if (property instanceof Number) {
- resolved = getIndex(target, ((Number) property).intValue());
+ resolved = ObjectModel.getIndex(target, ((Number) property).intValue());
} else {
resolved = getProperty(target, property);
}
@@ -105,25 +84,15 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
@Override
public boolean toBoolean(Object object) {
- return toBooleanInternal(object);
+ return ObjectModel.toBoolean(object);
}
@Override
public Number toNumber(Object object) {
- if (object == null) {
- return null;
- }
- if (object instanceof Number) {
- return (Number) object;
- }
- String stringValue = toString(object);
- try {
- return NumberUtils.createNumber(stringValue);
- } catch (NumberFormatException e) {
- return null;
- }
+ return ObjectModel.toNumber(object);
}
+ @Override
public Date toDate(Object object) {
if (object instanceof Date) {
return (Date)object;
@@ -135,12 +104,15 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
@Override
public String toString(Object target) {
- return objectToString(target);
+ return ObjectModel.toString(target);
}
@Override
public Collection<Object> toCollection(Object object) {
- return obtainCollection(object);
+ if (object instanceof Record) {
+ return ((Record) object).getPropertyNames();
+ }
+ return ObjectModel.toCollection(object);
}
@Override
@@ -150,7 +122,6 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
} else if (object instanceof Record) {
Map<String, Object> map = new HashMap<>();
Record record = (Record) object;
- @SuppressWarnings("unchecked")
Set<String> properties = record.getPropertyNames();
for (String property : properties) {
map.put(property, record.getProperty(property));
@@ -160,247 +131,136 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
return Collections.emptyMap();
}
- protected String objectToString(Object obj) {
- String output = "";
- if (obj != null) {
- if (obj instanceof String) {
- output = (String) obj;
- } else if (isPrimitive(obj)) {
- output = obj.toString();
- } else if (obj instanceof Enum) {
- return ((Enum) obj).name();
- } else {
- Collection<?> col = obtainCollection(obj);
- if (col != null) {
- output = collectionToString(col);
- }
- }
- }
- return output;
- }
-
protected Object getProperty(Object target, Object propertyObj) {
- String property = toString(propertyObj);
- if (StringUtils.isEmpty(property)) {
- throw new IllegalArgumentException("Invalid property name");
- }
- if (target == null) {
- return null;
- }
+ String property = ObjectModel.toString(propertyObj);
Object result = null;
- if (target instanceof Map) {
- result = getMapProperty((Map) target, property);
- }
- if (result == null && target instanceof Record) {
+ if (target instanceof Record) {
result = ((Record) target).getProperty(property);
}
if (result == null) {
- result = getObjectProperty(target, property);
+ result = ObjectModel.resolveProperty(target, property);
}
return result;
}
- @SuppressWarnings("unchecked")
+ /**
+ * @deprecated see {@link ObjectModel#toCollection(Object)}
+ */
+ @Deprecated
protected Collection<Object> obtainCollection(Object obj) {
- if (obj == null) {
- return Collections.emptyList();
- }
- if (obj instanceof Object[]) {
- return Arrays.asList((Object[]) obj);
- }
- if (obj instanceof Collection) {
- return (Collection<Object>) obj;
- }
- if (obj instanceof Map) {
- return ((Map) obj).keySet();
- }
- if (obj instanceof Record) {
- return ((Record) obj).getPropertyNames();
- }
- if (obj instanceof Enumeration) {
- return Collections.list((Enumeration<Object>) obj);
- }
- if (obj instanceof Iterator) {
- return fromIterator((Iterator<Object>) obj);
- }
- if (obj instanceof Iterable) {
- Iterable iterable = (Iterable) obj;
- return fromIterator(iterable.iterator());
- }
- if (obj instanceof String || obj instanceof Number) {
- Collection list = new ArrayList();
- list.add(obj);
- return list;
- }
- return Collections.emptyList();
+ return ObjectModel.toCollection(obj);
+ }
+
+ /**
+ * @deprecated see {@link ObjectModel#toString(Object)}
+ */
+ @Deprecated
+ protected String objectToString(Object obj) {
+ return ObjectModel.toString(obj);
}
+ /**
+ * @deprecated see {@link ObjectModel#collectionToString(Collection)}
+ */
+ @Deprecated
protected String collectionToString(Collection<?> col) {
- StringBuilder builder = new StringBuilder();
- String prefix = "";
- for (Object o : col) {
- builder.append(prefix).append(objectToString(o));
- prefix = ",";
- }
- return builder.toString();
+ return ObjectModel.collectionToString(col);
}
+ /**
+ * @deprecated see {@link ObjectModel#fromIterator(Iterator)}
+ */
+ @Deprecated
protected Collection<Object> fromIterator(Iterator<Object> iterator) {
- ArrayList<Object> result = new ArrayList<>();
- while (iterator.hasNext()) {
- result.add(iterator.next());
- }
- return result;
+ return ObjectModel.fromIterator(iterator);
}
+ /**
+ * @deprecated see {@link ObjectModel#toBoolean(Object)}
+ */
+ @Deprecated
protected boolean toBooleanInternal(Object obj) {
- if (obj == null) {
- return false;
- }
-
- if (obj instanceof Number) {
- Number number = (Number) obj;
- return !(number.doubleValue() == 0.0);
- }
-
- String s = obj.toString().trim();
- if ("".equals(s)) {
- return false;
- } else if ("true".equalsIgnoreCase(s) || "false".equalsIgnoreCase(s)) {
- return Boolean.parseBoolean(s);
- }
-
- if (obj instanceof Collection) {
- return ((Collection) obj).size() > 0;
- }
-
- if (obj instanceof Map) {
- return ((Map) obj).size() > 0;
- }
-
- if (obj instanceof Iterable<?>) {
- return ((Iterable<?>) obj).iterator().hasNext();
- }
-
- if (obj instanceof Iterator<?>) {
- return ((Iterator<?>) obj).hasNext();
- }
-
- return !(obj instanceof Object[]) || ((Object[]) obj).length > 0;
+ return ObjectModel.toBoolean(obj);
}
+ /**
+ * @deprecated see {@link ObjectModel#getIndex(Object, int)}
+ */
+ @Deprecated
protected Object getIndex(Object obj, int index) {
- if (obj instanceof Map) {
- Map map = (Map) obj;
- if (map.containsKey(index)) {
- return map.get(index);
- }
- }
- Collection collection = toCollection(obj);
- if (collection instanceof List) {
- return getIndexSafe((List) collection, index);
- }
- return null;
+ return ObjectModel.getIndex(obj, index);
}
+ /**
+ * @deprecated see {@link ObjectModel#getIndex(Object, int)}
+ */
+ @Deprecated
protected Object getIndexSafe(List list, int index) {
- if (index < 0 || index >= list.size()) {
- return null;
- }
- return list.get(index);
+ return ObjectModel.getIndex(list, index);
}
+ /**
+ * @deprecated use {@link Map#get(Object)}
+ */
+ @Deprecated
protected Object getMapProperty(Map map, String property) {
return map.get(property);
}
+ /**
+ * @deprecated see {@link ObjectModel#resolveProperty(Object, Object)}
+ */
+ @Deprecated
protected Object getObjectProperty(Object obj, String property) {
- Object result = getObjectNoArgMethod(obj, property);
- if (result == null) {
- result = getField(obj, property);
- }
- return result;
+ return ObjectModel.resolveProperty(obj, property);
}
+ /**
+ * @deprecated see {@link ObjectModel#getField(Object, String)}
+ */
+ @Deprecated
protected static Object getField(Object obj, String property) {
- Class<?> cls = obj.getClass();
- if (cls.isArray() && "length".equals(property)) {
- return Array.getLength(obj);
- }
- try {
- Field field = cls.getDeclaredField(property);
- return field.get(obj);
- } catch (Exception e) {
- return null;
- }
+ return ObjectModel.getField(obj, property);
}
+ /**
+ * @deprecated see {@link ObjectModel#invokeBeanMethod(Object, String)}
+ */
+ @Deprecated
protected Object getObjectNoArgMethod(Object obj, String property) {
- Class<?> cls = obj.getClass();
- Method method = findMethod(cls, property);
- if (method != null) {
- method = extractMethodInheritanceChain(cls, method);
- try {
- return method.invoke(obj);
- } catch (Exception e) {
- LOGGER.error("Cannot access method " + property + " on object " + obj.toString(), e);
- }
- }
- return null;
+ return ObjectModel.invokeBeanMethod(obj, property);
}
+ /**
+ * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)}
+ */
+ @Deprecated
protected static Method findMethod(Class<?> cls, String baseName) {
- Method[] publicMethods = cls.getMethods();
- String capitalized = StringUtils.capitalize(baseName);
- for (Method m : publicMethods) {
- if (m.getParameterTypes().length == 0) {
- String methodName = m.getName();
- if (baseName.equals(methodName) || ("get" + capitalized).equals(methodName) || ("is" + capitalized).equals(methodName)) {
- // this method is good, check whether allowed
- if (isMethodAllowed(m)) {
- return m;
- }
- // method would match but is not allowed, abort
- break;
- }
- }
- }
- return null;
+ return ObjectModel.findBeanMethod(cls, baseName);
}
+ /**
+ * @deprecated see {@link ObjectModel#isMethodAllowed(Method)}
+ */
+ @Deprecated
protected static boolean isMethodAllowed(Method method) {
- Class<?> declaringClass = method.getDeclaringClass();
- //methods of the Object.class are forbidden (except toString, which is allowed)
- return declaringClass != Object.class || TO_STRING_METHOD.equals(method.getName());
+ return ObjectModel.isMethodAllowed(method);
}
+ /**
+ * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)} (Class, Method)}
+ */
+ @Deprecated
protected Method extractMethodInheritanceChain(Class type, Method m) {
- if (m == null || Modifier.isPublic(type.getModifiers())) {
- return m;
- }
- Class[] iFaces = type.getInterfaces();
- Method mp;
- for (Class<?> iFace : iFaces) {
- mp = getClassMethod(iFace, m);
- if (mp != null) {
- return mp;
- }
- }
- return getClassMethod(type.getSuperclass(), m);
+ return ObjectModel.findBeanMethod(type, m.getName());
}
+ /**
+ * @deprecated see {@link ObjectModel#findBeanMethod(Class, String)} (Class, Method)}
+ */
+ @Deprecated
protected Method getClassMethod(Class<?> clazz, Method m) {
- Method mp;
- try {
- mp = clazz.getMethod(m.getName(), m.getParameterTypes());
- mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp);
- if (mp != null) {
- return mp;
- }
- } catch (NoSuchMethodException e) {
- // do nothing
- }
- return null;
+ return ObjectModel.findBeanMethod(clazz, m.getName());
}
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 16/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.2
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 0096b6393980ce2c5c2f438bcba32c6f5600d3de
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Oct 10 15:46:52 2016 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.2
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764127 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 616e9ea..4df353b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.1-SNAPSHOT</version>
+ <version>1.0.2</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.2</url>
</scm>
<properties>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 42/50:
SLING-7084 - Coverage report is not generated correctly for HTL modules
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 0ec256053598508e705875ecc9cf0437391e1a32
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Aug 24 13:10:03 2017 +0000
SLING-7084 - Coverage report is not generated correctly for HTL modules
* switched to slingstart-maven-plugin 1.7.7-SNAPSHOT, until 1.7.8 is released
* updated JaCoCo version to 0.7.9
* based tests on released Apache Sling Launchpad 9
* increased LaunchpadReadyIT timeouts from 20 to 60 seconds
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1806038 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 389b82c..c3f6de2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
</scm>
<properties>
- <jacoco.maven.plugin.version>0.7.6.201602180812</jacoco.maven.plugin.version>
+ <jacoco.maven.plugin.version>0.7.9</jacoco.maven.plugin.version>
</properties>
<!-- ======================================================================= -->
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 03/50:
SLING-5825 - Add support for implicit conversion of Enum to String
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 7df537b18cef6660890d61a8c237390d9b986cf6
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Jul 8 11:20:36 2016 +0000
SLING-5825 - Add support for implicit conversion of Enum to String
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1751880 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/scripting/sightly/render/AbstractRuntimeObjectModel.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index aa42104..a55b21f 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -130,6 +130,8 @@ public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
output = (String) obj;
} else if (isPrimitive(obj)) {
output = obj.toString();
+ } else if (obj instanceof Enum) {
+ return ((Enum) obj).name();
} else {
Collection<?> col = obtainCollection(obj);
if (col != null) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 48/50:
releng: adjusted dependencies after staging release
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit c4e666e7c2a9b6235f5e5da18c2224b5f7b4ef54
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 15 07:35:21 2017 +0000
releng: adjusted dependencies after staging release
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1808429 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3b5734c..b891e9d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.14</version>
+ <version>1.0.15-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 22/50:
SLING-6186 - Add support for checking code coverage with jacoco
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit b64b190a90978bd5589135ebe0fed2398e65c8b3
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Tue Nov 1 16:30:23 2016 +0000
SLING-6186 - Add support for checking code coverage with jacoco
* allow the jacoco version to be configurable; also downgraded to 0.7.6
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1767517 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index a522534..19168bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,7 @@
</scm>
<properties>
- <sling.java.version>7</sling.java.version>
+ <jacoco.maven.plugin.version>0.7.6.201602180812</jacoco.maven.plugin.version>
</properties>
<!-- ======================================================================= -->
@@ -121,7 +121,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
- <version>0.7.7.201606060606</version>
+ <version>${jacoco.maven.plugin.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 46/50:
[maven-release-plugin] prepare release
org.apache.sling.scripting.sightly.compiler.java-1.0.14
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 663eb124b654fbb53bd03603c1bb0a7e654b995d
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Sep 15 07:25:20 2017 +0000
[maven-release-plugin] prepare release org.apache.sling.scripting.sightly.compiler.java-1.0.14
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1808422 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index d1d4dcf..3bc2432 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
<!-- P R O J E C T -->
<!-- ======================================================================= -->
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
- <version>1.0.13-SNAPSHOT</version>
+ <version>1.0.14</version>
<packaging>bundle</packaging>
<name>Apache Sling Scripting HTL Java Compiler</name>
@@ -42,9 +42,9 @@
</description>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</developerConnection>
- <url>http://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</developerConnection>
+ <url>http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.scripting.sightly.compiler.java-1.0.14</url>
</scm>
<properties>
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.13-SNAPSHOT</version>
+ <version>1.0.14</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.
[sling-org-apache-sling-scripting-sightly-compiler-java] 28/50:
update to next snapshot version until releases are available on maven
central
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git
commit 6a61604a9dda585369b30fc975cb08149e56311a
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Thu Dec 22 09:51:15 2016 +0000
update to next snapshot version until releases are available on maven central
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1775600 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c5a2e0a..0a98b8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,7 +156,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
- <version>1.0.4</version>
+ <version>1.0.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.