use of net.sourceforge.pmd.ReportListener in project Gargoyle by callakrsos.
the class PMDCheckedListComposite method dirFilePmd.
protected void dirFilePmd(File file) {
try {
GargoylePMDParameters params = new GargoylePMDParameters();
try {
Field declaredField = GargoylePMDParameters.class.getDeclaredField("sourceDir");
if (declaredField != null) {
declaredField.setAccessible(true);
declaredField.set(params, file.getAbsolutePath());
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
long start = System.nanoTime();
List<ReportListener> listeners = new ArrayList<>();
listeners.addAll(chartComposite.getAvalilableReportListenerList());
listeners.add(reportListenerProperty.get());
listeners.add(violationCountingListener.get());
doPMD.doPMD(transformParametersIntoConfiguration(params), listeners);
long end = System.nanoTime();
Benchmarker.mark(Benchmark.TotalPMD, end - start, 0);
TextReport report = new TextReport();
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
report.generate(Benchmarker.values(), new PrintStream(out));
out.flush();
LOGGER.debug(out.toString("UTF-8"));
}
Platform.runLater(() -> {
updateViolationLabel();
chartComposite.build();
});
} catch (IOException e) {
LOGGER.error(ValueUtil.toString(e));
}
}
use of net.sourceforge.pmd.ReportListener in project Gargoyle by callakrsos.
the class DoPMD method doPMD.
public int doPMD(GargoylePMDConfiguration configuration, List<ReportListener> listeners) {
renerderWriter = RendererWriterFactory.get(WRITER_TYPE.StringWriter);
// Load the RuleSets
RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.getRulesetFactory(configuration);
RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory);
if (ruleSets == null) {
return 0;
}
Set<Language> languages = getApplicableLanguages(configuration, ruleSets);
List<DataSource> files = getApplicableFiles(configuration, languages);
long reportStart = System.nanoTime();
try {
// Renderer renderer = RendererFactory.createRenderer(configuration.getReportFormat(), configuration.getReportProperties()); //configuration.createRenderer();//createDefaultRenderer();
List<Renderer> renderers = new LinkedList<>();
//configuration.createRenderer();
Renderer renderer = new DatabaseXmlRenderer();
renderer.setWriter(renerderWriter.getWriter());
renderer.start();
renderers.add(renderer);
Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0);
RuleContext ctx = new RuleContext();
final AtomicInteger violations = new AtomicInteger(0);
ctx.getReport().addListener(new ReportListener() {
@Override
public void ruleViolationAdded(RuleViolation ruleViolation) {
violations.incrementAndGet();
}
@Override
public void metricAdded(Metric metric) {
}
});
if (listeners != null && !listeners.isEmpty()) {
for (ReportListener l : listeners) ctx.getReport().addListener(l);
}
processFiles(configuration, ruleSetFactory, files, ctx, renderers);
reportStart = System.nanoTime();
// renderer.renderFileReport();
renderer.end();
renderer.flush();
return violations.get();
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
return 0;
} finally {
Benchmarker.mark(Benchmark.Reporting, System.nanoTime() - reportStart, 0);
try {
close();
} catch (IOException e) {
LOGGER.error(ValueUtil.toString(e));
}
}
}
Aggregations