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 e5bd978549..0c91f74439 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,6 +3,7 @@ */ package net.sourceforge.pmd.ant.internal; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -14,6 +15,14 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Handler; import java.util.logging.Level; +import org.apache.commons.io.IOUtils; +import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; + import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.Report; @@ -37,14 +46,6 @@ import net.sourceforge.pmd.util.datasource.FileDataSource; import net.sourceforge.pmd.util.log.AntLogHandler; import net.sourceforge.pmd.util.log.ScopedLogHandlersManager; -import org.apache.commons.io.IOUtils; -import org.apache.tools.ant.AntClassLoader; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; - public class PMDTaskImpl { private Path classpath; @@ -267,6 +268,13 @@ public class PMDTaskImpl { doTask(); } finally { logManager.close(); + tryCloseClassLoader(configuration.getClassLoader()); + } + } + + private void tryCloseClassLoader(ClassLoader classLoader) { + if (classLoader instanceof Closeable) { + IOUtils.closeQuietly((Closeable)classLoader); } }