Search in sources :

Example 1 with ReportListener

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));
    }
}
Also used : Field(java.lang.reflect.Field) PrintStream(java.io.PrintStream) ReportListener(net.sourceforge.pmd.ReportListener) ArrayList(java.util.ArrayList) GargoylePMDParameters(com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDParameters) TextReport(net.sourceforge.pmd.benchmark.TextReport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with ReportListener

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));
        }
    }
}
Also used : ReportListener(net.sourceforge.pmd.ReportListener) RuleContext(net.sourceforge.pmd.RuleContext) RuleViolation(net.sourceforge.pmd.RuleViolation) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IOException(java.io.IOException) DataSource(net.sourceforge.pmd.util.datasource.DataSource) ReaderDataSource(net.sourceforge.pmd.util.datasource.ReaderDataSource) RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) Language(net.sourceforge.pmd.lang.Language) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RuleSets(net.sourceforge.pmd.RuleSets) Renderer(net.sourceforge.pmd.renderers.Renderer) Metric(net.sourceforge.pmd.stat.Metric)

Aggregations

IOException (java.io.IOException)2 ReportListener (net.sourceforge.pmd.ReportListener)2 GargoylePMDParameters (com.kyj.fx.voeditor.visual.framework.pmd.GargoylePMDParameters)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RuleContext (net.sourceforge.pmd.RuleContext)1 RuleSetFactory (net.sourceforge.pmd.RuleSetFactory)1 RuleSets (net.sourceforge.pmd.RuleSets)1 RuleViolation (net.sourceforge.pmd.RuleViolation)1 TextReport (net.sourceforge.pmd.benchmark.TextReport)1 Language (net.sourceforge.pmd.lang.Language)1 Renderer (net.sourceforge.pmd.renderers.Renderer)1 Metric (net.sourceforge.pmd.stat.Metric)1 DataSource (net.sourceforge.pmd.util.datasource.DataSource)1 ReaderDataSource (net.sourceforge.pmd.util.datasource.ReaderDataSource)1