This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.scripting.java-2.0.10 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-java.git
commit fdd2bb512d709d33e1cae36f2a46389e866d0b83 Author: Carsten Ziegeler <[email protected]> AuthorDate: Tue Jul 1 16:14:51 2014 +0000 SLING-3724 : Provide option to always use current vm version for source and target git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/java@1607130 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/scripting/java/impl/CompilerOptions.java | 12 ++++++++++-- .../sling/scripting/java/impl/JavaScriptEngineFactory.java | 5 +++-- .../apache/sling/scripting/java/impl/JavaServletConfig.java | 11 ++++++++--- src/main/resources/OSGI-INF/metatype/metatype.properties | 7 +++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/sling/scripting/java/impl/CompilerOptions.java b/src/main/java/org/apache/sling/scripting/java/impl/CompilerOptions.java index 7e937f7..94019c9 100644 --- a/src/main/java/org/apache/sling/scripting/java/impl/CompilerOptions.java +++ b/src/main/java/org/apache/sling/scripting/java/impl/CompilerOptions.java @@ -26,6 +26,8 @@ public class CompilerOptions extends Options { private String encoding; + private static final String VERSION_AUTO = "auto"; + /** * Create an compiler options object using data available from * the component configuration. @@ -37,10 +39,16 @@ public class CompilerOptions extends Options { opts.put(Options.KEY_GENERATE_DEBUG_INFO, classDebugInfo != null ? classDebugInfo : true); final String sourceVM = (String) props.get(JavaScriptEngineFactory.PROPERTY_COMPILER_SOURCE_V_M); - opts.put(Options.KEY_SOURCE_VERSION, sourceVM != null && sourceVM.length() > 0 ? sourceVM : JavaScriptEngineFactory.DEFAULT_VM_VERSION); + opts.put(Options.KEY_SOURCE_VERSION, sourceVM != null && sourceVM.trim().length() > 0 ? sourceVM.trim() : JavaScriptEngineFactory.DEFAULT_VM_VERSION); + if ( VERSION_AUTO.equalsIgnoreCase((String)opts.get(Options.KEY_SOURCE_VERSION)) ) { + opts.put(Options.KEY_SOURCE_VERSION, System.getProperty("java.vm.specification.version")); + } final String targetVM = (String) props.get(JavaScriptEngineFactory.PROPERTY_COMPILER_TARGET_V_M); - opts.put(Options.KEY_TARGET_VERSION, targetVM != null && targetVM.length() > 0 ? targetVM : JavaScriptEngineFactory.DEFAULT_VM_VERSION); + opts.put(Options.KEY_TARGET_VERSION, targetVM != null && targetVM.trim().length() > 0 ? targetVM.trim() : JavaScriptEngineFactory.DEFAULT_VM_VERSION); + if ( VERSION_AUTO.equalsIgnoreCase((String)opts.get(Options.KEY_TARGET_VERSION)) ) { + opts.put(Options.KEY_TARGET_VERSION, System.getProperty("java.vm.specification.version")); + } final String encoding = (String) props.get(JavaScriptEngineFactory.PROPERTY_ENCODING); opts.encoding = encoding != null && encoding.length() > 0 ? encoding : "UTF-8"; diff --git a/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java b/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java index e6b662a..e2149d3 100644 --- a/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java +++ b/src/main/java/org/apache/sling/scripting/java/impl/JavaScriptEngineFactory.java @@ -80,8 +80,8 @@ public class JavaScriptEngineFactory public static final String PROPERTY_ENCODING = "java.javaEncoding"; - /** Default source and target VM version (value is "1.5"). */ - public static final String DEFAULT_VM_VERSION = "1.5"; + /** Default source and target VM version (value is "1.6"). */ + public static final String DEFAULT_VM_VERSION = "1.6"; @Reference private JavaCompiler javaCompiler; @@ -130,6 +130,7 @@ public class JavaScriptEngineFactory /** * @see javax.script.ScriptEngineFactory#getParameter(String) */ + @Override public Object getParameter(String name) { if ("THREADING".equals(name)) { return "STATELESS"; diff --git a/src/main/java/org/apache/sling/scripting/java/impl/JavaServletConfig.java b/src/main/java/org/apache/sling/scripting/java/impl/JavaServletConfig.java index 9949098..278c9c4 100644 --- a/src/main/java/org/apache/sling/scripting/java/impl/JavaServletConfig.java +++ b/src/main/java/org/apache/sling/scripting/java/impl/JavaServletConfig.java @@ -56,10 +56,15 @@ public class JavaServletConfig implements ServletConfig { // copy the "java." properties initParams = new HashMap<String, String>(); for (Enumeration<?> ke = config.keys(); ke.hasMoreElements();) { - String key = (String) ke.nextElement(); + final String key = (String) ke.nextElement(); if (key.startsWith("java.")) { - initParams.put(key.substring("java.".length()), - String.valueOf(config.get(key))); + final Object value = config.get(key); + if ( value != null ) { + final String strValue = String.valueOf(value).trim(); + if ( strValue.length() > 0 ) { + initParams.put(key.substring("java.".length()), strValue); + } + } } } } diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties index b5de3a5..80fc269 100644 --- a/src/main/resources/OSGI-INF/metatype/metatype.properties +++ b/src/main/resources/OSGI-INF/metatype/metatype.properties @@ -36,8 +36,11 @@ java.javaEncoding.description = Encoding to be used to read the source files. \ java.compilerSourceVM.name = Source VM java.compilerSourceVM.description = Java Specification to be used to read \ - the source files. + the source files. If left empty, the default version, 1.6., is used. If the \ + value "auto" is used, the current vm version will be used. java.compilerTargetVM.name = Target VM -java.compilerTargetVM.description = Target Java version for compilation. +java.compilerTargetVM.description = Target Java version for compilation. If left \ + empty, the default version, 1.6., is used. If the value "auto" is used, the current \ + vm version will be used. \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
