diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java index 9c03be6a87..c0efe783ec 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -361,6 +361,8 @@ public class PMD { } else { new MonoThreadProcessor(configuration).processFiles(ruleSetFactory, files, ctx, renderers); } + + IOUtil.tryCloseClassLoader(configuration.getClassLoader()); } private static void sortFiles(final PMDConfiguration configuration, final List files) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java index 0c91f74439..6ccb8e7008 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java @@ -3,7 +3,6 @@ */ package net.sourceforge.pmd.ant.internal; -import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -40,6 +39,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.renderers.AbstractRenderer; import net.sourceforge.pmd.renderers.Renderer; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.datasource.FileDataSource; @@ -268,13 +268,7 @@ public class PMDTaskImpl { doTask(); } finally { logManager.close(); - tryCloseClassLoader(configuration.getClassLoader()); - } - } - - private void tryCloseClassLoader(ClassLoader classLoader) { - if (classLoader instanceof Closeable) { - IOUtils.closeQuietly((Closeable)classLoader); + IOUtil.tryCloseClassLoader(configuration.getClassLoader()); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java index 37f6cb2705..e2d21037d2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java @@ -5,12 +5,15 @@ package net.sourceforge.pmd.util; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.Closeable; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import org.apache.commons.io.IOUtils; + /** * * @author Brian Remedios @@ -45,4 +48,11 @@ public final class IOUtil { } return in; } + + public static void tryCloseClassLoader(ClassLoader classLoader) { + if (classLoader instanceof Closeable) { + IOUtils.closeQuietly((Closeable)classLoader); + } + } + }