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 2017/09/14 00:16:15 UTC

[1/2] groovy git commit: Groovyc did not correctly release resources hold by GroovyClassLoader.

Repository: groovy
Updated Branches:
  refs/heads/master 8ad6e770a -> abfde7ef5


Groovyc did not correctly release resources hold by GroovyClassLoader.


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

Branch: refs/heads/master
Commit: 4e3ee3cb0ebdc11b5bbfef5be9040b28593463f9
Parents: 8ad6e77
Author: Marcus Berndt <ma...@data-experts.de>
Authored: Wed Aug 23 11:07:24 2017 +0200
Committer: sunlan <su...@apache.org>
Committed: Thu Sep 14 08:13:13 2017 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/ant/Groovyc.java   | 27 +++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4e3ee3cb/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index 3a15cd3..4d4ffb2 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -1195,7 +1195,13 @@ public class Groovyc extends MatchingTask {
             }
 
             if (!fileNameErrors) {
-                FileSystemCompiler.doCompilation(configuration, makeCompileUnit(), filenames, forceLookupUnnamedFiles);
+              GroovyClassLoader loader = buildClassLoaderFor();
+              try {
+                FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), filenames, forceLookupUnnamedFiles);
+              } finally {
+                if (loader != null)
+                  loader.close();
+              }
             }
 
         } catch (Exception re) {
@@ -1259,7 +1265,7 @@ public class Groovyc extends MatchingTask {
         }
     }
 
-    protected CompilationUnit makeCompileUnit() {
+    protected CompilationUnit makeCompileUnit(GroovyClassLoader loader) {
         Map<String, Object> options = configuration.getJointCompilationOptions();
         if (options != null) {
             if (keepStubs) {
@@ -1276,9 +1282,9 @@ public class Groovyc extends MatchingTask {
                     throw new BuildException(ioe);
                 }
             }
-            return new JavaAwareCompilationUnit(configuration, buildClassLoaderFor());
+            return new JavaAwareCompilationUnit(configuration, loader);
         } else {
-            return new CompilationUnit(configuration, null, buildClassLoaderFor());
+            return new CompilationUnit(configuration, null, loader);
         }
     }
 
@@ -1347,10 +1353,19 @@ public class Groovyc extends MatchingTask {
             Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
             final String[] pe = classpath.list();
             final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
-            for (String file : pe) {
+            try {
+              for (String file : pe) {
                 loader.addClasspath(file);
+              }
+              scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
+            } finally {
+              try {
+                loader.close();
+              }
+              catch ( IOException e ) {
+                throw new RuntimeException( e );
+              }
             }
-            scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
         }
     }
 }


[2/2] groovy git commit: Closing the GroovyClassLoader is now realized by try-with-resources. (closes #595)

Posted by su...@apache.org.
Closing the GroovyClassLoader is now realized by
try-with-resources. (closes #595)

Old Methode makeCompileUnit is added for API compatibility and marked as deprecated.


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

Branch: refs/heads/master
Commit: abfde7ef53d5d2185a53e5d43c16214691f0266e
Parents: 4e3ee3c
Author: Marcus Berndt <ma...@data-experts.de>
Authored: Fri Aug 25 08:17:49 2017 +0200
Committer: sunlan <su...@apache.org>
Committed: Thu Sep 14 08:13:44 2017 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/ant/Groovyc.java   | 59 ++++++++++----------
 1 file changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/abfde7ef/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index 4d4ffb2..d69dcb4 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -291,7 +291,7 @@ public class Groovyc extends MatchingTask {
      * @param version the bytecode compatibility mode
      */
     public void setTargetBytecode(String version) {
-        
+
         for (String allowedJdk : CompilerConfiguration.ALLOWED_JDKS) {
             if (allowedJdk.equals(version)) {
                 this.targetBytecode = version;
@@ -304,8 +304,8 @@ public class Groovyc extends MatchingTask {
      * Retrieves the compiler bytecode compatibility mode.
      *
      * @return bytecode compatibility mode. Can be one of the values
-     *         <tt>1.8</tt>, <tt>1.7</tt>, <tt>1.6</tt>, <tt>1.5</tt> or
-     *         <tt>1.4</tt>.
+     * <tt>1.8</tt>, <tt>1.7</tt>, <tt>1.6</tt>, <tt>1.5</tt> or
+     * <tt>1.4</tt>.
      */
     public String getTargetBytecode() {
         return this.targetBytecode;
@@ -666,7 +666,7 @@ public class Groovyc extends MatchingTask {
      * Get the result of the groovyc task (success or failure).
      *
      * @return true if compilation succeeded, or
-     *         was not necessary, false if the compilation failed.
+     * was not necessary, false if the compilation failed.
      */
     public boolean getTaskSuccess() {
         return taskSuccess;
@@ -786,7 +786,7 @@ public class Groovyc extends MatchingTask {
 
     /**
      * Set the forceLookupUnnamedFiles flag. Defaults to false.
-     *
+     * <p>
      * The Groovyc Ant task is frequently used in the context of a build system
      * that knows the complete list of source files to be compiled. In such a
      * context, it is wasteful for the Groovy compiler to go searching the
@@ -1195,13 +1195,9 @@ public class Groovyc extends MatchingTask {
             }
 
             if (!fileNameErrors) {
-              GroovyClassLoader loader = buildClassLoaderFor();
-              try {
-                FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), filenames, forceLookupUnnamedFiles);
-              } finally {
-                if (loader != null)
-                  loader.close();
-              }
+                try (GroovyClassLoader loader = buildClassLoaderFor()) {
+                    FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), filenames, forceLookupUnnamedFiles);
+                }
             }
 
         } catch (Exception re) {
@@ -1265,6 +1261,14 @@ public class Groovyc extends MatchingTask {
         }
     }
 
+    /**
+     * @deprecated This method is not in use anymore. Use {@link Groovyc#makeCompileUnit(GroovyClassLoader)} instead.
+     */
+    @Deprecated
+    protected CompilationUnit makeCompileUnit() {
+        return makeCompileUnit(buildClassLoaderFor());
+    }
+
     protected CompilationUnit makeCompileUnit(GroovyClassLoader loader) {
         Map<String, Object> options = configuration.getJointCompilationOptions();
         if (options != null) {
@@ -1319,12 +1323,11 @@ public class Groovyc extends MatchingTask {
                  * may not exist in the classpath yet
                  */
                 if (!found && new File(cpEntry).exists()) {
-                	try {
-                		antLoader.addPathElement(cpEntry);
-                	}
-                	catch(BuildException e) {
-                		log.warn("The classpath entry " + cpEntry + " is not a valid Java resource");
-                	}
+                    try {
+                        antLoader.addPathElement(cpEntry);
+                    } catch (BuildException e) {
+                        log.warn("The classpath entry " + cpEntry + " is not a valid Java resource");
+                    }
                 }
             }
         }
@@ -1352,19 +1355,13 @@ public class Groovyc extends MatchingTask {
 
             Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
             final String[] pe = classpath.list();
-            final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
-            try {
-              for (String file : pe) {
-                loader.addClasspath(file);
-              }
-              scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
-            } finally {
-              try {
-                loader.close();
-              }
-              catch ( IOException e ) {
-                throw new RuntimeException( e );
-              }
+            try (GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader())) {
+                for (String file : pe) {
+                    loader.addClasspath(file);
+                }
+                scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
+            } catch (IOException e) {
+                throw new RuntimeException(e);
             }
         }
     }