Jacoco on the fly and offline instrumentation for multimodule project which has aspectj, not working

1,724 views
Skip to first unread message

er.yogesh...@gmail.com

unread,
Dec 28, 2016, 2:47:34 AM12/28/16
to JaCoCo and EclEmma Users
I am using aspectj compile time weaving and jacoco offline instrumentation in maven.
also we have multiple modules and using aspectj in one module only, so i want to use on-the-fly and offline instrumentation both.
On-the-fly for non aspectj module and offline instrumentation for aspectj.
Is it possible?

I need that for unit and integration tests both. Any help would be really helpful?
if someone has github link which solves the problem, would be really helpful

er.yogesh...@gmail.com

unread,
Dec 30, 2016, 8:31:56 AM12/30/16
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
is there any solution for the same?

I tried using offline instrumentation for the aspectj but it fails as war contains the aspectj compiled classes which gets deployed.

Evgeny Mandrikov

unread,
Dec 30, 2016, 3:01:55 PM12/30/16
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
Since you don't provide enough details to understand your difficulties, let me post some links that might be helpful:

er.yogesh...@gmail.com

unread,
Dec 31, 2016, 6:21:47 AM12/31/16
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
here is my profile looks like in pom.xml

<profile>
<id>int-coverage</id>
<activation>
<property>
<name>fitnese</name>
<value>true</value>
</property>
</activation>
<properties>
<!-- Fitnesse run properties -->
<fitnesse.port>9997</fitnesse.port>

<jacoco.outputDir>${project.build.directory}</jacoco.outputDir>
<jacoco.it.execution.data.file>${project.build.directory}/../coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>

<!-- Only unit tests are run by default. -->
<skip.unit.tests>false</skip.unit.tests>
<skip.integration.tests>false</skip.integration.tests>

<ignore.unit.tests.failure>false</ignore.unit.tests.failure>
<ignore.integration.tests.failure>false</ignore.integration.tests.failure>

<ignore.rmp.build>false</ignore.rmp.build>
<!-- The Cargo container type -->
<cargo.container.id>tomcat7x</cargo.container.id>
<!-- The URL of the Zip file based installer for the container that Cargo is to deploy -->
<cargo.container.url>nexus/repositories/public/org/apache/tomcat/apache-tomcat/7.0.55/apache-tomcat-7.0.55.zip</cargo.container.url>
<!-- The location where downloaded container Zip file installers are cached -->
<cargo.container.download.dir>${user.home}/.m2/cargo/containers</cargo.container.download.dir>
<!-- The port used by the forked container -->
<cargo.container.port>8085</cargo.container.port>
<!-- When using Tomcat, the AJP connector listen port -->
<cargo.container.tomcat.ajp.port>5008</cargo.container.tomcat.ajp.port>
<!-- The RMI port used on the container. For Tomcat, this is the value of the /Server/@port attribute. -->
<cargo.container.rmi.port>8206</cargo.container.rmi.port>
<!-- Optional JVM arguments for the forked container that are prepended to the option
that configures the Zommons config location and appended to any debugging
configuration set by cargo.container.jvmargs.debug (See cargo-debug profile.)-->
<cargo.container.jvmargs>-javaagent:${user.settings}/org/jacoco/org.jacoco.agent/0.7.7.201606060606/org.jacoco.agent-0.7.7.201606060606-runtime.jar -XX:MaxPermSize=1024M -Xmx10204m</cargo.container.jvmargs>
<!-- The port to use when the debugger is enabled. -->
<cargo.container.debug.port>8003</cargo.container.debug.port>
<!-- The suspend setting to use when the debugger is enabled. -->
<cargo.container.debug.suspend>n</cargo.container.debug.suspend>
<!-- The debug arguments used to enable debugging on the forked JVM. -->
<cargo.container.debug.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=${cargo.container.debug.suspend},address=${cargo.container.debug.port} -Djava.compiler=NONE</cargo.container.debug.jvmargs>
<cargo.container.jvmargs.debug></cargo.container.jvmargs.debug>
</properties>
<build>
<plugins>
<plugin>
<groupId>uk.co.javahelp.fitnesse</groupId>
<artifactId>fitnesse-launcher-maven-plugin</artifactId>
<version>1.4.2</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>set-up</goal>
<goal>run-tests</goal>
<goal>tear-down</goal>
</goals>
</execution>

