use of net.sourceforge.pmd.util.log.ConsoleLogHandler in project pmd by pmd.
the class PMD method run.
/**
* Parses the command line arguments and executes PMD.
*
* @param args
* command line arguments
* @return the exit code, where <code>0</code> means successful execution,
* <code>1</code> means error, <code>4</code> means there have been
* violations found.
*/
public static int run(String[] args) {
int status = 0;
long start = System.nanoTime();
final PMDParameters params = PMDCommandLineInterface.extractParameters(new PMDParameters(), args, "pmd");
final PMDConfiguration configuration = params.toConfiguration();
final Level logLevel = params.isDebug() ? Level.FINER : Level.INFO;
final Handler logHandler = new ConsoleLogHandler();
final ScopedLogHandlersManager logHandlerManager = new ScopedLogHandlersManager(logLevel, logHandler);
final Level oldLogLevel = LOG.getLevel();
// Need to do this, since the static logger has already been initialized
// at this point
LOG.setLevel(logLevel);
try {
int violations = PMD.doPMD(configuration);
if (violations > 0 && configuration.isFailOnViolation()) {
status = PMDCommandLineInterface.VIOLATIONS_FOUND;
} else {
status = 0;
}
} catch (Exception e) {
System.out.println(PMDCommandLineInterface.buildUsageText());
System.out.println();
System.err.println(e.getMessage());
status = PMDCommandLineInterface.ERROR_STATUS;
} finally {
logHandlerManager.close();
LOG.setLevel(oldLogLevel);
if (params.isBenchmark()) {
long end = System.nanoTime();
Benchmarker.mark(Benchmark.TotalPMD, end - start, 0);
// TODO get specified report format from config
TextReport report = new TextReport();
report.generate(Benchmarker.values(), System.err);
}
}
return status;
}
Aggregations