Cobertura Plugin configuration for hudson.
来源:互联网 发布:resolved java 编辑:程序博客网 时间:2024/06/07 08:24
Detail info please check the plugin website is http://wiki.hudson-ci.org/display/HUDSON/Cobertura+Plugin
Configuring the Cobertura Plugin
- Install the cobertura plugin (via Manage Hudson -> Manage Plugins)
- Configure your project's build script to generate cobertura XML reports (See below for examples with Ant and Maven2)
- Enable the "Publish Cobertura Coverage Report" publisher
- Specify the directory where the coverage.xml report is generated.
- (Optional) Configure the coverage metric targets to reflect your goals.
Configuring build tools
Here are the configuration details for common build tools. Please feel free to update this with corrections or additions.
Maven 2
Quick configuration
You can either, enable "cobertura" analysis in your 'pom.xml' files or just tell Hudson to run "cobertura" goal.
If you don't want to change your pom files, just add the goal 'cobertura:cobertura' to your Maven project in Hudson.
Single Project
If you are using a single module configuration, add the following into your pom.xml. This will cause cobertura to be called each time you run "mvn package".
<project ...> ... <build> ... <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.2</version> <configuration> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> ... </plugins> ... </build> ...</project>
Execute cobertura only from hudson using profiles
You can reduce the load of your developer machine by using maven profiles to execute the plugin only if you are running within hudson. Theconfiguration below shows how to enable the plugin based on the information if maven was started by hudson.
<project ...> ... <profiles> <!-- Hudson by default defines a property BUILD_NUMBER which is used to enable the profile. --> <profile> <id>hudson</id> <activation> <property> <name>BUILD_NUMBER</name> </property> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.2</version> <configuration> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> ...</project>
Project hierarchies
If you are using a common parent for all Maven2 modules you can move the plugin configuration to the pluginManagement section of the commonparent...
<project ...> ... <build> ... <pluginManagement> <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.2</version> <configuration> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> ... </plugins> </pluginManagement> ... </build> ...</project>
And add the plugin group and artifact to the children
<project ...> ... <build> ... <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> ... </plugins> ... </build> ...</project>
Execute cobertura only from hudson using profiles
It is highly recommend to reduce the workload of the developers machines by disabling the cobertura plugin and only using it from within hudson. The following excerpt from theparent shows how to do so:
<project ...> ... <profiles> <!-- Hudson by default defines a property BUILD_NUMBER which is used to enable the profile. --> <profile> <id>hudson</id> <activation> <property> <name>BUILD_NUMBER</name> </property> </activation> <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.2</version> <configuration> <formats> <format>xml</format> </formats> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> </profile> </profiles> ...</project>
Now that your parent is only using the plugin management section if it is running from within hudson, you need the childern poms adapted as well:
<project ...> ... <!-- If we are running in hudson use cobertura. --> <profiles> <profile> <id>hudson</id> <activation> <property> <name>BUILD_NUMBER</name> </property> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </build> </profile> </profiles> ...</project>
Ant
You must first tell Ant about the Cobertura Ant tasks using a taskdef statement. The best place to do this is near the top of your build.xml script, before any target statements.
<property name="cobertura.dir" value="C:/javastuff/cobertura" /><path id="cobertura.classpath"> <fileset dir="${cobertura.dir}"> <include name="cobertura.jar" /> <include name="lib/**/*.jar" /> </fileset></path><taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
You'll need to instrument the classes that JUnit will be testing (not the test classes themselves) as such:
<cobertura-instrument todir="${instrumented.dir}"> <ignore regex="org.apache.log4j.*" /> <fileset dir="${classes.dir}"> <include name="**/*.class" /> <exclude name="**/*Test.class" /> </fileset> <fileset dir="${guiclasses.dir}"> <include name="**/*.class" /> <exclude name="**/*Test.class" /> </fileset> <fileset dir="${jars.dir}"> <include name="my-simple-plugin.jar" /> </fileset></cobertura-instrument>
Here's an example call to the JUnit ant task that has been modified to work with Cobertura.
<junit fork="yes" dir="${basedir}" failureProperty="test.failed"><!--Specify the name of the coverage data file to use.The value specified below is the default.--><sysproperty key="net.sourceforge.cobertura.datafile"file="${basedir}/cobertura.ser" /><!--Note the classpath order: instrumented classes are before theoriginal (uninstrumented) classes. This is important.--><classpath location="${instrumented.dir}" /><classpath location="${classes.dir}" /><!--The instrumented classes reference classes used by theCobertura runtime, so Cobertura and its dependenciesmust be on your classpath.--><classpath refid="cobertura.classpath" /><formatter type="xml" /><test name="${testcase}" todir="${reports.xml.dir}" if="testcase" /><batchtest todir="${reports.xml.dir}" unless="testcase"><fileset dir="${src.dir}"><include name="**/*Test.java" /></fileset></batchtest></junit>
Finally, you need a task to generate the xml report, where 'destdir' is where you want the report (coverage.xml) generated.
Your cobertura.ser is generated to your module root.
srcdir is where your *.java files are located. If you use multiple modules in one build process you need to include the module name, if you use the simple srcdir parameter. It is not required to include module name if you use fileset.
<cobertura-report format="xml" destdir="${coveragereport.dir}" srcdir="${src.dir}" />You can use multiple source directories this way:<cobertura-report format="xml" destdir="${coveragereport.dir}" ><fileset dir="${src.dir.java}"><include name="**/*.java" /></fileset><fileset dir="${src.dir.main}"><include name="**/*.java" /></fileset></cobertura-report>
- Cobertura Plugin configuration for hudson.
- Maven Cobertura Plugin集成
- cobertura-maven-plugin用法
- Maven Cobertura Plugin集成
- sonar Cobertura Plugin
- cobertura-maven-plugin插件 maven
- hudson卸载plugin
- hudson(jenkins) plugin
- 测试覆盖率插件cobertura-maven-plugin
- 测试覆盖率插件cobertura-maven-plugin
- Hudson 加载 findbugs插件 Failed to load plugin instance for: analysis-core 报错解决
- Cobertura+Robolectric+Ant for REPORT
- Failure to find maven-plugins:maven-cobertura-plugin:plugin:1.3
- Emma Maven Plugin Configuration
- Vim plugin configuration note
- maven plugin configuration
- [CI]hudson installation and configuration guide
- 使用cobertura-maven-plugin做单元测试覆盖率统计
- 利用JAAS实现简单的页面验证与授权
- 第14周实验报告2
- Windows powershell
- ORACLE11G 字符集更改
- freescale LTIB使用总结1(转)
- Cobertura Plugin configuration for hudson.
- Python_API_ZipFile_extractall_待填充
- 手工加载未注册的 COM 组件
- PyGTK: GTK+ for Python
- 在IIS部署Silverlight应用和WCF RIA Services,出现异常:未能加载文件或程序集“System.ServiceModel.DomainServices.Hosting, Ver
- android解析JSON字符串 (最强最简便方法)
- 自定义异常及堆栈结构
- SAP常用BASIS技巧整理
- tab