use of net.sourceforge.pmd.RuleSetFactory 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));
}
}
}
use of net.sourceforge.pmd.RuleSetFactory in project maven-plugins by apache.
the class PmdReport method processFilesWithPMD.
private void processFilesWithPMD(PMDConfiguration pmdConfiguration, List<DataSource> dataSources) throws MavenReportException {
RuleSetFactory ruleSetFactory = new RuleSetFactory(RuleSetFactory.class.getClassLoader(), RulePriority.valueOf(this.minimumPriority), false, true);
RuleContext ruleContext = new RuleContext();
try {
getLog().debug("Executing PMD...");
PMD.processFiles(pmdConfiguration, ruleSetFactory, dataSources, ruleContext, Arrays.<Renderer>asList(renderer));
if (getLog().isDebugEnabled()) {
getLog().debug("PMD finished. Found " + renderer.getViolations().size() + " violations.");
}
} catch (Exception e) {
String message = "Failure executing PMD: " + e.getLocalizedMessage();
if (!skipPmdError) {
throw new MavenReportException(message, e);
}
getLog().warn(message, e);
}
}
use of net.sourceforge.pmd.RuleSetFactory in project Gargoyle by callakrsos.
the class RulesetsFactoryUtils method getRulesetFactory.
public static RuleSetFactory getRulesetFactory(GargoylePMDConfiguration configuration) {
RuleSetFactory ruleSetFactory = new RuleSetFactory();
ruleSetFactory.setMinimumPriority(configuration.getMinimumPriority());
if (!configuration.isRuleSetFactoryCompatibilityEnabled()) {
ruleSetFactory.disableCompatibilityFilter();
}
return ruleSetFactory;
}
Aggregations