forked from phoedos/pmd
Fixes #1508 [core] [java] PMD is leaking file handles
Closes class loader after ant task is finished
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user