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/01 14:30:23 UTC
[groovy] 02/03: [GROOVY-9109] override the classloader with
different config
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
commit 0e14fb8af9fcbafc0902a31520257220bc948b2a
Author: Jan Lukavsky <je...@seznam.cz>
AuthorDate: Thu May 23 14:25:15 2019 +0200
[GROOVY-9109] override the classloader with different config
(cherry picked from commit 9ce87bc821e67a9a60300b88c62a0bed33219134)
---
src/main/groovy/groovy/lang/GroovyClassLoader.java | 12 ++++++++++--
src/main/groovy/groovy/lang/GroovyShell.java | 4 +++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/main/groovy/groovy/lang/GroovyClassLoader.java b/src/main/groovy/groovy/lang/GroovyClassLoader.java
index 6c440f9..0b31298 100644
--- a/src/main/groovy/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/groovy/lang/GroovyClassLoader.java
@@ -225,6 +225,14 @@ public class GroovyClassLoader extends URLClassLoader {
}
/**
+ * Retrieve configuration used by this class loader.
+ * @return CompilerConfiguration used by this classloader
+ */
+ public CompilerConfiguration getCompilerConfiguration() {
+ return config;
+ }
+
+ /**
* Parses the given file into a Java class capable of being run
*
* @param file the file name to parse
@@ -280,7 +288,7 @@ public class GroovyClassLoader extends URLClassLoader {
});
return parseClass(gcs);
}
-
+
/**
* @deprecated Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
* Use {@link #parseClass(Reader, String) parseClass} instead
@@ -922,7 +930,7 @@ public class GroovyClassLoader extends URLClassLoader {
private static File fileReallyExists(URL ret, String fileWithoutPackage) {
File path;
try {
- /* fix for GROOVY-5809 */
+ /* fix for GROOVY-5809 */
path = new File(ret.toURI());
} catch(URISyntaxException e) {
path = new File(decodeFileName(ret.getFile()));
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index ad109f5..cc947ab 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -95,7 +95,9 @@ public class GroovyShell extends GroovyObjectSupport {
throw new IllegalArgumentException("Compiler configuration must not be null.");
}
final ClassLoader parentLoader = (parent!=null)?parent:GroovyShell.class.getClassLoader();
- if (parentLoader instanceof GroovyClassLoader) {
+
+ if (parentLoader instanceof GroovyClassLoader
+ && ((GroovyClassLoader) parentLoader).getCompilerConfiguration() == config) {
this.loader = (GroovyClassLoader) parentLoader;
} else {
this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {