Repository: groovy
Updated Branches:
  refs/heads/master ae2bc0c6e -> 51bf34224


Minor refactoring


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/51bf3422
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/51bf3422
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/51bf3422

Branch: refs/heads/master
Commit: 51bf34224c3fc54fe26568486d7c0144d49cb851
Parents: ae2bc0c
Author: sunlan <[email protected]>
Authored: Thu Dec 7 13:32:51 2017 +0800
Committer: sunlan <[email protected]>
Committed: Thu Dec 7 13:32:51 2017 +0800

----------------------------------------------------------------------
 src/main/groovy/lang/GroovyClassLoader.java | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/51bf3422/src/main/groovy/lang/GroovyClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/GroovyClassLoader.java 
b/src/main/groovy/lang/GroovyClassLoader.java
index a64cf48..af01538 100644
--- a/src/main/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/lang/GroovyClassLoader.java
@@ -103,6 +103,7 @@ public class GroovyClassLoader extends URLClassLoader {
      */
     protected final Map<String, Class> sourceCache = new HashMap<String, 
Class>();
     private final CompilerConfiguration config;
+    private String sourceEncoding;
     private Boolean recompile;
     // use 1000000 as offset to avoid conflicts with names form the GroovyShell
     private static int scriptNameCounter = 1000000;
@@ -164,6 +165,17 @@ public class GroovyClassLoader extends URLClassLoader {
                 this.addClasspath(path);
             }
         }
+
+        initSourceEncoding(config);
+    }
+
+    private void initSourceEncoding(CompilerConfiguration config) {
+        sourceEncoding = config.getSourceEncoding();
+        if (null ==  sourceEncoding) {
+            // Keep the same default source encoding with the one used by 
#parseClass(InputStream, String)
+            // TODO should we use 
org.codehaus.groovy.control.CompilerConfiguration.DEFAULT_SOURCE_ENCODING 
instead?
+            sourceEncoding = CharsetToolkit.getDefaultSystemCharset().name();
+        }
     }
 
     /**
@@ -797,12 +809,6 @@ public class GroovyClassLoader extends URLClassLoader {
         if (source != null) {
             // found a source, compile it if newer
             if ((oldClass != null && isSourceNewer(source, oldClass)) || 
(oldClass == null)) {
-                String sourceEncoding = config.getSourceEncoding();
-                if (null ==  sourceEncoding) {
-                    // Keep the same default source encoding with the one used 
by #parseClass(InputStream, String)
-                    // TODO should we use 
org.codehaus.groovy.control.CompilerConfiguration.DEFAULT_SOURCE_ENCODING 
instead?
-                    sourceEncoding = 
CharsetToolkit.getDefaultSystemCharset().name();
-                }
                 synchronized (sourceCache) {
                     String name = source.toExternalForm();
                     sourceCache.remove(name);

Reply via email to