diff options
Diffstat (limited to 'jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java')
-rw-r--r-- | jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java | 87 |
1 files changed, 27 insertions, 60 deletions
diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java b/jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java index 1cdf847c..c484309e 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportSupport.java @@ -1,9 +1,10 @@ /******************************************************************************* - * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Evgeny Mandrikov - initial API and implementation @@ -16,14 +17,12 @@ import static java.lang.String.format; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Locale; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -32,7 +31,6 @@ import org.jacoco.core.analysis.CoverageBuilder; import org.jacoco.core.analysis.IBundleCoverage; import org.jacoco.core.analysis.IClassCoverage; import org.jacoco.core.tools.ExecFileLoader; -import org.jacoco.report.FileMultiReportOutput; import org.jacoco.report.IReportGroupVisitor; import org.jacoco.report.IReportVisitor; import org.jacoco.report.ISourceFileLocator; @@ -40,17 +38,15 @@ import org.jacoco.report.MultiReportVisitor; import org.jacoco.report.check.IViolationsOutput; import org.jacoco.report.check.Rule; import org.jacoco.report.check.RulesChecker; -import org.jacoco.report.csv.CSVFormatter; -import org.jacoco.report.html.HTMLFormatter; -import org.jacoco.report.xml.XMLFormatter; /** * Encapsulates the tasks to create reports for Maven projects. Instances are * supposed to be used in the following sequence: - * + * * <ol> * <li>Create an instance</li> - * <li>Load one or multiple exec files with <code>loadExecutionData()</code></li> + * <li>Load one or multiple exec files with + * <code>loadExecutionData()</code></li> * <li>Add one or multiple formatters with <code>addXXX()</code> methods</li> * <li>Create the root visitor with <code>initRootVisitor()</code></li> * <li>Process one or multiple projects with <code>processProject()</code></li> @@ -64,7 +60,7 @@ final class ReportSupport { /** * Construct a new instance with the given log output. - * + * * @param log * for log output */ @@ -76,7 +72,7 @@ final class ReportSupport { /** * Loads the given execution data file. - * + * * @param execFile * execution data file to load * @throws IOException @@ -87,38 +83,8 @@ final class ReportSupport { loader.load(execFile); } - public void addXmlFormatter(final File targetfile, final String encoding) - throws IOException { - final XMLFormatter xml = new XMLFormatter(); - xml.setOutputEncoding(encoding); - formatters.add(xml.createVisitor(new FileOutputStream(targetfile))); - } - - public void addCsvFormatter(final File targetfile, final String encoding) - throws IOException { - final CSVFormatter csv = new CSVFormatter(); - csv.setOutputEncoding(encoding); - formatters.add(csv.createVisitor(new FileOutputStream(targetfile))); - } - - public void addHtmlFormatter(final File targetdir, final String encoding, - final String footer, final Locale locale) throws IOException { - final HTMLFormatter htmlFormatter = new HTMLFormatter(); - htmlFormatter.setOutputEncoding(encoding); - htmlFormatter.setLocale(locale); - if (footer != null) { - htmlFormatter.setFooterText(footer); - } - formatters.add(htmlFormatter.createVisitor(new FileMultiReportOutput( - targetdir))); - } - - public void addAllFormatters(final File targetdir, final String encoding, - final String footer, final Locale locale) throws IOException { - targetdir.mkdirs(); - addXmlFormatter(new File(targetdir, "jacoco.xml"), encoding); - addCsvFormatter(new File(targetdir, "jacoco.csv"), encoding); - addHtmlFormatter(targetdir, encoding, footer, locale); + public void addVisitor(final IReportVisitor visitor) { + formatters.add(visitor); } public void addRulesChecker(final List<Rule> rules, @@ -130,15 +96,15 @@ final class ReportSupport { public IReportVisitor initRootVisitor() throws IOException { final IReportVisitor visitor = new MultiReportVisitor(formatters); - visitor.visitInfo(loader.getSessionInfoStore().getInfos(), loader - .getExecutionDataStore().getContents()); + visitor.visitInfo(loader.getSessionInfoStore().getInfos(), + loader.getExecutionDataStore().getContents()); return visitor; } /** * Calculates coverage for the given project and emits it to the report * group without source references - * + * * @param visitor * group visitor to emit the project's coverage to * @param project @@ -160,10 +126,10 @@ final class ReportSupport { /** * Calculates coverage for the given project and emits it to the report * group including source references - * + * * @param visitor * group visitor to emit the project's coverage to - * @param bundeName + * @param bundleName * name for this project in the report * @param project * the MavenProject @@ -177,20 +143,20 @@ final class ReportSupport { * if class files can't be read */ public void processProject(final IReportGroupVisitor visitor, - final String bundeName, final MavenProject project, + final String bundleName, final MavenProject project, final List<String> includes, final List<String> excludes, final String srcEncoding) throws IOException { - processProject(visitor, bundeName, project, includes, excludes, + processProject(visitor, bundleName, project, includes, excludes, new SourceFileCollection(project, srcEncoding)); } private void processProject(final IReportGroupVisitor visitor, - final String bundeName, final MavenProject project, + final String bundleName, final MavenProject project, final List<String> includes, final List<String> excludes, final ISourceFileLocator locator) throws IOException { final CoverageBuilder builder = new CoverageBuilder(); - final File classesDir = new File(project.getBuild() - .getOutputDirectory()); + final File classesDir = new File( + project.getBuild().getOutputDirectory()); if (classesDir.isDirectory()) { final Analyzer analyzer = new Analyzer( @@ -201,7 +167,7 @@ final class ReportSupport { } } - final IBundleCoverage bundle = builder.getBundle(bundeName); + final IBundleCoverage bundle = builder.getBundle(bundleName); logBundleInfo(bundle, builder.getNoMatchClasses()); visitor.visitBundle(bundle, locator); @@ -214,7 +180,7 @@ final class ReportSupport { Integer.valueOf(bundle.getClassCounter().getTotalCount()))); if (!nomatch.isEmpty()) { log.warn(format( - "Classes in bundle '%s' do no match with execution data. " + "Classes in bundle '%s' do not match with execution data. " + "For report generation the same class files must be used as at runtime.", bundle.getName())); for (final IClassCoverage c : nomatch) { @@ -275,7 +241,8 @@ final class ReportSupport { } } - private static List<File> getCompileSourceRoots(final MavenProject project) { + private static List<File> getCompileSourceRoots( + final MavenProject project) { final List<File> result = new ArrayList<File>(); for (final Object path : project.getCompileSourceRoots()) { result.add(resolvePath(project, (String) path)); |