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/77e6d138 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/77e6d138 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/77e6d138 Branch: refs/heads/GROOVY_2_5_X Commit: 77e6d138adfaf9cc6dba5a95b99a824611e8189d Parents: 849a275 Author: Marcus Berndt <marcus.ber...@data-experts.de> Authored: Wed Aug 23 17:07:24 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Thu Sep 14 08:28:10 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/77e6d138/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)); } } }