I have some code which reads the exec file and creates html pages for all of my projects running on a webspehre server. The server is on a remote machine, I have all the source code running on the remote machine copied to my local machine. I need to know how, with the html file generated and the exec file how I can view the source code.
Is this even possible?
To successfully create coverage reports with Jacoco from Maven you should add the jacoco maven plugin to your POM.
As explained on the Jacoco Maven Plugin page you need to add the plugin (with the latest version as of this posting):
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6-SNAPSHOT</version>
</plugin>
And then you need to add extra configuration to tell jacoco what phase to instrument tests and then when to generate the reports
This configuration was taken from one of the example jacoco poms for a JAR project that runs JUnit tests under code coverage and creates a coverage report (target/site/jacoco/index.html).
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6-SNAPSHOT</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<!-- implementation is needed only for Maven 2 -->
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<!-- implementation is needed only for Maven 2 -->
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Related
My belief is that JaCoCo Maven plugins check goal does not support integration tests in a multi module project (where the integration tests are in a different module to the code under test).
I have a project with the following structure:
service
├── webapp
├── lib1
├── lib2
└── integration-test
webapp depends on lib1 and lib2 and builds to a WAR, integration-test uses an in memory container to run webapp and execute tests against it.
My configuration is such that JaCoCo is successfully generating consolidated data files (jacoco.exec and jacoco-it.exec in service/target/) for unit tests in {webapp, lib1, lib2} AND integration test coverage for the tests run in integration-test.
When adding in the configuration for check I get this output from the plugin.
[INFO] --- jacoco-maven-plugin:0.7.8:check (default-check) # integration-test ---
[INFO] Skipping JaCoCo execution due to missing classes directory:/home/mark/workspace/service/integration-test/target/classes
The error is accurate, as the integration-test module has only test source, so there is no target/classes directory. Adding a source directory didn't help, check failed indicating 0% coverage because there was no applicable class files in the target/classes directory.
From this (and looking at the check Mojo source) it seems the check goal requires the classes directories of all the modules that it is instrumenting (webapp, lib1, lib2).
No such configuration exists in check that allows me to specify where the classes directories nor does it looks like it supports such a feature looking at the source.
Root / parent pom.xml
<properties>
<sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
<-- Note, I am using build/plugins/plugin - not build/pluginManagement/plugin
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
</configuration>
</execution>
<execution>
<id>agent-for-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.itReportPath}</destFile>
</configuration>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
<configuration>
<dataFile>${sonar.jacoco.itReportPath}</dataFile>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9800</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
integration-test pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skipTests}</skipTests>
<argLine>${argLine} -Duser.timezone=UTC -Xms256m -Xmx256m</argLine>
<reuseForks>false</reuseForks>
</configuration>
</execution>
</executions>
</plugin>
On my maven project, I have a different log4j configuration for development and integration environment and also different ones for test purposes than for the main usage of my webapp. Located in :
src/main/resources/dev/log4j.properties
src/main/resources/int/log4j.properties
src/test/resources/dev/log4j_test.properties
src/test/resources/int/log4j_test.properties
So I have different profiles (DEV / INT) to manage thoses differences...
And for surefire (used for unit testing) and failsafe (used for integration testing) plugin I added some configuration :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<log4j.configuration>file:${basedir}/${profile.test.resource}/log4j_test.properties</log4j.configuration>
</systemPropertyVariables>
<!-- Stop the integration tests after the first failure to keep in database
the content of the failed test. -->
<skipAfterFailureCount>1</skipAfterFailureCount>
<includes>
<!-- Include only integration tests -->
<include>**/*IntegrationTest.java</include>
</includes>
<skip>${skip.integration.tests}</skip>
</configuration>
</plugin>
But now I'm adding gwt-maven-plugin for GWT specific unit testing in DEV mode.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>Appication.html</runTarget>
<webappDirectory>${webappDirectory}</webappDirectory>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundles>
...
</i18nMessagesBundles>
<extraJvmArgs>${gwt.extra.args}</extraJvmArgs>
<style>${compile.style}</style>
<module>${module.name}</module>
</configuration>
</plugin>
Is it possible to configure it to point on a specific / filtered lop4j as I did for surefire and failsafe ?*
Thanks,
You can pass system properties in extraJvmArgs
First the requirement:
I need to write code that consumes a SOAP service and build it as an OSGi bundle that can be deployed in Apache Sling. The build is done using Maven 3.0.3
What I have done so far:
I created a maven module and used this for generating SOAP client classes: https://jax-ws-commons.java.net/jaxws-maven-plugin/usage.html. I had to remove the plugin dependency jaxws-tools version 2.2.5 as it was not supporting the -encoding parameter to wsimport. Removing it automatically downloads version 2.2.8 and it works fine as it is a dependency for the POM.
Next, I changed the package type to bundle and included maven-bundle-plugin and maven-scr-plugin to package the generated code as a OSGi bundle and built it using Maven
Finally I deployed it to Sling running locally as a standalone application.
Following are the issues I faced in the given order:
javax.jws package unresolved - I included this as a private-package under configurations for the maven-bundle-plugin
Similar packages that were unresolved were added which includes:
javax.xml.ws
javax.xml.ws.handler
javax.xml.ws.spi
javax.xml.ws.spi.http
javax.xml.ws.wsaddressing
After adding these to the private-package, I started getting this error:
(javax.xml.ws.WebServiceException: Provider com.sun.xml.internal.ws.spi.ProviderImpl not found) javax.xml.ws.WebServiceException: Provider com.sun.xml.internal.ws.spi.ProviderImpl not found
Root Cause: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl not found by org.apache.felix.http.jetty
This is where I hit a roadblock which I am not able to move past.
What I have tried so far to fix this based on numerous answers on google
tried to include this line in the sling.properties file:
sling.bootdelegation.com.sun=com.sun.*
Tried adding this line
sling.system.packages.simple=com.sun.xml.internal.ws.spi.ProviderImpl
Tried adding this line
sling.bootdelegation.class.com.sun.xml.internal.ws.spi.ProviderImpl=com.sun.xml.internal.ws.spi
Tried adding all the packages mentioned earlier to the org.osgi.framework.system.packages property as well as to the jre-1.6 property
After doing this, I can see that these packages are now being exposed by the system bundle. But only the javax.jws is showing as resolved. All other bundles still show as unresolved.
Tried all possible combinations of export-packages.
Even tried to remove unresolved packages as suggested by some posts
I am using Maven 3.0.3, JDK 1.6.0_43, Apache Sling org.apache.sling.launchpad.base.jar 2.4.0 all of which is running on my Mac Book Pro with OSX 10.8.5
Here is my POM snippet that is relevant to this question. If more information is needed I can provide the same as well
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Private-Package>
<!--javax.jws,-->
javax.xml.ws,
javax.xml.ws.handler,
javax.xml.ws.spi,
javax.xml.ws.spi.http,
javax.xml.ws.wsaddressing
</Private-Package>
<!--
<Export-Package>
com.sun.xml.internal.ws.spi
</Export-Package>
<Import-Package>
!javax.xml.ws,*
</Import-Package>
-->
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The name of your generated source package -->
<packageName>com.mycompany.mypackage</packageName>
<wsdlUrls>
<wsdlUrl>http://localhost/mysoapservice?WSDL</wsdlUrl>
</wsdlUrls>
<extension>true</extension>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${project.build.directory}/endorsed</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/endorsed</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.9</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help would be greatly appreciated. Waiting for a response in anticipation.
I have a maven web application(Spring+ApacheCXF webservices) and have a couple of IntegrationTests(*IT.java). I want to run integration tests using failsafe plugin by deploying the war file using cargo-maven plugin.
Here is my pom configuration:
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.3</version>
<configuration>
<container>
<containerId>jboss51x</containerId>
<home>C:/jboss-5.1.0.GA</home>
<append>false</append>
<log>${project.build.directory}/logs/jboss51x.log</log>
<output>${project.build.directory}/logs/jboss51x.out</output>
<timeout>300000</timeout>
</container>
<configuration>
<type>existing</type>
<home>C:/jboss-5.1.0.GA/server/default</home>
<properties>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.jboss.configuration>default</cargo.jboss.configuration>
<cargo.rmi.port>1099</cargo.rmi.port>
<cargo.logging>high</cargo.logging>
</properties>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>admin-services</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deployer-deploy</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>deployer-undeploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>failsafe-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
But the problem is cargo plugin deploys the WAR file and immediately failsafe plugin is trying to execute the IntegrationTests, and by that time application is not deployed so tests are failing.
With the same configuration I am able to run the integration tests in two steps successfully.
1. execute cargo:deployer-deploy
2. execute integration-test
Is there anyway to trigger failsafe plugin only after the application got deployed by cargo plugin?
I think you can use the pingURL parameter to provide an url to verify the deployment is completed: see http://cargo.codehaus.org/Maven2+Plugin+Reference+Guide
Using cargo you dont have to deploy the application, there is also support for: http://cargo.codehaus.org/Functional+testing (but that depends on your tests of course)
I have created some unit tests for my node.js application in nodeunit. I want to be able to run the tests through maven / ant, because I intend to run them through Jenkins. Has anyone had any success doing this?
The Maven exec plugin can be used to run Nodeunit and the appropriate tests.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>nodeunit</executable>
<workingDirectory>./</workingDirectory>
<arguments>
<argument>tests/node/ServerTests.js</argument>
</arguments>
</configuration>
</plugin>