Packages from running integration module are not excluded - jacoco

I´m running some integration test from module A getting first all the classes from module B, what I´m interested is in not add in the coverture some packages from B, but also some package from A.
I´m using excludes in the jacocco plugin, and all the packages that I´m specify from B are exlude perfectly, but the ones from A it dont
Here my config
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>prepare-jacoco-service-test-agent</id>
<!-- default pre-integration is to late for the process-exec-maven-plugin -->
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>failsafe.argLine</propertyName>
<includes>
<include>com.in*</include>
</includes>
<excludes>
<exclude>com.B.dg.*</exclude>
<exclude>com.B.es.core.server.vertx.*</exclude>
<!--f2e-core-test-->
<exclude>com.B.es.client.service.*</exclude>
<exclude>com.B.es.core.service.test.*</exclude>
<exclude>com.B.es.core.test.helper.*</exclude>
<exclude>com.B.es.coretest.*</exclude>
<!--f2e-mock-->
<exclude>com.A.f2e.*</exclude>
</excludes>
<classDumpDir>${project.build.outputDirectory}</classDumpDir>
<destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>report-jacoco-service-test-results</id>
<goals>
<goal>report-integration</goal>
</goals>
<phase>verify</phase>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
<outputDirectory>${project.build.directory}/coverage-reports/out/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Any idea why any package of module A it´s not excluded?

By configuring exclusions for prepare-agent-integration you specified that packages should be excluded from instrumentation, but not from report. You need to configure exclusions for report-integration instead.

Related

Exclude Encrypted Jar from jacoco analysis

How to exclude cncrypted jar from jacoco analysis as it is giving ClassNotFound Exception ?
I have tried to remove the jar using excludes inside configuration in the jacoco-maven-plugin. But that didn't work. Someone please help.
Thank You in Advance.
Here is the plugin configuration i am using.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/companyname/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
In my case following configuration for jacoco executions worked.
<excludes>
<exclude>**/myJar.jar/**</exclude>
</excludes>

axistools-maven-plugin wsdl2java how to set different packages for each wsdl

I want use the axistools-maven-plugin to generate java classes from wsdl.
Now I have this code and it works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<executions>
<execution>
<id>ax-ws-autogen</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceDirectory>src/main/resources/wsdl</sourceDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
</wsdlFiles>
<packageSpaces>my.package.code.first</packageSpaces>
<testCases>false</testCases>
<serverSide>false</serverSide>
<subPackageByFileName>false</subPackageByFileName>
<outputDirectory>src/main/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Now I need to use another wsdl. So I want add it to this plugin, but in another packages. How can I to do?
I see that I can add wsdl file in <wsdlFiles> tag, but I don't know how to add the new package for the new wsdl.
With CXF I can set different wsdl and packages in the <wsdlOptions> tag, but with axis I don't know how to do.
Can you help me, please?
I solved my problem setting <subPackageByFileName> = true and changing <packageSpace> in a general package:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<executions>
<execution>
<id>ax-ws-autogen</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceDirectory>src/main/resources/wsdl</sourceDirectory>
<wsdlFiles>
<wsdlFile>myfirstwsdl.wsdl</wsdlFile>
<wsdlFile>mysecondwsdl.wsdl</wsdlFile>
</wsdlFiles>
<packageSpace>my.package.code</packageSpace>
<testCases>false</testCases>
<serverSide>false</serverSide>
<subPackageByFileName>true</subPackageByFileName>
<outputDirectory>src/main/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
In this way I get a single package my.package.code that contain two packages:
my.package.code.myfirstwsdl with all classes of my first wsdl;
my.package.code.mysecondwsdl with all classes of my second wsdl.

Could cxf maven plugin generate classes for a directory of wsdl files?

I use cxf-codgen-plugin in maven to generate classes for web services. Here is a part of my pom.xml
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/wsdl/ws1.wsdl</wsdl>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/wsdl/ws2.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is every time I want to add a new WSDL I had to add a line in the pom.xml like this:
<wsdlOption>
<wsdl>${basedir}/wsdl/ws2.wsdl</wsdl>
</wsdlOption>
What I want to do is to specify a directory and cxf will generate classes for all the WSDL files in this directory.
Is there a way to do this?
Thanks.
I found the way to do this:
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlRoot>${basedir}/wsdl</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>

maven-ear-plugin unpack, filter and repack jarModule

a jarModule that is packaged in my ear file contains a persistence.xml file that I need to remove as part of the package phase. The best I can do is with:
<JarModule>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<unpack>true</unpack> -->
</JarModule>
<packagingExcludes>*/META-INF/persistence.xml,*/META-INF/orm.xml</packagingExcludes>
but I need the jar to be repacked before the packaging the ear.
Any suggestions?
Thanks
You can use the TrueZIP Maven PLugin to remove files from an archive:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>remove-from-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>remove</goal>
</goals>
<configuration>
<fileset>
<directory>${project.build.directory}\<someFolders>\<I-contain-persistence-xml.jar></directory>
<includes>
<include>**\persistence.xml</include>
<include>**\orm.xml</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Archives (*.jar, *.war, ...) can be used like directories with TrueZIP. As shown on the usage page you can move or copy files in archives easily.

