Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1241 support report of transitive reactor dependencies #1242

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>commons</artifactId>
<packaging>jar</packaging>

</project>
@@ -0,0 +1,18 @@
/*******************************************************************************
* 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 commons;
public final class Util {
public static String randomString() {
return "notsorandom";
}
}
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>it</artifactId>

<dependencies>
<dependency>
<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,20 @@
/*******************************************************************************
* 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
*
*******************************************************************************/
import org.junit.Test;

public class ItTest {
@Test
public void test() {
service.Service.randomString();
}
}
50 changes: 50 additions & 0 deletions jacoco-maven-plugin.test/it/it-report-aggregate-transitive/pom.xml
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>jacoco</groupId>
<artifactId>setup-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>commons</module>
<module>service</module>
<module>it</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>service</artifactId>

<dependencies>
<dependency>
<groupId>jacoco-it-report-aggregate-transitive</groupId>
<artifactId>commons</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,18 @@
/*******************************************************************************
* 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 service;
public class Service {
public static String randomString() {
return commons.Util.randomString();
}
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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, Jan Wloka - initial API and implementation
*
*******************************************************************************/
import org.codehaus.plexus.util.*;
import java.util.regex.*;

String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) );

if ( !new File( basedir, "it/target/jacoco.exec" ).isFile()) {
throw new RuntimeException( "No execution data in it." );
}

File utilCoverage = new File( basedir, "it/target/site/jacoco-aggregate/commons/commons/Util.html" );
if ( !utilCoverage.isFile() ) {
throw new RuntimeException( "Util class in transitive dependency not covered." );
}
24 changes: 7 additions & 17 deletions jacoco-maven-plugin/src/org/jacoco/maven/ReportAggregateMojo.java
Expand Up @@ -26,6 +26,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.jacoco.report.IReportGroupVisitor;

Expand Down Expand Up @@ -53,7 +54,7 @@
*
* @since 0.7.7
*/
@Mojo(name = "report-aggregate", threadSafe = true)
@Mojo(name = "report-aggregate", threadSafe = true, requiresDependencyResolution = ResolutionScope.TEST)
public class ReportAggregateMojo extends AbstractReportMojo {

/**
Expand Down Expand Up @@ -182,10 +183,9 @@ 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 : project.getDependencies()) {
final Dependency dependency = (Dependency) dependencyObject;
if (scopeList.contains(dependency.getScope())) {
final MavenProject project = findProjectFromReactor(dependency);
for (final Artifact artifact : project.getArtifacts()) {
if (scopeList.contains(artifact.getScope())) {
final MavenProject project = findProjectFromReactor(artifact);
if (project != null) {
result.add(project);
}
Expand All @@ -201,21 +201,11 @@ private List<MavenProject> findDependencies(final String... scopes) {
* selected. For example in case of range <code>[0,2]</code> if version 1 is
* before version 2 in reactor, then version 1 will be selected.
*/
private MavenProject findProjectFromReactor(final Dependency d) {
final VersionRange depVersionAsRange;
try {
depVersionAsRange = VersionRange
.createFromVersionSpec(d.getVersion());
} catch (final InvalidVersionSpecificationException e) {
throw new AssertionError(e);
}

private MavenProject findProjectFromReactor(final Artifact d) {
for (final MavenProject p : reactorProjects) {
final DefaultArtifactVersion pv = new DefaultArtifactVersion(
p.getVersion());
if (p.getGroupId().equals(d.getGroupId())
&& p.getArtifactId().equals(d.getArtifactId())
&& depVersionAsRange.containsVersion(pv)) {
&& d.getVersion().equals(p.getVersion())) {
return p;
}
}
Expand Down