You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/02/11 19:11:59 UTC

[groovy] branch GROOVY-9392 created (now 6c07a02)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY-9392
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 6c07a02  GROOVY-9392: prevent recursive invocation in CompilerConfiguration

This branch includes the following new commits:

     new 6c07a02  GROOVY-9392: prevent recursive invocation in CompilerConfiguration

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: GROOVY-9392: prevent recursive invocation in CompilerConfiguration

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9392
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 6c07a02c590d88739275dfc439fc1064afbb9743
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Feb 11 12:59:27 2020 -0600

    GROOVY-9392: prevent recursive invocation in CompilerConfiguration
---
 .../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
+    }
 }