Search in sources :

Example 16 with IReportVisitor

use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.

the class CheckMojo method executeCheck.

private void executeCheck() throws MojoExecutionException {
    violations = false;
    final ReportSupport support = new ReportSupport(getLog());
    final List<Rule> checkerrules = new ArrayList<Rule>();
    for (final RuleConfiguration r : rules) {
        checkerrules.add(r.rule);
    }
    support.addRulesChecker(checkerrules, this);
    try {
        final IReportVisitor visitor = support.initRootVisitor();
        support.loadExecutionData(dataFile);
        support.processProject(visitor, getProject(), this.getIncludes(), this.getExcludes());
        visitor.visitEnd();
    } catch (final IOException e) {
        throw new MojoExecutionException("Error while checking code coverage: " + e.getMessage(), e);
    }
    if (violations) {
        if (this.haltOnFailure) {
            throw new MojoExecutionException(CHECK_FAILED);
        } else {
            this.getLog().warn(CHECK_FAILED);
        }
    } else {
        this.getLog().info(CHECK_SUCCESS);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) Rule(org.jacoco.report.check.Rule) IOException(java.io.IOException) IReportVisitor(org.jacoco.report.IReportVisitor)

Example 17 with IReportVisitor

use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.

the class CSVFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given stream.
 *
 * @param output
 *            output stream to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final OutputStream output) throws IOException {
    final DelimitedWriter writer = new DelimitedWriter(new OutputStreamWriter(output, outputEncoding));
    final ClassRowWriter rowWriter = new ClassRowWriter(writer, languageNames);
    class Visitor extends CSVGroupHandler implements IReportVisitor {

        Visitor() {
            super(rowWriter);
        }

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
        // Info not used for CSV report
        }

        public void visitEnd() throws IOException {
            writer.close();
        }
    }
    return new Visitor();
}
Also used : IReportVisitor(org.jacoco.report.IReportVisitor) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) List(java.util.List) IReportVisitor(org.jacoco.report.IReportVisitor)

Example 18 with IReportVisitor

use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.

the class HTMLFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given output.
 *
 * @param output
 *            output to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final IMultiReportOutput output) throws IOException {
    final ReportOutputFolder root = new ReportOutputFolder(output);
    resources = new Resources(root);
    resources.copyResources();
    index = new ElementIndex(root);
    return new IReportVisitor() {

        private List<SessionInfo> sessionInfos;

        private Collection<ExecutionData> executionData;

        private HTMLGroupVisitor groupHandler;

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
            this.sessionInfos = sessionInfos;
            this.executionData = executionData;
        }

        public void visitBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            final BundlePage page = new BundlePage(bundle, null, locator, root, HTMLFormatter.this);
            createSessionsPage(page);
            page.render();
        }

        public IReportGroupVisitor visitGroup(final String name) throws IOException {
            groupHandler = new HTMLGroupVisitor(null, root, HTMLFormatter.this, name);
            createSessionsPage(groupHandler.getPage());
            return groupHandler;
        }

        private void createSessionsPage(final ReportPage rootpage) {
            sessionsPage = new SessionsPage(sessionInfos, executionData, index, rootpage, root, HTMLFormatter.this);
        }

        public void visitEnd() throws IOException {
            if (groupHandler != null) {
                groupHandler.visitEnd();
            }
            sessionsPage.render();
            output.close();
        }
    };
}
Also used : ReportOutputFolder(org.jacoco.report.internal.ReportOutputFolder) SessionsPage(org.jacoco.report.internal.html.page.SessionsPage) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) ReportPage(org.jacoco.report.internal.html.page.ReportPage) IReportVisitor(org.jacoco.report.IReportVisitor) HTMLGroupVisitor(org.jacoco.report.internal.html.HTMLGroupVisitor) BundlePage(org.jacoco.report.internal.html.page.BundlePage) Collection(java.util.Collection) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) List(java.util.List) Resources(org.jacoco.report.internal.html.resources.Resources) ElementIndex(org.jacoco.report.internal.html.index.ElementIndex)

Example 19 with IReportVisitor

use of org.jacoco.report.IReportVisitor in project jacoco by jacoco.

the class XMLFormatter method createVisitor.

/**
 * Creates a new visitor to write a report to the given stream.
 *
 * @param output
 *            output stream to write the report to
 * @return visitor to emit the report data to
 * @throws IOException
 *             in case of problems with the output stream
 */
public IReportVisitor createVisitor(final OutputStream output) throws IOException {
    final XMLElement root = new XMLDocument("report", PUBID, SYSTEM, outputEncoding, true, output);
    class RootVisitor extends XMLGroupVisitor implements IReportVisitor {

        RootVisitor(final XMLElement element) throws IOException {
            super(element, null);
        }

        private List<SessionInfo> sessionInfos;

        public void visitInfo(final List<SessionInfo> sessionInfos, final Collection<ExecutionData> executionData) throws IOException {
            this.sessionInfos = sessionInfos;
        }

        @Override
        protected void handleBundle(final IBundleCoverage bundle, final ISourceFileLocator locator) throws IOException {
            writeHeader(bundle.getName());
            XMLCoverageWriter.writeBundle(bundle, element);
        }

        @Override
        protected AbstractGroupVisitor handleGroup(final String name) throws IOException {
            writeHeader(name);
            return new XMLGroupVisitor(element, name);
        }

        private void writeHeader(final String name) throws IOException {
            element.attr("name", name);
            for (final SessionInfo i : sessionInfos) {
                final XMLElement sessioninfo = root.element("sessioninfo");
                sessioninfo.attr("id", i.getId());
                sessioninfo.attr("start", i.getStartTimeStamp());
                sessioninfo.attr("dump", i.getDumpTimeStamp());
            }
        }

        @Override
        protected void handleEnd() throws IOException {
            element.close();
        }
    }
    return new RootVisitor(root);
}
Also used : XMLGroupVisitor(org.jacoco.report.internal.xml.XMLGroupVisitor) Collection(java.util.Collection) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) SessionInfo(org.jacoco.core.data.SessionInfo) List(java.util.List) XMLElement(org.jacoco.report.internal.xml.XMLElement) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) XMLDocument(org.jacoco.report.internal.xml.XMLDocument) IReportVisitor(org.jacoco.report.IReportVisitor)

Aggregations

IReportVisitor (org.jacoco.report.IReportVisitor)19 Test (org.junit.Test)6 IOException (java.io.IOException)4 Collection (java.util.Collection)4 List (java.util.List)4 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)4 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)3 FileMultiReportOutput (org.jacoco.report.FileMultiReportOutput)3 HTMLFormatter (org.jacoco.report.html.HTMLFormatter)3 BufferedReader (java.io.BufferedReader)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 SessionInfo (org.jacoco.core.data.SessionInfo)2 MultiReportVisitor (org.jacoco.report.MultiReportVisitor)2 CSVFormatter (org.jacoco.report.csv.CSVFormatter)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1