You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2016/06/16 16:08:00 UTC
svn commit: r1748750 [11/12] - in /sling/trunk/bundles/scripting/sightly: ./
compiler/ compiler/src/ compiler/src/main/ compiler/src/main/antlr4/
compiler/src/main/antlr4/org/ compiler/src/main/antlr4/org/apache/
compiler/src/main/antlr4/org/apache/sli...
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/operator/UnaryOpGen.java Thu Jun 16 16:07:57 2016
@@ -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);
+
+}
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/JavaEscapeUtils.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/JavaEscapeUtils.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/JavaEscapeUtils.java (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/impl/utils/JavaEscapeUtils.java Thu Jun 16 16:07:57 2016
@@ -5,16 +5,16 @@
* 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>
+ *
+ * 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.impl.utils;
+package org.apache.sling.scripting.sightly.java.compiler.impl.utils;
import java.util.HashSet;
import java.util.Set;
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/java/compiler/package-info.java Thu Jun 16 16:07:57 2016
@@ -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;
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/package-info.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/package-info.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/package-info.java Thu Jun 16 16:07:57 2016
@@ -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;
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/Use.java Thu Jun 16 16:07:57 2016
@@ -23,28 +23,25 @@ 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}
+ * 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="http://docs.adobe.com/docs/en/aem/6-0/develop/sightly.html#use">Sightly Block Statements - Use</a>
+ * @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 {
/**
- * Called to initialize the Java object with the current Java Scripting
- * API bindings.
* <p>
- * This method is called only if the object has been instantiated by
- * Sightly as part of processing the {@code data-sly-use} attribute.
- * <p>
- * The Java Scripting API bindings provide all the global variables
- * known to a script being executed. Consider these bindings of a map
- * from variable name to the variable's value.
+ * 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.
*/
- public void init(Bindings bindings);
+ void init(Bindings bindings);
}
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/pojo/package-info.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
(empty)
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/RenderUtils.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/RenderUtils.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/utils/RenderUtils.java (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java Thu Jun 16 16:07:57 2016
@@ -1,22 +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
+ * 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
+ * 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.
+ * 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.impl.utils;
+package org.apache.sling.scripting.sightly.render;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -34,90 +32,88 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
-import org.apache.sling.api.adapter.Adaptable;
-import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.scripting.sightly.Record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class RenderUtils {
+/**
+ * Default abstract implementation of {@link RuntimeObjectModel}.
+ */
+public abstract class AbstractRuntimeObjectModel implements RuntimeObjectModel {
- private static final Logger LOGGER = LoggerFactory.getLogger(RenderUtils.class);
-
- public static final String TO_STRING_METHOD = "toString";
- public static final String PROPERTY_ACCESS = "resolveProperty";
- public static final String COLLECTION_COERCE = "toCollection";
- public static final String NUMERIC_COERCE = "toNumber";
- public static final String STRING_COERCE = "toString";
- public static final String BOOLEAN_COERCE = "toBoolean";
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRuntimeObjectModel.class);
/**
- * 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
+ * A {@link Set} that stores all the supported primitive classes.
*/
- public static boolean isCollection(Object target) {
- return (target instanceof Collection) || (target instanceof Object[])
- || (target instanceof Iterable)
- || (target instanceof Iterator);
+ 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());
}
- /**
- * Coerce the object to a numeric value
- *
- * @param object - the target object
- * @return - the numeric representation
- */
- public static Number toNumber(Object object) {
+ @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;
}
- /**
- * Convert the given object to a string.
- *
- * @param target - the target object
- * @return - the string representation of the object
- */
- public static String toString(Object target) {
+ @Override
+ public String toString(Object target) {
return objectToString(target);
}
- /**
- * Convert the given object to a boolean value
- *
- * @param object - the target object
- * @return - the boolean representation of that object
- */
- public static boolean toBoolean(Object object) {
- return toBooleanInternal(object);
- }
-
- /**
- * Force the conversion of the object to a collection
- *
- * @param object - the target object
- * @return the collection representation of the object
- */
- public static Collection<Object> toCollection(Object object) {
+ @Override
+ public Collection<Object> toCollection(Object object) {
return obtainCollection(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
- */
- @SuppressWarnings("unchecked")
- public static Map toMap(Object 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<String, Object>();
+ 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));
@@ -127,25 +123,24 @@ public class RenderUtils {
return Collections.emptyMap();
}
- /**
- * 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
- */
- public static Object resolveProperty(Object target, Object property) {
- Object resolved;
- if (property instanceof Number) {
- resolved = getIndex(target, ((Number) property).intValue());
- } else {
- resolved = getProperty(target, property);
+ 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 resolved;
+ return output;
}
- private static Object getProperty(Object target, Object propertyObj) {
+ protected Object getProperty(Object target, Object propertyObj) {
String property = toString(propertyObj);
if (StringUtils.isEmpty(property)) {
throw new IllegalArgumentException("Invalid property name");
@@ -163,14 +158,11 @@ public class RenderUtils {
if (result == null) {
result = getObjectProperty(target, property);
}
- if (result == null && target instanceof Adaptable) {
- result = getValueMapProperty(((Adaptable) target).adaptTo(ValueMap.class), property);
- }
return result;
}
@SuppressWarnings("unchecked")
- private static Collection<Object> obtainCollection(Object obj) {
+ protected Collection<Object> obtainCollection(Object obj) {
if (obj == null) {
return Collections.emptyList();
}
@@ -204,22 +196,31 @@ public class RenderUtils {
return Collections.emptyList();
}
- private static Collection<Object> fromIterator(Iterator<Object> iterator) {
- ArrayList<Object> result = new ArrayList<Object>();
+ 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;
}
- private static boolean toBooleanInternal(Object obj) {
+ protected boolean toBooleanInternal(Object obj) {
if (obj == null) {
return false;
}
if (obj instanceof Number) {
Number number = (Number) obj;
- //todo should we consider precision issues?
return !(number.doubleValue() == 0.0);
}
@@ -249,7 +250,7 @@ public class RenderUtils {
return !(obj instanceof Object[]) || ((Object[]) obj).length > 0;
}
- private static Object getIndex(Object obj, int index) {
+ protected Object getIndex(Object obj, int index) {
if (obj instanceof Map) {
Map map = (Map) obj;
if (map.containsKey(index)) {
@@ -263,25 +264,18 @@ public class RenderUtils {
return null;
}
- private static Object getIndexSafe(List list, int index) {
+ protected Object getIndexSafe(List list, int index) {
if (index < 0 || index >= list.size()) {
return null;
}
return list.get(index);
}
- private static Object getValueMapProperty(ValueMap valueMap, String property) {
- if (valueMap == null) {
- return null;
- }
- return valueMap.get(property);
- }
-
- private static Object getMapProperty(Map map, String property) {
+ protected Object getMapProperty(Map map, String property) {
return map.get(property);
}
- private static Object getObjectProperty(Object obj, String property) {
+ protected Object getObjectProperty(Object obj, String property) {
Object result = getObjectNoArgMethod(obj, property);
if (result == null) {
result = getField(obj, property);
@@ -289,7 +283,7 @@ public class RenderUtils {
return result;
}
- private static Object getField(Object obj, String property) {
+ 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;
@@ -303,7 +297,7 @@ public class RenderUtils {
}
}
- private static Object getObjectNoArgMethod(Object obj, String property) {
+ protected Object getObjectNoArgMethod(Object obj, String property) {
Class<?> cls = obj.getClass();
Method method = findMethod(cls, property);
if (method != null) {
@@ -317,113 +311,59 @@ public class RenderUtils {
return null;
}
- private static Method findMethod(Class<?> cls, String baseName) {
+ 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)) {
-
+ 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;
}
- private static boolean isMethodAllowed(Method method) {
+ 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());
}
-
- private static 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;
- }
-
- private static final Set<Class<?>> primitiveClasses = primitiveClasses();
-
- public static boolean isPrimitive(Object obj) {
- return primitiveClasses.contains(obj.getClass());
- }
-
- private static String collectionToString(Collection<?> col) {
- StringBuilder builder = new StringBuilder();
- String prefix = "";
- for (Object o : col) {
- builder.append(prefix).append(objectToString(o));
- prefix = ",";
- }
- return builder.toString();
- }
-
- private static Set<Class<?>> primitiveClasses() {
- Set<Class<?>> set = new HashSet<Class<?>>();
- set.add(Boolean.class);
- set.add(Character.class);
- set.add(Byte.class);
- set.add(Short.class);
- set.add(Integer.class);
- set.add(Long.class);
- set.add(Float.class);
- set.add(Double.class);
- set.add(Void.class);
- return set;
- }
-
- private static Method extractMethodInheritanceChain(Class type, Method m) {
+ protected Method extractMethodInheritanceChain(Class type, Method m) {
if (m == null || Modifier.isPublic(type.getModifiers())) {
return m;
}
- Class[] inf = type.getInterfaces();
+ Class[] iFaces = type.getInterfaces();
Method mp;
- for (Class<?> iface : inf) {
- try {
- mp = iface.getMethod(m.getName(), m.getParameterTypes());
- mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp);
- if (mp != null) {
- return mp;
- }
- } catch (NoSuchMethodException e) {
- // do nothing
+ for (Class<?> iFace : iFaces) {
+ mp = getClassMethod(iFace, m);
+ if (mp != null) {
+ return mp;
}
}
- Class<?> sup = type.getSuperclass();
- if (sup != null) {
- try {
- mp = sup.getMethod(m.getName(), m.getParameterTypes());
- mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp);
- if (mp != null) {
- return mp;
- }
- } catch (NoSuchMethodException e) {
- // do nothing
+ 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;
}
+
}
+
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RenderContext.java Thu Jun 16 16:07:57 2016
@@ -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);
+}
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/RuntimeObjectModel.java Thu Jun 16 16:07:57 2016
@@ -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);
+}
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/package-info.java Thu Jun 16 16:07:57 2016
@@ -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;
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/ProviderOutcome.java Thu Jun 16 16:07:57 2016
@@ -16,11 +16,10 @@
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
-
package org.apache.sling.scripting.sightly.use;
/**
- * Result returned by a use provider
+ * Result returned by a {@link UseProvider}.
*/
public final class ProviderOutcome {
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/UseProvider.java Thu Jun 16 16:07:57 2016
@@ -22,17 +22,12 @@ package org.apache.sling.scripting.sight
import javax.script.Bindings;
import org.apache.sling.scripting.sightly.render.RenderContext;
-import org.osgi.framework.Constants;
import aQute.bnd.annotation.ConsumerType;
/**
* <p>
- * A {@code UseProvider} instantiates objects for the Use-API. Providers are queried in the descending order of their
- * {@link Constants#SERVICE_RANKING service ranking} until one is found which can provide a non-null instance.
- * </p>
- * <p>
- * The default value for the ranking if the property is missing is zero.
+ * A {@code UseProvider} instantiates objects for the Use-API.
* </p>
*/
@ConsumerType
@@ -43,9 +38,9 @@ public interface UseProvider {
*
* @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
+ * @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);
}
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/use/package-info.java&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
(empty)
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/compiled_unit_template.txt (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/compiled_unit_template.txt)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/compiled_unit_template.txt?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/compiled_unit_template.txt&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/compiled_unit_template.txt&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/compiled_unit_template.txt (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/compiled_unit_template.txt Thu Jun 16 16:07:57 2016
@@ -22,9 +22,8 @@ import java.io.PrintWriter;
import java.util.Collection;
import javax.script.Bindings;
-import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderUnit;
-import org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl;
-import org.apache.sling.scripting.sightly.impl.utils.RenderUtils;
+import org.apache.sling.scripting.sightly.java.compiler.RenderUnit;
+import org.apache.sling.scripting.sightly.render.RenderContext;
public final class ##ClassName## extends RenderUnit {
@@ -32,7 +31,7 @@ public final class ##ClassName## extends
protected final void render(PrintWriter out,
Bindings bindings,
Bindings arguments,
- RenderContextImpl renderContext) {
+ RenderContext renderContext) {
// Main Template Body -----------------------------------------------------------------------------
##MainBody##
Copied: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/subtemplate.txt (from r1748726, sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/subtemplate.txt)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/subtemplate.txt?p2=sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/subtemplate.txt&p1=sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/subtemplate.txt&r1=1748726&r2=1748750&rev=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/resources/templates/subtemplate.txt (original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/resources/templates/subtemplate.txt Thu Jun 16 16:07:57 2016
@@ -22,7 +22,7 @@ addSubTemplate("##Name##", new RenderUni
protected final void render(PrintWriter out,
Bindings bindings,
Bindings arguments,
- RenderContextImpl renderContext) {
+ RenderContext renderContext) {
// Main Sub-Template Body -------------------------------------------------------------------------
##MainBody##
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/JavaClassBackendCompilerTest.java Thu Jun 16 16:07:57 2016
@@ -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());
+
+ }
+}
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompiler.java Thu Jun 16 16:07:57 2016
@@ -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);
+ }
+}
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/CharSequenceJavaCompilerException.java Thu Jun 16 16:07:57 2016
@@ -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);
+ }
+}
+
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/java/org/apache/sling/scripting/sightly/compiler/java/utils/TestUtils.java Thu Jun 16 16:07:57 2016
@@ -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;
+ }
+ };
+ }
+}
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test-output.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test-output.html?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test-output.html (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test-output.html Thu Jun 16 16:07:57 2016
@@ -0,0 +1,23 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<ul>
+ <li>1</li>
+
+ <li>2</li>
+
+ <li>3</li>
+</ul>
Added: sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test.html?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test.html (added)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/test/resources/test.html Thu Jun 16 16:07:57 2016
@@ -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>
Modified: sling/trunk/bundles/scripting/sightly/js-use-provider/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/js-use-provider/pom.xml?rev=1748750&r1=1748749&r2=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/js-use-provider/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/js-use-provider/pom.xml Thu Jun 16 16:07:57 2016
@@ -117,7 +117,19 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly</artifactId>
- <version>1.0.2</version>
+ <version>1.0.19-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Modified: sling/trunk/bundles/scripting/sightly/models-use-provider/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/models-use-provider/pom.xml?rev=1748750&r1=1748749&r2=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/models-use-provider/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/models-use-provider/pom.xml Thu Jun 16 16:07:57 2016
@@ -99,8 +99,8 @@
<!-- Sightly -->
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.scripting.sightly</artifactId>
- <version>1.0.0</version>
+ <artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Modified: sling/trunk/bundles/scripting/sightly/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/pom.xml?rev=1748750&r1=1748749&r2=1748750&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/pom.xml Thu Jun 16 16:07:57 2016
@@ -50,6 +50,8 @@
</scm>
<modules>
+ <module>compiler</module>
+ <module>java-compiler</module>
<module>engine</module>
<module>js-use-provider</module>
<module>models-use-provider</module>
Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/update/update.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/update/update.html?rev=1748750&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/update/update.html (added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/update/update.html Thu Jun 16 16:07:57 2016
@@ -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 id="update" data-sly-text="${'Hello world!'}">replace me!</div>