You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/02/12 05:10:52 UTC
[groovy] branch master updated: GROOVY-9392: prevent recursive
invocation in CompilerConfiguration (closes #1163)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 5648225 GROOVY-9392: prevent recursive invocation in CompilerConfiguration (closes #1163)
5648225 is described below
commit 564822566229bdb7b345641a7053dc11825519c4
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Feb 11 12:59:27 2020 -0600
GROOVY-9392: prevent recursive invocation in CompilerConfiguration (closes #1163)
---
.../groovy/control/CompilerConfiguration.java | 8 +--
src/test/groovy/execute/ExecuteTest.groovy | 63 +++++++++++++++-------
2 files changed, 47 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 0c1f16e..f7e888ec 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -426,10 +426,10 @@ public class CompilerConfiguration {
warningLevel = WarningMessage.LIKELY_ERRORS;
parameters = getBooleanSafe("groovy.parameters");
previewFeatures = getBooleanSafe("groovy.preview.features");
+ sourceEncoding = getSystemPropertySafe("groovy.source.encoding",
+ getSystemPropertySafe("file.encoding", DEFAULT_SOURCE_ENCODING));
setTargetDirectorySafe(getSystemPropertySafe("groovy.target.directory"));
setTargetBytecodeIfValid(getSystemPropertySafe("groovy.target.bytecode", JDK8));
- sourceEncoding = Optional.ofNullable(getSystemPropertySafe("groovy.source.encoding"))
- .orElseGet(() -> getSystemPropertySafe("file.encoding", DEFAULT_SOURCE_ENCODING));
defaultScriptExtension = getSystemPropertySafe("groovy.default.scriptExtension", ".groovy");
optimizationOptions = new HashMap<>(4);
@@ -712,10 +712,6 @@ public class CompilerConfiguration {
* Sets the encoding to be used when reading source files.
*/
public void setSourceEncoding(final String encoding) {
- setSourceEncodingOrDefault(encoding);
- }
-
- private void setSourceEncodingOrDefault(final String encoding) {
this.sourceEncoding = Optional.ofNullable(encoding).orElse(DEFAULT_SOURCE_ENCODING);
}
diff --git a/src/test/groovy/execute/ExecuteTest.groovy b/src/test/groovy/execute/ExecuteTest.groovy
index 53c88e1..f707ca3 100644
--- a/src/test/groovy/execute/ExecuteTest.groovy
+++ b/src/test/groovy/execute/ExecuteTest.groovy
@@ -25,7 +25,8 @@ import static groovy.test.GroovyAssert.isAtLeastJdk
/**
* Cross platform tests for the DGM#execute() family of methods.
*/
-class ExecuteTest extends GroovyTestCase {
+final class ExecuteTest extends GroovyTestCase {
+
private String getCmd() {
def cmd = "ls -l"
if (System.properties.'os.name'.startsWith('Windows ')) {
@@ -123,28 +124,54 @@ class ExecuteTest extends GroovyTestCase {
}
void testExecuteCommandLineWithEnvironmentProperties() {
- List<String> javaArgs = [System.getProperty('java.home') + "/bin/java",
- "-classpath",
+ List<String> java = [
+ System.getProperty('java.home') + '/bin/java',
+ '-classpath',
System.getProperty('java.class.path'),
- "groovy.ui.GroovyMain",
- "-e",
- "println(System.getenv('foo'))"]
+ 'groovy.ui.GroovyMain',
+ '-e',
+ "println(System.getenv('foo'))"
+ ]
// jaxb deprecated in 9, gone in 11
if (isAtLeastJdk('9.0') && !isAtLeastJdk('11.0')) {
- javaArgs.add(3, '--add-modules')
- javaArgs.add(4, 'java.xml.bind')
+ java.add(3, '--add-modules')
+ java.add(4, 'java.xml.bind')
}
- String[] java = javaArgs.toArray()
+
println "Executing this command:\n${java.join(' ')}"
- def props = ["foo=bar"]
- StringBuffer sbout = new StringBuffer()
- StringBuffer sberr = new StringBuffer()
- def process = java.execute(props, null)
- process.waitForProcessOutput sbout, sberr
- def value = process.exitValue()
- int count = sbout.toString().readLines().size()
- assert sbout.toString().contains('bar')
- assert value == 0
+ def process = java.execute(['foo=bar'], null)
+ def out = new StringBuffer()
+ def err = new StringBuffer()
+ process.waitForProcessOutput(out, err)
+
+ assert out.toString().contains('bar')
+ assert process.exitValue() == 0
}
+ // GROOVY-9392
+ void testExecuteCommandLineProcessWithGroovySystemClassLoader() {
+ List<String> java = [
+ System.getProperty('java.home') + '/bin/java',
+ '-classpath',
+ System.getProperty('java.class.path'),
+ '-Djava.system.class.loader=groovy.lang.GroovyClassLoader',
+ 'groovy.ui.GroovyMain',
+ '-e',
+ "println('hello')"
+ ]
+ // jaxb deprecated in 9, gone in 11
+ if (isAtLeastJdk('9.0') && !isAtLeastJdk('11.0')) {
+ java.add(3, '--add-modules')
+ java.add(4, 'java.xml.bind')
+ }
+
+ println "Executing this command:\n${java.join(' ')}"
+ def process = java.execute()
+ def out = new StringBuffer()
+ def err = new StringBuffer()
+ process.waitForProcessOutput(out, err)
+
+ assert out.toString().startsWith('hello')
+ assert process.exitValue() == 0
+ }
}