From 61376f81121b678e7e49a785b6fab28553efa450 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 7 Oct 2017 21:28:20 +0200 Subject: [PATCH] [core] add temporary support for maven debug output refs #650 --- .../main/java/net/sourceforge/pmd/PMD.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 7b477607e7..db91c9eed6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -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 files, final RuleContext ctx, final List 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 files) {