</executions>
<configuration>
<port>${fitnesse.port}</port>
<workingDir>${project.basedir}/..</workingDir>
<root>FitNesseRoot</root>
<reportsDir>${project.build.directory}/reports</reportsDir>
<resultsDir>${project.build.directory}/results</resultsDir>
<summaryFile>${project.build.directory}/results/failsafe-summary.xml</summaryFile>
<createSymLink>true</createSymLink>
<excludeOptionalDependencies>false</excludeOptionalDependencies> <!-- Deprecated -->
<deletePluginsProperties>false</deletePluginsProperties> <!-- Note the 's' in "plugins" -->
<alwaysUnpackFitnesse>false</alwaysUnpackFitnesse>
<failIfNoTests>false</failIfNoTests>

</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--<argLine>${failsafeArgLine} -Xmx2048m -XX:MaxPermSize=1024m</argLine>-->
<reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<!--
Skips integration tests if the value of skip.integration.tests property is true
-->
<skipTests>false</skipTests>
<testFailureIgnore>false</testFailureIgnore>
<systemPropertyVariables>
<jacoco-agent.destfile>${jacoco.it.execution.data.file}</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>jacoco-instrument</id>
<phase>test</phase>
<configuration>

<tasks>

<mkdir dir="target/jacoco/backup" />
<!-- backup all classes so that we can instrument the original classes-->
<copy toDir="target/jacoco/backup" verbose="true" overwrite="true">
<fileset dir="target/classes">
<include name="**/*" />
</fileset>
</copy>


<!--<copy toDir="${project.build.directory}/classes" verbose="true" overwrite="true">-->
<!--<fileset dir="${project.build.directory}/generated-classes/jacoco">-->
<!--<include name="**/*.class" />-->
<!--</fileset>-->
<!--</copy>-->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>


</executions>
</plugin>


<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>instrument</id>
<phase>compile</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>

<execution>
<id>pre-integration-test</id>
<phase>test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<classDumpDir>${project.build.directory}/classes</classDumpDir>
</configuration>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>

<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<skip>false</skip>
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>
</dependency>
</dependencies>
</plugin>


<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.15</version>
<configuration>
<container>
<containerId>${cargo.container.id}</containerId>
<zipUrlInstaller>
<url>${cargo.container.url}</url>
<downloadDir>${cargo.container.download.dir}</downloadDir>
</zipUrlInstaller>
<log>${project.build.directory}/cargo/logs/cargo.log</log>

