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:29:37 UTC

groovy git commit: Groovyc did not correctly release resources hold by GroovyClassLoader.

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 1c395602e -> 8ff366f25


Groovyc did not correctly release resources hold by GroovyClassLoader.

(cherry picked from commit 4e3ee3c)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 8ff366f25dc30c5e3ef926b5bde1cb71ec24ab27
Parents: 1c395602
Author: Marcus Berndt <ma...@data-experts.de>
Authored: Wed Aug 23 17:07:24 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Thu Sep 14 08:29:33 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/8ff366f2/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 594dd40..c17b4ff 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
@@ -1162,7 +1162,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) {
@@ -1226,7 +1232,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) {
@@ -1243,9 +1249,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);
         }
     }
 
@@ -1314,10 +1320,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));
         }
     }
 }