[core] add temporary support for maven debug output

refs #650
This commit is contained in:
Andreas Dangel
2017-10-07 21:28:20 +02:00
parent 005e0d0fdf
commit 61376f8112

View File

@ -278,6 +278,19 @@ public class PMD {
return context;
}
// TODO: remove this, once the maven pmd plugin can report details of processing errors
private static ScopedLogHandlersManager enableLoggingMavenDebug() {
ScopedLogHandlersManager logHandlerManager = null;
String commandLine = System.getProperty("sun.java.command");
if (commandLine != null && commandLine.startsWith("org.codehaus.plexus.classworlds.launcher.Launcher")
&& (commandLine.endsWith("-X") || commandLine.contains("-X "))) {
final Handler logHandler = new ConsoleLogHandler();
logHandlerManager = new ScopedLogHandlersManager(Level.FINE, logHandler);
LOG.setLevel(Level.FINE);
}
return logHandlerManager;
}
/**
* Run PMD on a list of files using multiple threads - if more than one is
* available
@ -296,6 +309,8 @@ public class PMD {
public static void processFiles(final PMDConfiguration configuration, final RuleSetFactory ruleSetFactory,
final List<DataSource> files, final RuleContext ctx, final List<Renderer> renderers) {
ScopedLogHandlersManager logHandlerManager = enableLoggingMavenDebug();
sortFiles(configuration, files);
// Make sure the cache is listening for analysis results
@ -316,6 +331,11 @@ public class PMD {
// Persist the analysis cache
configuration.getAnalysisCache().persist();
// see enableLoggingMavenDebug above
if (logHandlerManager != null) {
logHandlerManager.close();
}
}
private static void sortFiles(final PMDConfiguration configuration, final List<DataSource> files) {