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 2019/08/08 23:16:50 UTC
[groovy] branch GROOVY_2_5_X updated: Console,
GroovyMain and Groovysh (via its Main) use context class loader
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 52b4c60 Console, GroovyMain and Groovysh (via its Main) use context class loader
52b4c60 is described below
commit 52b4c608d027b47cac32af7b873290940cbf1ef5
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Aug 8 17:01:02 2019 -0500
Console, GroovyMain and Groovysh (via its Main) use context class loader
- All: pass system properties to new CompilerConfiguration instances
- Console: use default parameters to reduce constructor variants
(Clone of 93bebbe140846117cf16127360217dac1d13f5fc)
---
src/main/groovy/groovy/ui/GroovyMain.java | 4 ++--
.../src/main/groovy/groovy/ui/Console.groovy | 20 ++++----------------
.../org/codehaus/groovy/tools/shell/Main.groovy | 6 +-----
3 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/src/main/groovy/groovy/ui/GroovyMain.java b/src/main/groovy/groovy/ui/GroovyMain.java
index 699e5c0..af029d3 100644
--- a/src/main/groovy/groovy/ui/GroovyMain.java
+++ b/src/main/groovy/groovy/ui/GroovyMain.java
@@ -479,7 +479,7 @@ public class GroovyMain {
* Process the input files.
*/
private void processFiles() throws CompilationFailedException, IOException, URISyntaxException {
- GroovyShell groovy = new GroovyShell(conf);
+ GroovyShell groovy = new GroovyShell(Thread.currentThread().getContextClassLoader(), conf);
setupContextClassLoader(groovy);
Script s = groovy.parse(getScriptSource(isScriptFile, script));
@@ -587,7 +587,7 @@ public class GroovyMain {
* Process the standard, single script with args.
*/
private void processOnce() throws CompilationFailedException, IOException, URISyntaxException {
- GroovyShell groovy = new GroovyShell(conf);
+ GroovyShell groovy = new GroovyShell(Thread.currentThread().getContextClassLoader(), conf);
setupContextClassLoader(groovy);
groovy.run(getScriptSource(isScriptFile, script), args);
}
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
index 200646a..0f49c2c 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
@@ -244,7 +244,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
//when starting via main set the look and feel to system
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
- def baseConfig = new CompilerConfiguration()
+ def baseConfig = new CompilerConfiguration(System.getProperties())
String starterConfigScripts = System.getProperty("groovy.starter.configscripts", null)
if (options.configscript || (starterConfigScripts != null && !starterConfigScripts.isEmpty())) {
List<String> configScripts = new ArrayList<String>()
@@ -263,7 +263,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
enableIndy(baseConfig)
}
- def console = new Console(Console.class.classLoader?.getRootLoader(), new Binding(), baseConfig)
+ def console = new Console(Thread.currentThread().contextClassLoader, new Binding(), baseConfig)
console.useScriptClassLoaderForScriptExecution = true
console.run()
def remaining = options.arguments()
@@ -312,23 +312,11 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
}
}
- Console() {
- this(new Binding())
- }
-
- Console(Binding binding) {
+ Console(Binding binding = new Binding()) {
this(null, binding)
}
- Console(ClassLoader parent) {
- this(parent, new Binding())
- }
-
- Console(ClassLoader parent, Binding binding) {
- this(parent, binding, new CompilerConfiguration())
- }
-
- Console(ClassLoader parent, Binding binding, CompilerConfiguration baseConfig) {
+ Console(ClassLoader parent, Binding binding = new Binding(), CompilerConfiguration baseConfig = new CompilerConfiguration(System.getProperties())) {
this.baseConfig = baseConfig
this.maxOutputChars = loadMaxOutputChars()
indy = indy || isIndyEnabled(baseConfig)
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
index 462dd35..8957a67 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
@@ -65,10 +65,6 @@ class Main {
groovysh = new Groovysh(io, configuration)
}
- Groovysh getGroovysh() {
- return groovysh
- }
-
/**
* create a Main instance, configures it according to CLI arguments, and starts the shell.
* @param main must have a Groovysh member that has an IO member.
@@ -151,7 +147,7 @@ class Main {
if (options.e) {
evalString = options.getOptionValue('e')
}
- def configuration = new CompilerConfiguration()
+ def configuration = new CompilerConfiguration(System.getProperties())
configuration.setParameters((boolean) options.hasOption("pa"))
List<String> filenames = options.arguments()