diff options
author | Allen Hair <allenhair@google.com> | 2022-03-22 17:50:58 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-03-22 17:50:58 +0000 |
commit | 18a980206d62b715d1bb9a0b411413b2d0d5ee6f (patch) | |
tree | e68ce50b1fc964c12a1eb020ca8b2483ff2955d4 /jacoco-maven-plugin/src/org/jacoco | |
parent | cf92214db05a512b30c7c8f842855208ae450580 (diff) | |
parent | 2f01fe494ff8b031970daf329253df53ef60dde3 (diff) | |
download | jacoco-android13-qpr3-s3-release.tar.gz |
Merge "Update jacoco to 0.8.7." am: 46c6f6b353 am: 7398ddd230 am: 2f01fe494ft_frc_odp_330442040t_frc_odp_330442000t_frc_ase_330444010android-13.0.0_r83android-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r79android-13.0.0_r78android-13.0.0_r77android-13.0.0_r76android-13.0.0_r75android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r71android-13.0.0_r70android-13.0.0_r69android-13.0.0_r68android-13.0.0_r67android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android-13.0.0_r63android-13.0.0_r62android-13.0.0_r61android-13.0.0_r60android-13.0.0_r59android-13.0.0_r58android-13.0.0_r57android-13.0.0_r56android-13.0.0_r54android-13.0.0_r53android-13.0.0_r52android-13.0.0_r51android-13.0.0_r50android-13.0.0_r49android-13.0.0_r48android-13.0.0_r47android-13.0.0_r46android-13.0.0_r45android-13.0.0_r44android-13.0.0_r43android-13.0.0_r42android-13.0.0_r41android-13.0.0_r40android-13.0.0_r39android-13.0.0_r38android-13.0.0_r37android-13.0.0_r36android-13.0.0_r35android-13.0.0_r34android-13.0.0_r33android-13.0.0_r32aml_go_odp_330912000aml_go_ads_330915100aml_go_ads_330915000aml_go_ads_330913000android13-qpr3-s9-releaseandroid13-qpr3-s8-releaseandroid13-qpr3-s7-releaseandroid13-qpr3-s6-releaseandroid13-qpr3-s5-releaseandroid13-qpr3-s4-releaseandroid13-qpr3-s3-releaseandroid13-qpr3-s2-releaseandroid13-qpr3-s14-releaseandroid13-qpr3-s13-releaseandroid13-qpr3-s12-releaseandroid13-qpr3-s11-releaseandroid13-qpr3-s10-releaseandroid13-qpr3-s1-releaseandroid13-qpr3-releaseandroid13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s3-releaseandroid13-qpr3-c-s2-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-releaseandroid13-qpr3-c-s1-releaseandroid13-qpr2-s9-releaseandroid13-qpr2-s8-releaseandroid13-qpr2-s7-releaseandroid13-qpr2-s6-releaseandroid13-qpr2-s5-releaseandroid13-qpr2-s3-releaseandroid13-qpr2-s2-releaseandroid13-qpr2-s12-releaseandroid13-qpr2-s11-releaseandroid13-qpr2-s10-releaseandroid13-qpr2-s1-releaseandroid13-qpr2-releaseandroid13-qpr2-b-s1-releaseandroid13-mainline-go-adservices-releaseandroid13-frc-odp-releaseandroid13-devandroid13-d4-s2-releaseandroid13-d4-s1-releaseandroid13-d4-releaseandroid13-d3-s1-release
Original change: https://android-review.googlesource.com/c/platform/external/jacoco/+/2015697
Change-Id: Ie848d2ff33b291aa64d065bf2e3ede1dbd861b97
Diffstat (limited to 'jacoco-maven-plugin/src/org/jacoco')
17 files changed, 374 insertions, 301 deletions
diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractAgentMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractAgentMojo.java index d097c530..74f90ace 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractAgentMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractAgentMojo.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 @@ -68,7 +69,10 @@ public abstract class AbstractAgentMojo extends AbstractJacocoMojo { /** * A list of class names to exclude from instrumentation. May use wildcard - * characters (* and ?). When not specified nothing will be excluded. + * characters (* and ?). When not specified nothing will be excluded. Except + * for performance optimization or technical corner cases this option is + * normally not required. If you want to exclude classes from the report + * please configure the <code>report</code> goal accordingly. */ @Parameter private List<String> excludes; @@ -155,8 +159,8 @@ public abstract class AbstractAgentMojo extends AbstractJacocoMojo { final String name = getEffectivePropertyName(); final Properties projectProperties = getProject().getProperties(); final String oldValue = projectProperties.getProperty(name); - final String newValue = createAgentOptions().prependVMArguments( - oldValue, getAgentJarFile()); + final String newValue = createAgentOptions() + .prependVMArguments(oldValue, getAgentJarFile()); getLog().info(name + " set to " + newValue); projectProperties.setProperty(name, newValue); } @@ -196,12 +200,12 @@ public abstract class AbstractAgentMojo extends AbstractJacocoMojo { agentOptions.setExclClassloader(exclClassLoaders); } if (inclBootstrapClasses != null) { - agentOptions.setInclBootstrapClasses(inclBootstrapClasses - .booleanValue()); + agentOptions.setInclBootstrapClasses( + inclBootstrapClasses.booleanValue()); } if (inclNoLocationClasses != null) { - agentOptions.setInclNoLocationClasses(inclNoLocationClasses - .booleanValue()); + agentOptions.setInclNoLocationClasses( + inclNoLocationClasses.booleanValue()); } if (sessionId != null) { agentOptions.setSessionId(sessionId); diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractJacocoMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractJacocoMojo.java index 8eb55ca3..4ea6b5af 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractJacocoMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractJacocoMojo.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 @@ -34,8 +35,8 @@ public abstract class AbstractJacocoMojo extends AbstractMojo { @Parameter(property = "jacoco.skip", defaultValue = "false") private boolean skip; - public final void execute() throws MojoExecutionException, - MojoFailureException { + public final void execute() + throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info( "Skipping JaCoCo execution because property jacoco.skip is set."); @@ -47,7 +48,7 @@ public abstract class AbstractJacocoMojo extends AbstractMojo { /** * Executes Mojo. - * + * * @throws MojoExecutionException * if an unexpected problem occurs. Throwing this exception * causes a "BUILD ERROR" message to be displayed. @@ -56,8 +57,8 @@ public abstract class AbstractJacocoMojo extends AbstractMojo { * occurs. Throwing this exception causes a "BUILD FAILURE" * message to be displayed. */ - protected abstract void executeMojo() throws MojoExecutionException, - MojoFailureException; + protected abstract void executeMojo() + throws MojoExecutionException, MojoFailureException; /** * Skips Mojo. diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java index ecd48ab5..097ecb10 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java @@ -1,26 +1,29 @@ /******************************************************************************* - * 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 + * troosan - add support for format selection * *******************************************************************************/ package org.jacoco.maven; +import java.io.File; import java.io.IOException; import java.util.List; import java.util.Locale; -import org.apache.maven.doxia.siterenderer.Renderer; +import org.apache.maven.doxia.sink.SinkFactory; +import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.MavenMultiPageReport; import org.apache.maven.reporting.MavenReportException; import org.jacoco.report.IReportGroupVisitor; import org.jacoco.report.IReportVisitor; @@ -29,7 +32,8 @@ import org.jacoco.report.IReportVisitor; * Base class for creating a code coverage report for tests of a single project * in multiple formats (HTML, XML, and CSV). */ -public abstract class AbstractReportMojo extends AbstractMavenReport { +public abstract class AbstractReportMojo extends AbstractMojo + implements MavenMultiPageReport { /** * Encoding of the generated reports. @@ -38,6 +42,15 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { String outputEncoding; /** + * A list of report formats to generate. Supported formats are HTML, XML and + * CSV. Defaults to all formats if no values are given. + * + * @since 0.8.7 + */ + @Parameter(defaultValue = "HTML,XML,CSV") + List<ReportFormat> formats; + + /** * Name of the root node HTML report pages. * * @since 0.7.7 @@ -85,34 +98,21 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { @Parameter(property = "project", readonly = true) MavenProject project; - /** - * Doxia Site Renderer. - */ - @Component - Renderer siteRenderer; - public String getDescription(final Locale locale) { return getName(locale) + " Coverage Report."; } - @Override public boolean isExternalReport() { return true; } - @Override - protected MavenProject getProject() { - return project; - } - - @Override - protected Renderer getSiteRenderer() { - return siteRenderer; + public String getCategoryName() { + return CATEGORY_PROJECT_REPORTS; } /** * Returns the list of class files to include in the report. - * + * * @return class files to include, may contain wildcard characters */ List<String> getIncludes() { @@ -121,14 +121,13 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { /** * Returns the list of class files to exclude from the report. - * + * * @return class files to exclude, may contain wildcard characters */ List<String> getExcludes() { return excludes; } - @Override public boolean canGenerateReport() { if (skip) { getLog().info( @@ -152,11 +151,27 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { abstract boolean canGenerateReportRegardingClassesDirectory(); + abstract File getOutputDirectory(); + + public void generate( + @SuppressWarnings("deprecation") final org.codehaus.doxia.sink.Sink sink, + final Locale locale) throws MavenReportException { + generate(sink, null, locale); + } + + public void generate(final org.apache.maven.doxia.sink.Sink sink, + final SinkFactory sinkFactory, final Locale locale) + throws MavenReportException { + if (!canGenerateReport()) { + return; + } + executeReport(locale); + } + /** * This method is called when the report generation is invoked directly as a * standalone Mojo. */ - @Override public void execute() throws MojoExecutionException { if (!canGenerateReport()) { return; @@ -169,8 +184,7 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { } } - @Override - protected void executeReport(final Locale locale) + private void executeReport(final Locale locale) throws MavenReportException { try { final ReportSupport support = new ReportSupport(getLog()); @@ -180,15 +194,20 @@ public abstract class AbstractReportMojo extends AbstractMavenReport { createReport(visitor, support); visitor.visitEnd(); } catch (final IOException e) { - throw new MavenReportException("Error while creating report: " - + e.getMessage(), e); + throw new MavenReportException( + "Error while creating report: " + e.getMessage(), e); } } - abstract void loadExecutionData(final ReportSupport support) - throws IOException; + private void addFormatters(final ReportSupport support, final Locale locale) + throws IOException { + getOutputDirectory().mkdirs(); + for (final ReportFormat f : formats) { + support.addVisitor(f.createVisitor(this, locale)); + } + } - abstract void addFormatters(final ReportSupport support, final Locale locale) + abstract void loadExecutionData(final ReportSupport support) throws IOException; abstract void createReport(final IReportGroupVisitor visitor, diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AgentITMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AgentITMojo.java index 03422d60..158b46eb 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/AgentITMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/AgentITMojo.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 @@ -26,7 +27,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * <li>bound to <code>pre-integration-test</code> phase</li> * <li>different <code>destFile</code></li> * </ul> - * + * * @since 0.6.4 */ @Mojo(name = "prepare-agent-integration", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true) diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/AgentMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/AgentMojo.java index f434c981..accc9896 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/AgentMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/AgentMojo.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 @@ -24,12 +25,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * as a VM argument to the application under test. Depending on the project * packaging type by default a property with the following name is set: * </p> - * + * * <ul> * <li>tycho.testArgLine for packaging type eclipse-test-plugin and</li> * <li>argLine otherwise.</li> * </ul> - * + * * <p> * If your project already defines VM arguments for test execution, be sure that * they will include property defined by JaCoCo. @@ -37,9 +38,11 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * * <p> * One of the ways to do this in case of maven-surefire-plugin - is to use - * syntax for <a href="http://maven.apache.org/surefire/maven-surefire-plugin/faq.html#late-property-evaluation">late property evaluation</a>: + * syntax for <a href= + * "http://maven.apache.org/surefire/maven-surefire-plugin/faq.html#late-property-evaluation">late + * property evaluation</a>: * </p> - * + * * <pre> * <plugin> * <groupId>org.apache.maven.plugins</groupId> @@ -49,17 +52,18 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * </configuration> * </plugin> * </pre> - * + * * <p> - * You can define empty property to avoid JVM startup error <code>Could not find or load main class @{argLine}</code> - * when using late property evaluation and jacoco-maven-plugin not executed. + * You can define empty property to avoid JVM startup error + * <code>Could not find or load main class @{argLine}</code> when using late + * property evaluation and jacoco-maven-plugin not executed. * </p> - * + * * <p> - * Another way is to define "argLine" as a Maven property rather than - * as part of the configuration of maven-surefire-plugin: + * Another way is to define "argLine" as a Maven property rather than as part of + * the configuration of maven-surefire-plugin: * </p> - * + * * <pre> * <properties> * <argLine>-your -extra -arguments</argLine> @@ -73,12 +77,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * </configuration> * </plugin> * </pre> - * + * * <p> * Resulting coverage information is collected during execution and by default * written to a file when the process terminates. * </p> - * + * * @since 0.5.3 */ @Mojo(name = "prepare-agent", defaultPhase = LifecyclePhase.INITIALIZE, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true) diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java index 68d6aa8d..21b7419b 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/CheckMojo.java @@ -1,15 +1,16 @@ /******************************************************************************* - * 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 * Kyle Lieber - implementation of CheckMojo * Marc Hoffmann - redesign using report APIs - * + * *******************************************************************************/ package org.jacoco.maven; @@ -30,7 +31,7 @@ import org.jacoco.report.check.Rule; /** * Checks that the code coverage metrics are being met. - * + * * @since 0.6.1 */ @Mojo(name = "check", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) @@ -47,27 +48,27 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput { * applies to a certain counter (INSTRUCTION, LINE, BRANCH, COMPLEXITY, * METHOD, CLASS) and defines a minimum or maximum for the corresponding * value (TOTALCOUNT, COVEREDCOUNT, MISSEDCOUNT, COVEREDRATIO, MISSEDRATIO). - * If a limit refers to a ratio the range is from 0.0 to 1.0 where the - * number of decimal places will also determine the precision in error - * messages. A limit ratio may optionally be declared as a percentage - * where 0.80 and 80% represent the same value, the value must end with %. + * If a limit refers to a ratio it must be in the range from 0.0 to 1.0 + * where the number of decimal places will also determine the precision in + * error messages. A limit ratio may optionally be declared as a percentage + * where 0.80 and 80% represent the same value. * </p> - * + * * <p> * If not specified the following defaults are assumed: * </p> - * + * * <ul> * <li>rule element: BUNDLE</li> * <li>limit counter: INSTRUCTION</li> * <li>limit value: COVEREDRATIO</li> * </ul> - * + * * <p> * This example requires an overall instruction coverage of 80% and no class * must be missed: * </p> - * + * * <pre> * {@code * <rules> @@ -88,12 +89,12 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput { * </rule> * </rules>} * </pre> - * + * * <p> * This example requires a line coverage minimum of 50% for every class * except test classes: * </p> - * + * * <pre> * {@code * <rules> @@ -149,8 +150,8 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput { getLog().info(MSG_SKIPPING + dataFile); return false; } - final File classesDirectory = new File(getProject().getBuild() - .getOutputDirectory()); + final File classesDirectory = new File( + getProject().getBuild().getOutputDirectory()); if (!classesDirectory.exists()) { getLog().info( "Skipping JaCoCo execution due to missing classes directory:" @@ -161,8 +162,7 @@ public class CheckMojo extends AbstractJacocoMojo implements IViolationsOutput { } @Override - public void executeMojo() throws MojoExecutionException, - MojoExecutionException { + public void executeMojo() throws MojoExecutionException { if (!canCheckCoverage()) { return; } diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/DumpMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/DumpMojo.java index 64836eea..783c4c7d 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/DumpMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/DumpMojo.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: * Chas Honton, Marc R. Hoffmann - initial implementation @@ -29,13 +30,13 @@ import org.jacoco.core.tools.ExecFileLoader; * Request a dump over TCP/IP from a JaCoCo agent running in * <code>tcpserver</code> mode. * </p> - * + * * <p> * Note concerning parallel builds: While the dump goal as such is thread safe, * it has to be considered that TCP/IP server ports of the agents are a shared * resource. * </p> - * + * * @since 0.6.4 */ @Mojo(name = "dump", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, threadSafe = true) @@ -94,9 +95,8 @@ public class DumpMojo extends AbstractJacocoMojo { @Override protected void onConnecting(final InetAddress address, final int port) { - getLog().info( - format("Connecting to %s:%s", address, - Integer.valueOf(port))); + getLog().info(format("Connecting to %s:%s", address, + Integer.valueOf(port))); } @Override @@ -111,9 +111,8 @@ public class DumpMojo extends AbstractJacocoMojo { try { final ExecFileLoader loader = client.dump(address, port); if (dump) { - getLog().info( - format("Dumping execution data to %s", - destFile.getAbsolutePath())); + getLog().info(format("Dumping execution data to %s", + destFile.getAbsolutePath())); loader.save(destFile, append); } } catch (final IOException e) { diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/FileFilter.java b/jacoco-maven-plugin/src/org/jacoco/maven/FileFilter.java index 09029c8a..377cbb65 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/FileFilter.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/FileFilter.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,7 +17,6 @@ import java.io.File; import java.io.IOException; import java.util.List; -import org.apache.commons.collections.CollectionUtils; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringUtils; @@ -33,20 +33,21 @@ public class FileFilter { /** * Construct a new FileFilter - * + * * @param includes * list of includes patterns * @param excludes * list of excludes patterns */ - public FileFilter(final List<String> includes, final List<String> excludes) { + public FileFilter(final List<String> includes, + final List<String> excludes) { this.includes = includes; this.excludes = excludes; } /** * Returns a list of file names. - * + * * @param directory * the directory to scan * @return a list of files @@ -60,7 +61,7 @@ public class FileFilter { /** * Returns a list of files. - * + * * @param directory * the directory to scan * @return a list of files @@ -73,7 +74,7 @@ public class FileFilter { /** * Get the includes pattern - * + * * @return the pattern */ public String getIncludes() { @@ -82,7 +83,7 @@ public class FileFilter { /** * Get the excludes pattern - * + * * @return the pattern */ public String getExcludes() { @@ -92,7 +93,7 @@ public class FileFilter { private String buildPattern(final List<String> patterns, final String defaultPattern) { String pattern = defaultPattern; - if (CollectionUtils.isNotEmpty(patterns)) { + if (patterns != null && !patterns.isEmpty()) { pattern = StringUtils.join(patterns.iterator(), ","); } return pattern; diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/InstrumentMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/InstrumentMojo.java index d99ada74..ac31a10c 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/InstrumentMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/InstrumentMojo.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 @@ -39,7 +40,7 @@ import org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator; * this mode. Please consult <a href="offline.html">documentation</a> about * offline instrumentation before using this mode. * </p> - * + * * @since 0.6.2 */ @Mojo(name = "instrument", defaultPhase = LifecyclePhase.PROCESS_CLASSES, threadSafe = true) @@ -54,23 +55,27 @@ public class InstrumentMojo extends AbstractJacocoMojo { /** * A list of class files to exclude from instrumentation. May use wildcard - * characters (* and ?). When not specified nothing will be excluded. + * characters (* and ?). When not specified nothing will be excluded. Except + * for performance optimization or technical corner cases this option is + * normally not required. If you want to exclude classes from the report + * please configure the <code>report</code> goal accordingly. */ @Parameter private List<String> excludes; @Override - public void executeMojo() throws MojoExecutionException, - MojoFailureException { - final File originalClassesDir = new File(getProject().getBuild() - .getDirectory(), "generated-classes/jacoco"); + public void executeMojo() + throws MojoExecutionException, MojoFailureException { + final File originalClassesDir = new File( + getProject().getBuild().getDirectory(), + "generated-classes/jacoco"); originalClassesDir.mkdirs(); final File classesDir = new File( getProject().getBuild().getOutputDirectory()); if (!classesDir.exists()) { getLog().info( - "Skipping JaCoCo execution due to missing classes directory:" + - classesDir); + "Skipping JaCoCo execution due to missing classes directory:" + + classesDir); return; } diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/MergeMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/MergeMojo.java index 11f95775..f1bb8103 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/MergeMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/MergeMojo.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: * Mads Mohr Christensen - implementation of MergeMojo @@ -26,7 +27,7 @@ import org.jacoco.core.tools.ExecFileLoader; /** * Mojo for merging a set of execution data files (*.exec) into a single file - * + * * @since 0.6.4 */ @Mojo(name = "merge", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) @@ -42,7 +43,7 @@ public class MergeMojo extends AbstractJacocoMojo { /** * This mojo accepts any number of execution data file sets. - * + * * <pre> * <code> * <fileSets> @@ -60,8 +61,8 @@ public class MergeMojo extends AbstractJacocoMojo { private List<FileSet> fileSets; @Override - protected void executeMojo() throws MojoExecutionException, - MojoFailureException { + protected void executeMojo() + throws MojoExecutionException, MojoFailureException { if (!canMergeReports()) { return; } @@ -95,13 +96,12 @@ public class MergeMojo extends AbstractJacocoMojo { continue; } try { - getLog().info( - "Loading execution data file " - + inputFile.getAbsolutePath()); + getLog().info("Loading execution data file " + + inputFile.getAbsolutePath()); loader.load(inputFile); } catch (final IOException e) { - throw new MojoExecutionException("Unable to read " - + inputFile.getAbsolutePath(), e); + throw new MojoExecutionException( + "Unable to read " + inputFile.getAbsolutePath(), e); } } } @@ -113,14 +113,14 @@ public class MergeMojo extends AbstractJacocoMojo { getLog().info(MSG_SKIPPING); return; } - getLog().info( - "Writing merged execution data to " - + destFile.getAbsolutePath()); + getLog().info("Writing merged execution data to " + + destFile.getAbsolutePath()); try { loader.save(destFile, false); } catch (final IOException e) { - throw new MojoExecutionException("Unable to write merged file " - + destFile.getAbsolutePath(), e); + throw new MojoExecutionException( + "Unable to write merged file " + destFile.getAbsolutePath(), + e); } } diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.java index 5b1f12f4..c63569f1 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.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: * John Oliver, Marc R. Hoffmann, Jan Wloka - initial API and implementation @@ -38,18 +39,18 @@ import org.jacoco.report.IReportGroupVisitor; * reports when tests are in separate projects than the code under test, for * example in case of integration tests. * </p> - * + * * <p> * Using the dependency scope allows to distinguish projects which contribute * execution data but should not become part of the report: * </p> - * + * * <ul> * <li><code>compile</code>, <code>runtime</code>, <code>provided</code>: * Project source and execution data is included in the report.</li> * <li><code>test</code>: Only execution data is considered for the report.</li> * </ul> - * + * * @since 0.7.7 */ @Mojo(name = "report-aggregate", threadSafe = true) @@ -106,7 +107,7 @@ public class ReportAggregateMojo extends AbstractReportMojo { final FileFilter filter = new FileFilter(dataFileIncludes, dataFileExcludes); - loadExecutionData(support, filter, getProject().getBasedir()); + loadExecutionData(support, filter, project.getBasedir()); for (final MavenProject dependency : findDependencies( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_TEST)) { @@ -122,10 +123,8 @@ public class ReportAggregateMojo extends AbstractReportMojo { } @Override - void addFormatters(final ReportSupport support, final Locale locale) - throws IOException { - support.addAllFormatters(outputDirectory, outputEncoding, footer, - locale); + File getOutputDirectory() { + return outputDirectory; } @Override @@ -140,16 +139,13 @@ public class ReportAggregateMojo extends AbstractReportMojo { } } - @Override - protected String getOutputDirectory() { - return outputDirectory.getAbsolutePath(); + public File getReportOutputDirectory() { + return outputDirectory; } - @Override public void setReportOutputDirectory(final File reportOutputDirectory) { - if (reportOutputDirectory != null - && !reportOutputDirectory.getAbsolutePath().endsWith( - "jacoco-aggregate")) { + if (reportOutputDirectory != null && !reportOutputDirectory + .getAbsolutePath().endsWith("jacoco-aggregate")) { outputDirectory = new File(reportOutputDirectory, "jacoco-aggregate"); } else { @@ -168,7 +164,7 @@ public class ReportAggregateMojo extends AbstractReportMojo { private List<MavenProject> findDependencies(final String... scopes) { final List<MavenProject> result = new ArrayList<MavenProject>(); final List<String> scopeList = Arrays.asList(scopes); - for (final Object dependencyObject : getProject().getDependencies()) { + for (final Object dependencyObject : project.getDependencies()) { final Dependency dependency = (Dependency) dependencyObject; if (scopeList.contains(dependency.getScope())) { final MavenProject project = findProjectFromReactor(dependency); @@ -192,7 +188,7 @@ public class ReportAggregateMojo extends AbstractReportMojo { try { depVersionAsRange = VersionRange .createFromVersionSpec(d.getVersion()); - } catch (InvalidVersionSpecificationException e) { + } catch (final InvalidVersionSpecificationException e) { throw new AssertionError(e); } diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/ReportFormat.java b/jacoco-maven-plugin/src/org/jacoco/maven/ReportFormat.java new file mode 100644 index 00000000..9406996f --- /dev/null +++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportFormat.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.maven; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Locale; + +import org.jacoco.report.FileMultiReportOutput; +import org.jacoco.report.IReportVisitor; +import org.jacoco.report.csv.CSVFormatter; +import org.jacoco.report.html.HTMLFormatter; +import org.jacoco.report.xml.XMLFormatter; + +/** + * Configurable output formats for the report goals. + */ +public enum ReportFormat { + + /** + * Multi-page html report. + */ + HTML() { + @Override + IReportVisitor createVisitor(final AbstractReportMojo mojo, + final Locale locale) throws IOException { + final HTMLFormatter htmlFormatter = new HTMLFormatter(); + htmlFormatter.setOutputEncoding(mojo.outputEncoding); + htmlFormatter.setLocale(locale); + if (mojo.footer != null) { + htmlFormatter.setFooterText(mojo.footer); + } + return htmlFormatter.createVisitor( + new FileMultiReportOutput(mojo.getOutputDirectory())); + } + }, + + /** + * Single-file XML report. + */ + XML() { + @Override + IReportVisitor createVisitor(final AbstractReportMojo mojo, + final Locale locale) throws IOException { + final XMLFormatter xml = new XMLFormatter(); + xml.setOutputEncoding(mojo.outputEncoding); + return xml.createVisitor(new FileOutputStream( + new File(mojo.getOutputDirectory(), "jacoco.xml"))); + } + }, + + /** + * Single-file CSV report. + */ + CSV() { + @Override + IReportVisitor createVisitor(final AbstractReportMojo mojo, + final Locale locale) throws IOException { + final CSVFormatter csv = new CSVFormatter(); + csv.setOutputEncoding(mojo.outputEncoding); + return csv.createVisitor(new FileOutputStream( + new File(mojo.getOutputDirectory(), "jacoco.csv"))); + } + }; + + abstract IReportVisitor createVisitor(AbstractReportMojo mojo, + final Locale locale) throws IOException; + +} diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.java index ba4dde2e..0ca4970b 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.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 @@ -28,7 +29,7 @@ import org.jacoco.report.IReportGroupVisitor; * <li>bound to <code>report-integration</code> phase</li> * <li>different <code>dataFile</code></li> * </ul> - * + * * @since 0.6.4 */ @Mojo(name = "report-integration", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) @@ -57,7 +58,7 @@ public class ReportITMojo extends AbstractReportMojo { @Override boolean canGenerateReportRegardingClassesDirectory() { - return new File(getProject().getBuild().getOutputDirectory()).exists(); + return new File(project.getBuild().getOutputDirectory()).exists(); } @Override @@ -66,29 +67,24 @@ public class ReportITMojo extends AbstractReportMojo { } @Override - void addFormatters(final ReportSupport support, final Locale locale) - throws IOException { - support.addAllFormatters(outputDirectory, outputEncoding, footer, - locale); + File getOutputDirectory() { + return outputDirectory; } @Override void createReport(final IReportGroupVisitor visitor, final ReportSupport support) throws IOException { - support.processProject(visitor, title, getProject(), getIncludes(), + support.processProject(visitor, title, project, getIncludes(), getExcludes(), sourceEncoding); } - @Override - protected String getOutputDirectory() { - return outputDirectory.getAbsolutePath(); + public File getReportOutputDirectory() { + return outputDirectory; } - @Override public void setReportOutputDirectory(final File reportOutputDirectory) { - if (reportOutputDirectory != null - && !reportOutputDirectory.getAbsolutePath().endsWith( - "jacoco-it")) { + if (reportOutputDirectory != null && !reportOutputDirectory + .getAbsolutePath().endsWith("jacoco-it")) { outputDirectory = new File(reportOutputDirectory, "jacoco-it"); } else { outputDirectory = reportOutputDirectory; diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java index 002e5404..522fec3f 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.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 @@ -23,7 +24,7 @@ import org.jacoco.report.IReportGroupVisitor; /** * Creates a code coverage report for tests of a single project in multiple * formats (HTML, XML, and CSV). - * + * * @since 0.5.3 */ @Mojo(name = "report", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) @@ -52,7 +53,7 @@ public class ReportMojo extends AbstractReportMojo { @Override boolean canGenerateReportRegardingClassesDirectory() { - return new File(getProject().getBuild().getOutputDirectory()).exists(); + return new File(project.getBuild().getOutputDirectory()).exists(); } @Override @@ -61,28 +62,24 @@ public class ReportMojo extends AbstractReportMojo { } @Override - void addFormatters(final ReportSupport support, final Locale locale) - throws IOException { - support.addAllFormatters(outputDirectory, outputEncoding, footer, - locale); + File getOutputDirectory() { + return outputDirectory; } @Override void createReport(final IReportGroupVisitor visitor, final ReportSupport support) throws IOException { - support.processProject(visitor, title, getProject(), getIncludes(), + support.processProject(visitor, title, project, getIncludes(), getExcludes(), sourceEncoding); } - @Override - protected String getOutputDirectory() { - return outputDirectory.getAbsolutePath(); + public File getReportOutputDirectory() { + return outputDirectory; } - @Override public void setReportOutputDirectory(final File reportOutputDirectory) { - if (reportOutputDirectory != null - && !reportOutputDirectory.getAbsolutePath().endsWith("jacoco")) { + if (reportOutputDirectory != null && !reportOutputDirectory + .getAbsolutePath().endsWith("jacoco")) { outputDirectory = new File(reportOutputDirectory, "jacoco"); } else { outputDirectory = reportOutputDirectory; 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)); diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/RestoreMojo.java b/jacoco-maven-plugin/src/org/jacoco/maven/RestoreMojo.java index 0e238d69..13e86901 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/RestoreMojo.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/RestoreMojo.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 @@ -22,19 +23,20 @@ import org.codehaus.plexus.util.FileUtils; /** * Restores original classes as they were before offline instrumentation. - * + * * @since 0.6.2 */ @Mojo(name = "restore-instrumented-classes", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true) public class RestoreMojo extends AbstractJacocoMojo { @Override - protected void executeMojo() throws MojoExecutionException, - MojoFailureException { - final File originalClassesDir = new File(getProject().getBuild() - .getDirectory(), "generated-classes/jacoco"); - final File classesDir = new File(getProject().getBuild() - .getOutputDirectory()); + protected void executeMojo() + throws MojoExecutionException, MojoFailureException { + final File originalClassesDir = new File( + getProject().getBuild().getDirectory(), + "generated-classes/jacoco"); + final File classesDir = new File( + getProject().getBuild().getOutputDirectory()); try { FileUtils.copyDirectoryStructure(originalClassesDir, classesDir); } catch (final IOException e) { diff --git a/jacoco-maven-plugin/src/org/jacoco/maven/RuleConfiguration.java b/jacoco-maven-plugin/src/org/jacoco/maven/RuleConfiguration.java index be4e5a1a..f9d711c0 100644 --- a/jacoco-maven-plugin/src/org/jacoco/maven/RuleConfiguration.java +++ b/jacoco-maven-plugin/src/org/jacoco/maven/RuleConfiguration.java @@ -1,15 +1,16 @@ /******************************************************************************* - * 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 * Kyle Lieber - implementation of CheckMojo * Marc Hoffmann - redesign using report APIs - * + * *******************************************************************************/ package org.jacoco.maven; @@ -22,7 +23,7 @@ import org.jacoco.report.check.Rule; /** * Wrapper for {@link Rule} objects to allow Maven style includes/excludes lists - * + * */ public class RuleConfiguration { @@ -37,8 +38,8 @@ public class RuleConfiguration { /** * @param element - * element type this rule applies to - * TODO: use ElementType directly once Maven 3 is required. + * element type this rule applies to TODO: use ElementType + * directly once Maven 3 is required. */ public void setElement(final String element) { rule.setElement(ElementType.valueOf(element)); @@ -53,7 +54,7 @@ public class RuleConfiguration { } /** - * + * * @param excludes * excludes patterns */ |