Skip to content

Commit

Permalink
Merge pull request quarkusio#6244 from stuartwdouglas/code-coverage
Browse files Browse the repository at this point in the history
Initial Support for Code coverage
  • Loading branch information
gsmet authored Jan 31, 2020
2 parents 69538a5 + 3a35468 commit 734c546
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 134 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ By default the build will use the native image server. This speeds up the build,
not being invalidated correctly in some cases. To run a build with a new instance of the server you can use
`./mvnw install -Dnative-image.new-server=true`.

### Test Coverage

Quarkus uses Jacoco to generate test coverage. If you would like to generate the report run `mvn install -Ptest-coverage`,
then change into the `coverage-report` directory and run `mvn package`. The code coverage report will be generated in
`target/site/jacoco/`.

This currently does not work on Windows as it uses a shell script to copy all the classes and files into the code coverage
module.

## The small print

This project is an open source project, please act responsibly, be nice, polite and enjoy!
Expand Down
35 changes: 35 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<keycloak.docker.image>quay.io/keycloak/keycloak:8.0.1</keycloak.docker.image>

<unboundid-ldap.version>4.0.13</unboundid-ldap.version>

<!-- Code Coverage Properties-->
<jacoco.agent.argLine></jacoco.agent.argLine>
<jacoco.version>0.8.5</jacoco.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -166,6 +170,7 @@
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -636,5 +641,35 @@
</pluginManagement>
</build>
</profile>

<profile>
<id>test-coverage</id>
<properties>
<jacoco.agent.argLine>${jacoco.activated.agent.argLine}</jacoco.agent.argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<includes>
<include>io.quarkus*</include>
</includes>
<propertyName>jacoco.activated.agent.argLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions ci-templates/jvm-build-steps.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
jdk: 1.8
extra:

steps:
- task: CacheBeta@0 #we know the very first job will have restored or created this, so this will never write built artifacts to the cache
Expand Down
21 changes: 19 additions & 2 deletions ci-templates/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,27 @@ stages:
steps:
- template: jvm-build-steps.yaml
parameters:
# we only generate the PDF documentation once for the initial JDK 8 build
extra: '-Ddocumentation-pdf'
# we only generate the PDF documentation and test coverage once for the initial JDK 8 build
extra: '-Ddocumentation-pdf -Ptest-coverage'
- publish: $(MAVEN_CACHE_FOLDER)
artifact: $(Build.SourceVersion)-BuiltMavenRepo

- task: Maven@3
displayName: 'Aggregate Code Coverage'
inputs:
mavenPomFile: 'coverage-report/pom.xml'
goals: 'install'
mavenOptions: $(MAVEN_OPTS)
options: '-B --settings azure-mvn-settings.xml -Dno-native -Dno-format'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: 'coverage-report/target/site/jacoco/jacoco.xml'
pathToSources: 'coverage-report/src/main/java'
reportDirectory: 'coverage-report/target/site/jacoco/'
failIfCoverageEmpty: true

- template: prepare-cache.yaml

- stage: run_jvm_tests_stage${{parameters.expectUseVMs}}
Expand Down
1 change: 1 addition & 0 deletions coverage-report/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/main/java
87 changes: 87 additions & 0 deletions coverage-report/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<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>
<artifactId>quarkus-build-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../build-parent/pom.xml</relativePath>
</parent>
<artifactId>quarkus-coverage-report</artifactId>
<name>Quarkus Test Coverage Report</name>
<description>Aggregates and compiles jacoco test coverage report.
This does not currently work on Windows.
</description>
<packaging>pom</packaging>

<properties>
<format.skip>true</format.skip>
</properties>


<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>copy-classes-and-source</id>
<phase>test-compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${project.basedir}/prepare.sh</executable>
<workingDirectory>${project.basedir}</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>merge-reports</id>
<phase>test-compile</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.basedir}/../</directory>
<includes>
<include>**/target/jacoco.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<title>Quarkus</title>
<footer>Code Coverage Report for Quarkus ${project.version}</footer>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
28 changes: 28 additions & 0 deletions coverage-report/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
rm -r target/classes src/main/java
mkdir -p target/classes
mkdir -p src/main/java

for j in '../extensions' '../core' '../devtools' '../independent-projects/'
do
for i in `find $j -regex .*target/classes`
do
cp -r $i/* target/classes/
done
for i in `find $j -regex .*src/main/java`
do
cp -r $i/* src/main/java/
done
done

#we don't care about classes in the 'graal' package, because they are only used in native image generation
find target/classes/ -name graal -exec rm -r {} \;

#antlr generated code
rm -r target/classes/io/quarkus/panacheql/internal

#we don't care about the document processor
rm -r target/classes/io/quarkus/annotation/processor/generate_doc

#needed to make sure the script always succeeds
echo "complete"
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ public String getOptionValue(String name) {

public String[] getOptionValues(String name) {
final Object o = options.get(name);
return o == null ? null : o instanceof String ? new String[] { o.toString() } : (String[]) o;
if (o == null) {
return null;
}
if (o instanceof String[]) {
return (String[]) o;
}
return new String[] { o.toString() };
}

public boolean isEmpty() {
Expand Down
131 changes: 0 additions & 131 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,137 +159,6 @@
</plugins>
</build>
</profile>
<!--
JaCoCo based code coverage analysis

mvn -Pjacoco clean verify
mvn antrun:run@jacoco-all-in-one-report -Pjacoco-report
open target/jacoco-report/index.html
-->
<profile>
<id>jacoco</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-prepare</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>io.quarkus.it.*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>jacoco-report-per-module</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jacoco-report</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>copy</goal>
</goals>
<phase>process-test-resources</phase>
<inherited>false</inherited>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
<outputDirectory>${project.build.directory}/jacoco-jars</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>jacoco-all-in-one-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<inherited>false</inherited>
<configuration>
<target>
<taskdef name="report" classname="org.jacoco.ant.ReportTask">
<classpath path="${project.build.directory}/jacoco-jars/org.jacoco.ant.jar"/>
</taskdef>
<echo>Creating JaCoCo for Quarkus code coverage reports</echo>
<report>
<executiondata>
<fileset dir="${basedir}">
<include name="**/target/jacoco.exec"/>
</fileset>
</executiondata>
<structure name="JaCoCo for Quarkus">
<classfiles>
<fileset dir="${basedir}">
<include name="**/*${project.version}.jar"/>
<exclude name="**/target/lib/*.jar"/>
<exclude name="independent-projects/**/*.jar"/>
<exclude name="integration-tests/**/*.jar"/>
<exclude name="**/*quarkus-cli-${project.version}.jar"/>
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<dirset dir="${basedir}">
<include name="**/src/main/java"/>
</dirset>
</sourcefiles>
</structure>
<html destdir="target/jacoco-report"/>
<xml destfile="target/jacoco-report/report.xml"/>
</report>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>tcks</id>
<activation>
Expand Down

0 comments on commit 734c546

Please sign in to comment.