Skip to content

Commit

Permalink
Remove Dependency on maven-reporting-impl
Browse files Browse the repository at this point in the history
This dependency is not really useful for JaCoCo reports and has several
transitive dependencies where security vulnerabilities have been
reported.

Fixes #641, #920
  • Loading branch information
marchof committed Nov 7, 2020
1 parent fa6a843 commit b902dc5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 64 deletions.
20 changes: 0 additions & 20 deletions jacoco-maven-plugin/pom.xml
Expand Up @@ -31,22 +31,6 @@
<maven>3.0</maven>
</prerequisites>

<dependencyManagement>
<dependencies>
<!-- maven-reporting-impl and slight update of version of its transitive dependency on commons-collections -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -74,10 +58,6 @@
<artifactId>maven-reporting-api</artifactId>
<version>${project.prerequisites.maven}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
46 changes: 23 additions & 23 deletions jacoco-maven-plugin/src/org/jacoco/maven/AbstractReportMojo.java
Expand Up @@ -16,12 +16,12 @@
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;
Expand All @@ -30,7 +30,8 @@
* 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.
Expand Down Expand Up @@ -86,29 +87,16 @@ 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;
}

/**
Expand All @@ -129,7 +117,6 @@ List<String> getExcludes() {
return excludes;
}

@Override
public boolean canGenerateReport() {
if (skip) {
getLog().info(
Expand All @@ -153,11 +140,25 @@ public boolean canGenerateReport() {

abstract boolean canGenerateReportRegardingClassesDirectory();

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;
Expand All @@ -170,8 +171,7 @@ public void execute() throws MojoExecutionException {
}
}

@Override
protected void executeReport(final Locale locale)
private void executeReport(final Locale locale)
throws MavenReportException {
try {
final ReportSupport support = new ReportSupport(getLog());
Expand Down
3 changes: 1 addition & 2 deletions jacoco-maven-plugin/src/org/jacoco/maven/FileFilter.java
Expand Up @@ -17,7 +17,6 @@
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;

Expand Down Expand Up @@ -94,7 +93,7 @@ public String getExcludes() {
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;
Expand Down
Expand Up @@ -107,7 +107,7 @@ void loadExecutionData(final ReportSupport support) throws IOException {

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)) {
Expand Down Expand Up @@ -141,12 +141,10 @@ void createReport(final IReportGroupVisitor visitor,
}
}

@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")) {
Expand All @@ -168,7 +166,7 @@ public String getName(final Locale locale) {
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);
Expand All @@ -192,7 +190,7 @@ private MavenProject findProjectFromReactor(final Dependency d) {
try {
depVersionAsRange = VersionRange
.createFromVersionSpec(d.getVersion());
} catch (InvalidVersionSpecificationException e) {
} catch (final InvalidVersionSpecificationException e) {
throw new AssertionError(e);
}

Expand Down
10 changes: 4 additions & 6 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportITMojo.java
Expand Up @@ -58,7 +58,7 @@ boolean canGenerateReportRegardingDataFiles() {

@Override
boolean canGenerateReportRegardingClassesDirectory() {
return new File(getProject().getBuild().getOutputDirectory()).exists();
return new File(project.getBuild().getOutputDirectory()).exists();
}

@Override
Expand All @@ -76,16 +76,14 @@ void addFormatters(final ReportSupport support, final Locale locale)
@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")) {
Expand Down
10 changes: 4 additions & 6 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportMojo.java
Expand Up @@ -53,7 +53,7 @@ boolean canGenerateReportRegardingDataFiles() {

@Override
boolean canGenerateReportRegardingClassesDirectory() {
return new File(getProject().getBuild().getOutputDirectory()).exists();
return new File(project.getBuild().getOutputDirectory()).exists();
}

@Override
Expand All @@ -71,16 +71,14 @@ void addFormatters(final ReportSupport support, final Locale locale)
@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")) {
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -32,6 +32,8 @@ <h3>Non-functional Changes</h3>
<li>JaCoCo now depends on ASM 9.0
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1094">#1094</a>,
<a href="https://github.com/jacoco/jacoco/issues/1097">#1097</a>).</li>
<li>Maven plug-in has no dependency on <code>maven-reporting-impl</code> any more
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1121">#1121</a>).</li>
</ul>


Expand Down

0 comments on commit b902dc5

Please sign in to comment.