This commit is contained in:
Clebert Suconic 2017-08-02 12:51:57 -04:00
commit 9672dc23e2
5 changed files with 257 additions and 1 deletions

View File

@ -5,6 +5,7 @@
* [IDE Integration](ide.md) * [IDE Integration](ide.md)
* [Building](building.md) * [Building](building.md)
* [Tests](tests.md) * [Tests](tests.md)
* [Code coverage report](code-coverage-report.md)
* [Code Formatting](formatting.md) * [Code Formatting](formatting.md)
* [Validating releases](validating-releases.md) * [Validating releases](validating-releases.md)
* [Notes for Maintainers](maintainers.md) * [Notes for Maintainers](maintainers.md)

View File

@ -0,0 +1,37 @@
# Code coverage report
## Getting JaCoCo exec files
Before you can generate code coverage report by JaCoCo tool,
you need to get data about what lines of code were executed
during testing. These information are collected by JaCoCo
agent and stored in JaCoCo exec files. All you need to do
is run the tests with `jacoco` maven profile.
```
mvn test -Ptests,extra-tests,jacoco
```
## Generate JaCoCo reports
```
mvn verify -Pjacoco-generate-report -DskipTests
```
For generating JaCoCo reports only run the maven build
with profile `jacoco-generate-report` as it is shown
in the example above. After the command was executed,
in directory `target/jacoco-report` you can find
reports in HTML and XML formats.
## Merge JaCoCo exec files to one
Since ActiveMQ Artemis is divided into several modules,
exec files are generated for each module separately.
If you need to merge them together to have all data
in one place, you can do it by command below.
```
mvn jacoco:merge -N -Pjacoco
```

192
pom.xml
View File

@ -102,6 +102,8 @@
<arquillian-weld-embedded.version>2.0.0.Beta3</arquillian-weld-embedded.version> <arquillian-weld-embedded.version>2.0.0.Beta3</arquillian-weld-embedded.version>
<owb.version>1.7.0</owb.version> <owb.version>1.7.0</owb.version>
<arquillian.version>1.1.11.Final</arquillian.version> <arquillian.version>1.1.11.Final</arquillian.version>
<version.org.jacoco>0.7.9</version.org.jacoco>
<version.org.jacoco.plugin>0.7.9</version.org.jacoco.plugin>
<owasp.version>1.4.3</owasp.version> <owasp.version>1.4.3</owasp.version>
@ -648,6 +650,18 @@
<version>${arquillian.version}</version> <version>${arquillian.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${version.org.jacoco}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>${version.org.jacoco}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>javax.enterprise</groupId> <groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId> <artifactId>cdi-api</artifactId>
@ -947,6 +961,179 @@
<skipTests>true</skipTests> <skipTests>true</skipTests>
</properties> </properties>
</profile> </profile>
<!-- This profile generates jacoco coverage files. To generate html report use "-Pjacoco-generate-report" -->
<profile>
<id>jacoco</id>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
</dependency>
</dependencies>
<properties>
<!-- Property set by Jacoco plugin -->
<jacoco.agent></jacoco.agent>
<activemq-surefire-argline>-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dlogging.configuration="file:${activemq.basedir}/tests/config/logging.properties"
-Djava.library.path="${activemq.basedir}/artemis-native/bin" -Djgroups.bind_addr=localhost -Dorg.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory.localBindAddress=localhost
-Djava.net.preferIPv4Stack=true -Dbasedir=${basedir}
@{jacoco.agent} -Djacoco.agent=@{jacoco.agent}
</activemq-surefire-argline>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-prepare</id>
<phase>validate</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<!-- Jacoco sets this property with agent configuration.
This property is passed to maven-surefire-plugin -->
<propertyName>jacoco.agent</propertyName>
</configuration>
</execution>
<execution>
<id>merge</id>
<phase>none</phase>
<goals>
<goal>merge</goal>
</goals>
</execution>
</executions>
<configuration>
<fileSets>
<fileSet implementation="org.apache.maven.shared.model.fileset.FileSet">
<directory>${activemq.basedir}</directory>
<includes>
<include>**/*.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- This profile generates html report from jacoco coverage files. Use "-Pjacoco" profile to generate coverage. -->
<profile>
<id>jacoco-generate-report</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<!-- Copy jacoco ant jar. This is needed to generate jacoco report with maven-antrun-plugin -->
<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>${version.org.jacoco.plugin}</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>
<executions>
<execution>
<phase>post-integration-test</phase>
<goals><goal>run</goal></goals>
<inherited>false</inherited>
<configuration>
<target>
<property name="result.report.dir" location="target/jacoco-report"/>
<taskdef name="report" classname="org.jacoco.ant.ReportTask">
<classpath path="${project.build.directory}/jacoco-jars/org.jacoco.ant.jar"/>
</taskdef>
<echo>Creating JaCoCo ActiveMQ Artemis test coverage reports...</echo>
<report>
<executiondata>
<fileset dir="${basedir}">
<include name="**/target/jacoco.exec"/>
</fileset>
</executiondata>
<structure name="JaCoCo ActiveMQ Artemis">
<classfiles>
<fileset dir="${activemq.basedir}/artemis-boot/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-cdi-client/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-cli/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-commons/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-core-client/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-dto/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-jdbc-store/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-jms-client/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-jms-server/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-journal/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-native/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-ra/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-rest/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-selector/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-server/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-server-osgi/target/classes"/>
<fileset dir="${activemq.basedir}/artemis-service-extensions/target"/>
<fileset dir="${activemq.basedir}/artemis-web/target/classes"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${activemq.basedir}/artemis-boot/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-cdi-client/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-cli/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-commons/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-core-client/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-dto/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-jdbc-store/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-jms-client/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-jms-server/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-journal/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-native/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-ra/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-rest/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-selector/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-server/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-server-osgi/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-service-extensions/src/main/java"/>
<fileset dir="${activemq.basedir}/artemis-web/src/main/java"/>
</sourcefiles>
</structure>
<html destdir="\${result.report.dir}"/>
<xml destfile="\${result.report.dir}/report.xml"/>
</report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${version.org.jacoco.plugin}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles> </profiles>
<build> <build>
@ -1191,6 +1378,11 @@
<artifactId>artemis-maven-plugin</artifactId> <artifactId>artemis-maven-plugin</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</plugin> </plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.org.jacoco.plugin}</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>

21
scripts/jacoco.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
mvn -Ptests,jacoco -DfailIfNoTests=false -Pextra-tests -DskipStyleCheck=true -DskipPerformanceTests=false -Dtest=$1 test
mvn jacoco:merge -N -Pjacoco
mvn verify -Pjacoco-generate-report -DskipTests

View File

@ -110,6 +110,11 @@ public final class SpawnedVMSupport {
commandList.add("-Djava.util.logging.config.file=" + loggingConfigFile + " "); commandList.add("-Djava.util.logging.config.file=" + loggingConfigFile + " ");
} }
String jacocoAgent = System.getProperty("jacoco.agent");
if (jacocoAgent != null && !jacocoAgent.isEmpty()) {
commandList.add(jacocoAgent);
}
String loggingPlugin = System.getProperty("org.jboss.logging.Logger.pluginClass"); String loggingPlugin = System.getProperty("org.jboss.logging.Logger.pluginClass");
if (loggingPlugin != null) { if (loggingPlugin != null) {
commandList.add("-Dorg.jboss.logging.Logger.pluginClass=" + loggingPlugin + " "); commandList.add("-Dorg.jboss.logging.Logger.pluginClass=" + loggingPlugin + " ");