You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/10/05 15:02:45 UTC
[groovy] branch danielsun/tweak-defaultTargetBytecodeVersion
created (now 2f4d727)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch danielsun/tweak-defaultTargetBytecodeVersion
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at 2f4d727 Set target bytecode by JDK
This branch includes the following new commits:
new 2f4d727 Set target bytecode by JDK
The 1 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.
[groovy] 01/01: Set target bytecode by JDK
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/tweak-defaultTargetBytecodeVersion
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2f4d7276a533255a068a5069bcc946ac2017dc8d
Author: Daniel Sun <su...@apache.org>
AuthorDate: Tue Oct 5 23:02:07 2021 +0800
Set target bytecode by JDK
---
.../org/codehaus/groovy/control/CompilerConfiguration.java | 11 ++++++++++-
.../java/org/codehaus/groovy/vmplugin/VMPluginFactory.java | 6 +++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index fa366a5..4f1e363 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.groovy.util.Maps;
import org.codehaus.groovy.control.customizers.CompilationCustomizer;
import org.codehaus.groovy.control.io.NullWriter;
import org.codehaus.groovy.control.messages.WarningMessage;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
import org.objectweb.asm.Opcodes;
import java.io.File;
@@ -465,7 +466,7 @@ public class CompilerConfiguration {
sourceEncoding = getSystemPropertySafe("groovy.source.encoding",
getSystemPropertySafe("file.encoding", DEFAULT_SOURCE_ENCODING));
setTargetDirectorySafe(getSystemPropertySafe("groovy.target.directory"));
- setTargetBytecodeIfValid(getSystemPropertySafe("groovy.target.bytecode", JDK8));
+ setTargetBytecodeIfValid(getSystemPropertySafe("groovy.target.bytecode", defaultTargetBytecode()));
defaultScriptExtension = getSystemPropertySafe("groovy.default.scriptExtension", ".groovy");
optimizationOptions = new HashMap<>(4);
@@ -475,6 +476,14 @@ public class CompilerConfiguration {
handleOptimizationOption(PARALLEL_PARSE, getSystemPropertySafe("groovy.parallel.parse", "true"));
}
+ private static String defaultTargetBytecode() {
+ final String javaVersion = VMPluginFactory.getJavaVersion();
+ if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(javaVersion)) {
+ return javaVersion;
+ }
+ return JDK8;
+ }
+
private void handleOptimizationOption(String key, String val) {
if (val != null) optimizationOptions.put(key, Boolean.valueOf(val));
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
index d3ac172..0e0adde 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
@@ -57,7 +57,7 @@ public class VMPluginFactory {
private static VMPlugin createPlugin() {
return AccessController.doPrivileged((PrivilegedAction<VMPlugin>) () -> {
- final BigDecimal specVer = new BigDecimal(System.getProperty("java.specification.version"));
+ final BigDecimal specVer = new BigDecimal(getJavaVersion());
ClassLoader loader = VMPluginFactory.class.getClassLoader();
for (Map.Entry<BigDecimal, String> entry : PLUGIN_MAP.entrySet()) {
if (isAtLeast(specVer, entry.getKey())) {
@@ -78,4 +78,8 @@ public class VMPluginFactory {
return null;
});
}
+
+ public static String getJavaVersion() {
+ return System.getProperty("java.specification.version");
+ }
}