Skip to content

Commit

Permalink
issue-1533: Setting up generic jacoco and sonar coverage configuratio…
Browse files Browse the repository at this point in the history
…n for multi-module projects.

This is intentionally using a `merge` in a `post-integration-test` since `report-aggregator` does not generate proper reports.
  • Loading branch information
steve-todorov committed Feb 25, 2020
1 parent a09e9be commit 36f4acd
Showing 1 changed file with 97 additions and 98 deletions.
195 changes: 97 additions & 98 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
<strongbox.host>localhost</strongbox.host>
<strongbox.port>48080</strongbox.port>

<!-- Sonar: -->
<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>target/jacoco-merged/jacoco-merged-report/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.exclusions>**/*Test.java,**/*TestIT.java,**/*Exception.java,**/InMemoryOrientDbConfig.java</sonar.exclusions>
<!-- Sonar. -->

<!-- Version properties: -->
<version.maven.indexer>6.0.1-SNAPSHOT</version.maven.indexer>

Expand Down Expand Up @@ -98,7 +105,8 @@
<version.awaitility>4.0.1</version.awaitility>
<version.asm>6.0</version.asm>
<version.jtwig>5.87.0.RELEASE</version.jtwig>
<version.jacoco>0.8.2</version.jacoco>
<version.jacoco>0.8.4</version.jacoco>
<version.sonar-maven-plugin>3.7.0.1746</version.sonar-maven-plugin>
<version.codacy.mvn.plugin>1.1.0</version.codacy.mvn.plugin>
<version.semver>0.9.34-SNAPSHOT</version.semver>
<version.springfox>2.9.2</version.springfox>
Expand Down Expand Up @@ -162,17 +170,15 @@
<inherited>true</inherited>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>-Xmx1024m -Xms512m ${surefireArgLine}</argLine>
<!-- Use @{} (late property evaluation) instead of ${} or jacoco will not write the exec file! -->
<argLine>@{surefireArgLine} -Xmx1024m -Xms512m</argLine>
<includes>
<include>**/*Test</include>
</includes>
<excludes>
<exclude>**/*TestIT</exclude>
</excludes>

<!-- This field needs to be set to 1 or jacoco reports will be incorrect/missing! -->
<forkCount>1</forkCount>

<systemPropertyVariables>
<strongbox.home>${project.build.directory}/strongbox</strongbox.home>
<strongbox.vault>${project.build.directory}/strongbox-vault</strongbox.vault>
Expand All @@ -187,13 +193,6 @@
<strongbox.nuget.download.feed>false</strongbox.nuget.download.feed>
<strongbox.download.indexes>false</strongbox.download.indexes>
</systemPropertyVariables>

<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>
<plugin>
Expand All @@ -203,7 +202,8 @@

<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>${failsafeArgLine}</argLine>
<!-- Use @{} (late property evaluation) instead of ${} or jacoco will not write the exec file! -->
<argLine>@{failsafeArgLine}</argLine>
<systemPropertyVariables>
<strongbox.home>${project.build.directory}/strongbox</strongbox.home>
<strongbox.vault>${project.build.directory}/strongbox-vault</strongbox.vault>
Expand Down Expand Up @@ -239,7 +239,7 @@
<artifactId>strongbox-common-resources</artifactId>
<version>${project.version}</version>
<type>jar</type>

<overWrite>true</overWrite>
<outputDirectory>${strongbox.home}/etc</outputDirectory>
<includes>logback*xml</includes>
Expand All @@ -249,7 +249,7 @@
<artifactId>strongbox-storage-api-resources</artifactId>
<version>${project.version}</version>
<type>jar</type>

<overWrite>true</overWrite>
<outputDirectory>${strongbox.home}</outputDirectory>
<includes>etc/conf/strongbox.yaml</includes>
Expand All @@ -259,7 +259,7 @@
<artifactId>strongbox-common-resources</artifactId>
<version>${project.version}</version>
<type>jar</type>

