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