Cobertura code coverage is wrong

I am have been trying to setup code coverage on my local Jenkins server with Maven. It would seem that my tests are not being included in the coverage reports.
I have the following in my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<check>
<haltOnFailure>false</haltOnFailure>
<totalLineRate>85</totalLineRate>
</check>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
and here is where I define the tests to be run
<plugin>
<!-- Separates the unit tests from the integration tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
<trimStackTrace>false</trimStackTrace>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test*.java</include>
</includes>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
And on my Jenkins server I am have the following:
Jenkins Configuration:
Sonar
Sonar name:sonar local 3.5.1
server url: http://local host:9000
Project level:
publish Cobertura Coverate Report:
xml report pattern: **/target/site.covertura/coverage.xml
But when I run either the maven task "mvn cobertura:cobertura" or view the sonar reports in Jenkins, all the coverage is at 0%, which makes me think my unit and integration tests are not being seen.
Is this a problem with the way my pom separates unit and integration tests?
cobertura can't look into integration test to see code coverage.
Try a look at code coverage by integration tests with sonar
and at separating integration and unit tests
To make a short story : you must launch the jacoco maven plugin who will set two properties, one for unit tests, the another for it tests, and launch surefire and failsafe with these properties.
And after, you can show result in sonar in separated applet.
In my own pom file, you will se a part for enabled jacoco :
<properties>
<!-- Coverage and report -->
<jacoco.destFile.unit>${project.build.directory}/jacoco-unit.target</jacoco.destFile.unit>
<jacoco.destFile.it>${project.build.directory}/jacoco-it.target</jacoco.destFile.it>
<coverage.reports.dir>${project.build.directory}/coverage-reports</coverage.reports.dir>
<version.surefire>2.12.4</version.surefire>
<!-- Sonar -->
<sonar.jacoco.itReportPath>${jacoco.destFile.it}</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${jacoco.destFile.unit}</sonar.jacoco.reportPath>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
</properties>
<build>
....
<plugins>
<!-- Jacoco configuration -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.0.201210061924</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.argLine.unit</propertyName>
<destFile>${jacoco.destFile.unit}</destFile>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.argLine.it</propertyName>
<destFile>${jacoco.destFile.it}</destFile>
</configuration>
</execution>
</executions>
</plugin>
<!-- And in the surefire and failsafe plugins you need to enable jacoco like this ->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${version.surefire}</version>
</dependency>
</dependencies>
<configuration>
<argLine>${jacoco.argLine.unit}
-Dfile.encoding=${project.build.sourceEncoding} -Xmx512m</argLine>
<forkMode>always</forkMode>
<parallel>classes</parallel>
</configuration>
</plugin-->
<!-- Play the /src/test/java/**IT.java with goal verify -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.surefire}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${version.surefire}</version>
</dependency>
</dependencies>
<configuration>
<forkMode>pertest</forkMode>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<argLine>${jacoco.argLine.it}
-Dfile.encoding=${project.build.sourceEncoding} -Xmx512m</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
In Jenkins, you must setup the "postbuild" JaCoCo plugins with
"**/**.target" for path to exec files
Hope this will help you.