groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/2] groovy git commit: Minor refactoring
Date Thu, 07 Dec 2017 06:57:43 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X b54a63dd8 -> 2de8e1dc3


Minor refactoring

(cherry picked from commit 51bf342)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 2de8e1dc340a25f74e7a439c98d308c271b35552
Parents: ac12287
Author: sunlan <sunlan@apache.org>
Authored: Thu Dec 7 13:32:51 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Dec 7 14:57:39 2017 +0800

----------------------------------------------------------------------
 src/main/groovy/lang/GroovyClassLoader.java       | 18 ++++++++++++------
 .../groovy/control/CompilerConfiguration.java     |  7 +++----
 2 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2de8e1dc/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);

http://git-wip-us.apache.org/repos/asf/groovy/blob/2de8e1dc/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
index 4c6c6dc..ba10123 100644
--- a/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -263,10 +263,9 @@ public class CompilerConfiguration {
         try {
             String groovyAntlr4Opt = System.getProperty(GROOVY_ANTLR4_OPT);
 
-            this.parserVersion =
-                    null == groovyAntlr4Opt || Boolean.valueOf(groovyAntlr4Opt)
-                            ? ParserVersion.V_4
-                            : ParserVersion.V_2;
+            this.parserVersion = !Boolean.valueOf(groovyAntlr4Opt)
+                            ? ParserVersion.V_2
+                            : ParserVersion.V_4;
         } catch (Exception e) {
             // IGNORE
         }


Mime
View raw message