Skip to content

Commit

Permalink
HV-2046 Enable code coverage with maven build
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Oct 17, 2024
1 parent afee3b9 commit 621d838
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 11 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ stage('Default build') {
install \
"} \
-Pdist \
-Pcoverage \
-Pjqassistant -Pci-build \
${enableDefaultBuildIT ? '' : '-DskipITs'} \
${toTestJdkArg(environments.content.jdk.default)} \
Expand Down
27 changes: 27 additions & 0 deletions build/reports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,31 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>coverage-report</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-report-aggregate</id>
<phase>package</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<dataFileIncludes>
<include>**/*.exec</include>
</dataFileIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
21 changes: 21 additions & 0 deletions engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@
<parallel>tests</parallel>
<threadCount>4</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<excludes>
<exclude>**/ByteBuddy*Test</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>bytebuddy-test</id>
<goals><goal>test</goal></goals>
<phase>test</phase>
<configuration>
<argLine>${surefire.jvm.nojacoco.args}</argLine>
<includes>
<include>**/ByteBuddy*Test</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void disallowStrengtheningInSubType() {
}

@Test
public void allowStrengtheningInSubType() {
public void allowStrengtheningInSubType() throws NoSuchMethodException {
HibernateValidatorConfiguration configuration = Validation.byProvider( HibernateValidator.class ).configure();

configuration.allowOverridingMethodAlterParameterConstraint( true );
Expand All @@ -83,7 +83,7 @@ public void allowStrengtheningInSubType() {
Set<ConstraintViolation<RealizationWithAdditionalMethodParameterConstraint>> violations =
validator.forExecutables().validateParameters(
new RealizationWithAdditionalMethodParameterConstraint(),
RealizationWithAdditionalMethodParameterConstraint.class.getDeclaredMethods()[0],
RealizationWithAdditionalMethodParameterConstraint.class.getDeclaredMethod( "bar", String.class ),
new Object[] { "foo" }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void methodDefinedInOtherTypeHierarchyDoesNotOverride() throws Exception

@Test
public void methodWithNarrowedParameterTypeDoesNotOverride() throws Exception {
Method methodFromBase = SimpleServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = SimpleServiceBase.class.getDeclaredMethod( "doSomething", Number.class );
Method methodFromImpl = SimpleServiceImpl1.class.getDeclaredMethod( "doSomething", Number.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
Expand All @@ -129,7 +129,7 @@ public void methodWithNarrowedParameterTypeDoesNotOverride() throws Exception {

@Test
public void methodWithIntermediateClass() throws Exception {
Method methodFromBase = SimpleServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = SimpleServiceBase.class.getDeclaredMethod( "doSomething", Number.class );
Method methodFromImpl = SimpleServiceImpl2.class.getDeclaredMethod( "doSomething", Number.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
Expand All @@ -141,7 +141,7 @@ public void methodWithIntermediateClass() throws Exception {

@Test
public void methodWithGenerics() throws Exception {
Method methodFromBase = GenericServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = GenericServiceBase.class.getDeclaredMethod( "doSomething", Object.class );
Method methodFromImpl = GenericServiceImpl1.class.getDeclaredMethod( "doSomething", Number.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
Expand All @@ -153,7 +153,7 @@ public void methodWithGenerics() throws Exception {

@Test
public void methodWithGenericsAndIntermediateClass() throws Exception {
Method methodFromBase = GenericServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = GenericServiceBase.class.getDeclaredMethod( "doSomething", Object.class );
Method methodFromImpl = GenericServiceImpl2.class.getDeclaredMethod( "doSomething", Number.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
Expand All @@ -165,10 +165,10 @@ public void methodWithGenericsAndIntermediateClass() throws Exception {

@Test
public void methodWithGenericsAndMultipleIntermediateClasses() throws Exception {
Method methodFromBase = GenericServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = GenericServiceBase.class.getDeclaredMethod( "doSomething", Object.class );
Method methodFromImpl = GenericServiceImpl3.class.getDeclaredMethod( "doSomething", Number.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).as( methodFromImpl + " : " + methodFromBase ).isTrue();

methodFromImpl = GenericServiceImpl2.class.getDeclaredMethod( "doSomething", Integer.class );

Expand All @@ -177,7 +177,7 @@ public void methodWithGenericsAndMultipleIntermediateClasses() throws Exception

@Test
public void methodWithParameterizedSubType() throws Exception {
Method methodFromBase = GenericServiceBase.class.getDeclaredMethods()[0];
Method methodFromBase = GenericServiceBase.class.getDeclaredMethod( "doSomething", Object.class );
Method methodFromImpl = ParameterizedSubType.class.getDeclaredMethod( "doSomething", Object.class );

assertThat( executableHelper.overrides( methodFromImpl, methodFromBase ) ).isTrue();
Expand Down
59 changes: 57 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
<version.versions.plugin>2.17.1</version.versions.plugin>
<version.maven-wrapper-plugin>3.3.2</version.maven-wrapper-plugin>
<version.spotless-maven-plugin>2.43.0</version.spotless-maven-plugin>
<version.jacoco.plugin>0.8.12</version.jacoco.plugin>

<!-- Forbidden API related properties -->
<forbiddenapis-junit.path>forbidden-junit.txt</forbiddenapis-junit.path>
Expand Down Expand Up @@ -358,6 +359,9 @@
<surefire.jvm.args.add-opens></surefire.jvm.args.add-opens>
<surefire.jvm.args.java-version></surefire.jvm.args.java-version>
<surefire.jvm.args.jaxp.strict-args></surefire.jvm.args.jaxp.strict-args>
<!-- JVM args generated by JaCoCo -->
<surefire.jvm.args.jacoco></surefire.jvm.args.jacoco>
<failsafe.jvm.args.jacoco></failsafe.jvm.args.jacoco>
<!--
The arguments below are Shrinkwrap settings taken from
https://github.com/shrinkwrap/resolver/blob/788a3c1148af3a7ebdfdaf817393273f5f5ee17b/impl-maven/src/main/java/org/jboss/shrinkwrap/resolver/impl/maven/bootstrap/MavenSettingsBuilder.java#L80
Expand All @@ -366,8 +370,9 @@
<surefire.jvm.args.shrinkwrap>
-Dmaven.repo.local=${settings.localRepository}
</surefire.jvm.args.shrinkwrap>
<surefire.jvm.args>${surefire.jvm.args.additional} ${surefire.jvm.args.add-opens} ${surefire.jvm.args.illegal-access} ${surefire.jvm.args.shrinkwrap} ${surefire.jvm.args.java-version} ${surefire.jvm.args.commandline} ${surefire.jvm.args.jaxp.strict-args}</surefire.jvm.args>
<failsafe.jvm.args>${surefire.jvm.args.additional} ${surefire.jvm.args.add-opens} ${surefire.jvm.args.illegal-access} ${surefire.jvm.args.shrinkwrap} ${surefire.jvm.args.java-version} ${surefire.jvm.args.commandline} ${surefire.jvm.args.jaxp.strict-args}</failsafe.jvm.args>
<surefire.jvm.nojacoco.args>${surefire.jvm.args.additional} ${surefire.jvm.args.add-opens} ${surefire.jvm.args.illegal-access} ${surefire.jvm.args.shrinkwrap} ${surefire.jvm.args.java-version} ${surefire.jvm.args.commandline} ${surefire.jvm.args.jaxp.strict-args}</surefire.jvm.nojacoco.args>
<surefire.jvm.args>${surefire.jvm.nojacoco.args} @{surefire.jvm.args.jacoco}</surefire.jvm.args>
<failsafe.jvm.args>${surefire.jvm.args.additional} ${surefire.jvm.args.add-opens} ${surefire.jvm.args.illegal-access} ${surefire.jvm.args.shrinkwrap} ${surefire.jvm.args.java-version} ${surefire.jvm.args.commandline} ${surefire.jvm.args.jaxp.strict-args} @{failsafe.jvm.args.jacoco}</failsafe.jvm.args>

<!--
Should be set from the command line.
Expand Down Expand Up @@ -1507,6 +1512,11 @@
<distributionType>bin</distributionType>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco.plugin}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down Expand Up @@ -1848,6 +1858,51 @@
</pluginManagement>
</build>
</profile>

<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*_$logger.class</exclude>
<exclude>**/*_$bundle.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefire.jvm.args.jacoco</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-prepare-agent-integration</id>
<!--
This is necessary in order for the property to be set before we process resources,
such as arquillian.xml in WildFly tests or maven.properties in OSGi tests.
-->
<phase>initialize</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>failsafe.jvm.args.jacoco</propertyName>
<destFile>${project.build.directory}/coverage/jacoco.exec</destFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<!--
WARNING: this MUST be the very last profile,
so that the "report" module is the very last module,
Expand Down

0 comments on commit 621d838

Please sign in to comment.