Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 849a275bc -> da1d02ce6
Closing the GroovyClassLoader is now realized by try-with-resources. (closes #595) Old Methode makeCompileUnit is added for API compatibility and marked as deprecated. (cherry picked from commit abfde7e) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/da1d02ce Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/da1d02ce Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/da1d02ce Branch: refs/heads/GROOVY_2_5_X Commit: da1d02ce668ebcbdb0cb3e4576736a42d79ab789 Parents: 77e6d13 Author: Marcus Berndt <marcus.ber...@data-experts.de> Authored: Fri Aug 25 14:17:49 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Thu Sep 14 08:28:10 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/da1d02ce/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); } } }