<overWrite>true</overWrite>
<outputDirectory>${strongbox.home}</outputDirectory>
<includes>etc/**</includes>
Expand All @@ -285,7 +285,7 @@
<goals>deploy -DaltDeploymentRepository=${serverId}::default::${deployUrl}</goals>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down Expand Up @@ -1389,6 +1389,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${version.sonar-maven-plugin}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand All @@ -1400,130 +1405,124 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco}</version>
<inherited>true</inherited>
<configuration>
<append>true</append>
<includes>
<include>org/carlspring/**</include>
</includes>
<excludes>
<exclude>org/carlspring/strongbox/app/*</exclude>
<exclude>org/carlspring/strongbox/config/*</exclude>
<exclude>org/carlspring/strongbox/data/server/InMemoryOrientDbServer.class</exclude>
<exclude>com/orientechnologies/*</exclude>
<exclude>org/orientechnologies/*</exclude>
<exclude>org/springframework/*</exclude>
<exclude>com/hazelcast/*</exclude>
<exclude>*Test.java</exclude>
<exclude>*TestIT.java</exclude>
<exclude>*Exception.java</exclude>
</excludes>
</configuration>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<id>prepare-unit-test-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>


<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Failsafe plugin is executed.
-->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<id>prepare-integration-test-agent</id>
<goals>
<goal>prepare-agent</goal>
<goal>prepare-agent-integration</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<destFile>${project.build.directory}/jacoco/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>

<!-- Merge jacoco-it and jacoco-ut into jacoco-aggregated (necessary for next step) -->
<execution>
<id>merge-results</id>
<phase>verify</phase>
<id>report-unit-tests</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
<outputDirectory>${project.build.directory}/jacoco/jacoco-ut</outputDirectory>
</configuration>
</execution>
<execution>
<id>report-integration-tests</id>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco/jacoco-it.exec</dataFile>
<outputDirectory>${project.build.directory}/jacoco/jacoco-it</outputDirectory>
</configuration>
</execution>
<execution>
<id>merge-unit-and-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<directory>${project.build.directory}/jacoco/</directory>
<includes>
<include>jacoco-it.exec</include>
<include>jacoco-ut.exec</include>
<include>jacoco-*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/jacoco-aggregated.exec</destFile>
<destFile>${project.build.directory}/jacoco-merged/jacoco.exec</destFile>
</configuration>
</execution>

<!-- We need this step for submitting reports to codacy -->
<execution>
<id>report-coverage</id>
<phase>verify</phase>
<id>create-merged-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/jacoco-aggregated.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregated-report</outputDirectory>
<dataFile>${project.build.directory}/jacoco-merged/jacoco.exec</dataFile>
<outputDirectory>${project.build.directory}/jacoco-merged/jacoco-merged-report</outputDirectory>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>codacy</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.gavinmogan</groupId>
<artifactId>codacy-maven-plugin</artifactId>
<version>${version.codacy.mvn.plugin}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- codacy -->
<plugin>
<groupId>com.gavinmogan</groupId>
<artifactId>codacy-maven-plugin</artifactId>
<configuration>
<!-- expects to receive the jacoco.xml aggregated report which comes from the report-coverage execution -->
<coverageReportFile>${project.reporting.outputDirectory}/jacoco-aggregated-report/jacoco.xml</coverageReportFile>
<apiToken>${env.CODACY_API_TOKEN}</apiToken>
<projectToken>${env.CODACY_PROJECT_TOKEN_STRONGBOX}</projectToken>
<commit>${env.GIT_COMMIT}</commit>
<codacyApiBaseUrl>https://api.codacy.com</codacyApiBaseUrl>
<failOnMissingReportFile>false</failOnMissingReportFile>
</configuration>
<executions>
<execution>
<id>post-test</id>
<id>check</id>
<phase>verify</phase>
<goals>
<goal>coverage</goal>
<goal>check</goal>
</goals>
<configuration>
<!-- TODO: We need to set this to true when the coverage increases enough -->
<haltOnFailure>false</haltOnFailure>
<rules>
<rule>
<element>BUNDLE</element>
<excludes>
<exclude>*Test.java</exclude>
<exclude>*TestIT.java</exclude>
</excludes>
<limits>
<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.7</minimum>
</limit>
</limits>
</rule>
</rules>
<dataFile>${project.build.directory}/jacoco-merged/jacoco.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
Expand Down

0 comments on commit 36f4acd

Please sign in to comment.