<output>${project.build.directory}/cargo/logs/container.log</output>
<logLevel>debug</logLevel>
<timeout>3600000</timeout>
<systemProperties>
<jacoco-agent.destfile>${jacoco.it.execution.data.file}</jacoco-agent.destfile>
</systemProperties>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
</dependency>
</dependencies>
</container>
<deployables>
<deployable>
<location>${project.build.directory}/abc.war</location>
<type>war</type>
<properties>
<context>/abc</context>
</properties>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<!-- We bring this configuration down into the start goal since this configuration
really only applies to the startup activities. This is particularly relevant
for forked JVM debugging since the stop goal will try to launch another JVM using
the same JVM args if we leave this configuration at the plug-in level. When the
debugger is in use, there will be a port collision and the build will hang. -->
<configuration>
<configuration>
<properties>
<cargo.jvmargs>
${cargo.container.jvmargs.debug}
${cargo.container.jvmargs}
</cargo.jvmargs>
<cargo.servlet.port>${cargo.container.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${cargo.container.tomcat.ajp.port}</cargo.tomcat.ajp.port>
<cargo.rmi.port>${cargo.container.rmi.port}</cargo.rmi.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<!-- We bring this configuration down into the CLI run goal because we need it to apply to the
run goal too. See note in the start goal as to why it is needed in the first place. -->
<configuration>
<configuration>
<properties>
<cargo.jvmargs>
${cargo.container.jvmargs.debug}
${cargo.container.jvmargs}
</cargo.jvmargs>
<cargo.servlet.port>${cargo.container.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${cargo.container.tomcat.ajp.port}</cargo.tomcat.ajp.port>
<cargo.rmi.port>${cargo.container.rmi.port}</cargo.rmi.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
<!-- We bring this configuration down into the stop goal because we need it to apply to the
stop goal too. -->
<configuration>
<configuration>
<properties>
<cargo.servlet.port>${cargo.container.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${cargo.container.tomcat.ajp.port}</cargo.tomcat.ajp.port>
<cargo.rmi.port>${cargo.container.rmi.port}</cargo.rmi.port>
</properties>
</configuration>
</configuration>
</execution>
</executions>


</plugin>

</plugins>
</build>
</profile>

can you please tell me what am it doing wrong:
project structure is:
module1
module2
module3

module 1 is aspectj and use module2 as apectj.

er.yogesh...@gmail.com

unread,
Jan 3, 2017, 10:45:25 AM1/3/17
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
can someone please check , where i am doing wrong?

er.yogesh...@gmail.com

unread,
Jan 4, 2017, 10:39:26 AM1/4/17
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
On Tuesday, January 3, 2017 at 9:15:25 PM UTC+5:30, er.yogesh...@gmail.com wrote:
> can someone please check , where i am doing wrong?

I was able to make it work but i am facing one problem and i am sure i am pretty close but not finding what i need to do:
Here is my pom.xml:


<profile>
<id>int-coverage</id>
<activation>
<property>
<name>fitnese</name>
<value>true</value>
</property>
</activation>
<properties>
<!-- Fitnesse run properties -->
<fitnesse.port>9997</fitnesse.port>

<fitnesse.suitename>FitNesse.Tests</fitnesse.suitename>
<fitnesse.suitename.filter>smoke</fitnesse.suitename.filter>


<jacoco.outputDir>${project.build.directory}</jacoco.outputDir>
<jacoco.it.execution.data.file>${project.build.directory}/../coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>

<!-- Only unit tests are run by default. -->
<skip.unit.tests>false</skip.unit.tests>
<skip.integration.tests>false</skip.integration.tests>

<ignore.unit.tests.failure>false</ignore.unit.tests.failure>
<ignore.integration.tests.failure>false</ignore.integration.tests.failure>

<ignore.rmp.build>false</ignore.rmp.build>
<!-- The Cargo container type -->
<cargo.container.id>tomcat7x</cargo.container.id>
<!-- The URL of the Zip file based installer for the container that Cargo is to deploy -->

<cargo.container.url>http://nexus/content/repositories/public/org/apache/tomcat/apache-tomcat/7.0.55/apache-tomcat-7.0.55.zip</cargo.container.url>


<!-- The location where downloaded container Zip file installers are cached -->
<cargo.container.download.dir>${user.home}/.m2/cargo/containers</cargo.container.download.dir>
<!-- The port used by the forked container -->
<cargo.container.port>8085</cargo.container.port>
<!-- When using Tomcat, the AJP connector listen port -->
<cargo.container.tomcat.ajp.port>5008</cargo.container.tomcat.ajp.port>
<!-- The RMI port used on the container. For Tomcat, this is the value of the /Server/@port attribute. -->
<cargo.container.rmi.port>8206</cargo.container.rmi.port>
<!-- Optional JVM arguments for the forked container that are prepended to the option
that configures the Zommons config location and appended to any debugging
configuration set by cargo.container.jvmargs.debug (See cargo-debug profile.)-->

<cargo.container.jvmargs>-javaagent:${user.settings}/org/jacoco/org.jacoco.agent/0.7.6.201602180812/org.jacoco.agent-0.7.6.201602180812-runtime.jar=destfile=intuit/git/new/master/test/target/../coverage-reports/jacoco-it.exec -XX:MaxPermSize=1024M -Xmx10204m</cargo.container.jvmargs>

<workingDir>${project.basedir}/../../../</workingDir>


<root>FitNesseRoot</root>
<reportsDir>${project.build.directory}/reports</reportsDir>
<resultsDir>${project.build.directory}/results</resultsDir>
<summaryFile>${project.build.directory}/results/failsafe-summary.xml</summaryFile>
<createSymLink>true</createSymLink>
<excludeOptionalDependencies>false</excludeOptionalDependencies> <!-- Deprecated -->
<deletePluginsProperties>false</deletePluginsProperties> <!-- Note the 's' in "plugins" -->
<alwaysUnpackFitnesse>false</alwaysUnpackFitnesse>
<failIfNoTests>false</failIfNoTests>

<launches>
<launch>
<suite>${fitnesse.suitename}</suite>
<suiteFilter>${fitnesse.suitename.filter}</suiteFilter>
</launch>
</launches>
</configuration>
</plugin>

<plugin>


<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>

<configuration>
<append>true</append>
</configuration>


<executions>
<execution>
<id>instrument</id>

<!--<phase>compile</phase>-->


<goals>
<goal>instrument</goal>
</goals>
</execution>

<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>


<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>

<destFile>${jacoco.it.execution.data.file}</destFile>
<propertyName>jacoco-agent.destfile</propertyName>


</configuration>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>post-integration-test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>

</execution>

<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<skip>false</skip>
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>

</configuration>
</execution>
</executions>

</plugin>


<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.15</version>
<configuration>
<container>
<containerId>${cargo.container.id}</containerId>
<zipUrlInstaller>
<url>${cargo.container.url}</url>
<downloadDir>${cargo.container.download.dir}</downloadDir>
</zipUrlInstaller>
<log>${project.build.directory}/cargo/logs/cargo.log</log>

<output>${project.build.directory}/cargo/logs/container.log</output>
<logLevel>debug</logLevel>
<timeout>3600000</timeout>

</container>


<configuration>
<properties>
<cargo.jvmargs>
${cargo.container.jvmargs.debug}
${cargo.container.jvmargs}
</cargo.jvmargs>
<cargo.servlet.port>${cargo.container.port}</cargo.servlet.port>
<cargo.tomcat.ajp.port>${cargo.container.tomcat.ajp.port}</cargo.tomcat.ajp.port>
<cargo.rmi.port>${cargo.container.rmi.port}</cargo.rmi.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>

<deployables>
<deployable>
<location>${project.build.directory}/${project.version}.war</location>
<type>war</type>
<properties>
<context>/</context>


</properties>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>

</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>

</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>

</execution>
</executions>


</plugin>


</plugins>

</build>
<dependencies>
<!-- Unit test code coverage with Sonar. -->


<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>

<scope>test</scope>
</dependency>
</dependencies>
</profile>

this gives me coverage of module 2 module but doesnot give me coverage of module1 which is added as aspectj after binary waving is done.

so if i do the instrument in compile phase before aspectj kicks in, it does give me the coverage of aspectj module and if i do the instrument after the aspectj compile , it gives me coverage of main module which i am building and deploying and has depdendency of module 2 as aspectj.

can you please tell me what i am doing wrong?

Evgeny Mandrikov

unread,
Jan 8, 2017, 8:52:52 AM1/8/17
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
Quite hard to say what you are doing wrong based on just excerpt of pom.xml
In https://github.com/jacoco/jacoco/issues/476#issuecomment-271118961 that discusses similar issue, you can find example of JaCoCo usage with AspectJ Compile-Time Weaving.

er.yogesh...@gmail.com

unread,
Jan 10, 2017, 5:04:39 AM1/10/17
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
I tried it but it gives me coverage only for one class. It doesnot give coverage of ExampleAspectj class.

Evgeny Mandrikov

unread,
Jan 10, 2017, 7:40:01 AM1/10/17
to JaCoCo and EclEmma Users, er.yogesh...@gmail.com
Didn't realized from the beginning that https://github.com/jacoco/jacoco/issues/476 actually was created by you. Please don't cross-post in future! or at worse - add a note about cross-post.

So I'm closing this thread here.

For posterity: please refer to https://github.com/jacoco/jacoco/issues/476#issuecomment-271563549 that contains improved example.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages