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

Add jacoco.append property to the merge goal #1338

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
invoker.goals.1=clean verify
invoker.goals.2=org.jacoco:jacoco-maven-plugin:check
invoker.profiles.2=check-using-merge-append-file
invoker.buildResult.2=failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2022 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
-->
<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</groupId>
<artifactId>it-merge-append</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>it-merge-append-project1</artifactId>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project1;

public class Example1 {

// coverage provided by project1
public void sayHello() {
System.out.println("Hello");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project1;

public class Example2 {

// coverage provided by project2
public void sayHello() {
System.out.println("Hello");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project1;

import org.junit.Test;

public class Example1Test {

@Test
public void test() {
new Example1().sayHello();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2022 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
-->
<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</groupId>
<artifactId>it-merge-append</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>it-merge-append-project2</artifactId>

<dependencies>
<dependency>
<groupId>jacoco</groupId>
<artifactId>it-merge-append-project1</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project2;

import project1.Example2;

import org.junit.Test;

public class Project1Example2Test {
@Test
public void testProject1ExampleClass2(){
new Example2().sayHello();
}

}
124 changes: 124 additions & 0 deletions jacoco-maven-plugin.test/it/it-merge-append-false/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2022 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
-->
<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</groupId>
<artifactId>setup-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>it-merge-append</artifactId>
<packaging>pom</packaging>

<modules>
<module>it-merge-append-project1</module>
<module>it-merge-append-project2</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>jacoco</groupId>
<artifactId>it-merge-append-project1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>merge</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.parent.build.directory}/merged.exec</destFile>
<append>false</append>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>check-using-merge-append-file</id>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<dataFile>${project.parent.build.directory}/merged.exec</dataFile>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>1</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
25 changes: 25 additions & 0 deletions jacoco-maven-plugin.test/it/it-merge-append-false/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
import java.io.*;
import org.codehaus.plexus.util.*;

String buildLog = FileUtils.fileRead( new File( basedir, "build.log" ) );
if ( buildLog.indexOf( "Loading execution data file" ) < 0 ) {
throw new RuntimeException( "Could not load execution data file" );
}
if ( buildLog.indexOf( "Writing merged execution data to" ) < 0 ) {
throw new RuntimeException( "Could not write merged execution data" );
}
if ( buildLog.indexOf( "Rule violated for class project1.Example1: lines covered ratio is 0, but expected minimum is 1" ) < 0 ) {
throw new RuntimeException( "Expected check failure for project1.Example1 not reported" );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
invoker.goals.1=clean verify
invoker.goals.2=org.jacoco:jacoco-maven-plugin:check
invoker.profiles.2=check-using-merge-append-file
invoker.buildResult.2=success
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2022 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
-->
<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</groupId>
<artifactId>it-merge-append</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>it-merge-append-project1</artifactId>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project1;

public class Example1 {

// coverage provided by project1
public void sayHello() {
System.out.println("Hello");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2009, 2022 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
*
*******************************************************************************/
package project1;

public class Example2 {

// coverage provided by project2
public void sayHello() {
System.out.println("Hello");
}

}
Loading