语法挺简单的,一看就能了解个大概,就是把Ubuntu中的指令放到一个脚本里,方便后续在Jenkins上部署,自动生成各种报告
1、gedit build.xml
2、
<project name="JaCoCoCoverage" default="generateReport" basedir=".">
<!-- Target to start Java service with JaCoCo agent -->
<target name="javac">
<exec executable="javac">
<arg line="/home/wd/ApplicationTest/Junit/com/wd/test/JUTest.java"/>
</exec>
</target>
<target name="cp" depends="javac">
<exec executable="cp">
<arg line="-rf /home/wd/ApplicationTest/Junit/com/wd/test/JUTest.class /home/wd/ApplicationTest/JunitClass/com/wd/test"/>
</exec>
</target>
<target name="jar" depends="cp">
<exec executable="jar">
<arg line="cfm /home/wd/ApplicationTest/JUTest.jar /home/wd/ApplicationTest/Manifest.txt *.class"/>
</exec>
</target>
<target name="startJavaService" depends="jar">
<exec executable="java">
<arg line="-javaagent:/home/wd/ApplicationTest/jacocoagent.jar=includes=com.wd.test.*,output=tcpserver,port=6300,address=172.22.10.61 -cp /home/wd/ApplicationTest/junit-4.10.jar:/home/wd/ApplicationTest/JunitClass:/home/wd/ApplicationTest/JUTest.jar org.junit.runner.JUnitCore com.wd.test.JUTest"/>
</exec>
</target>
<!-- Target to run tests and generate coverage exec file -->
<target name="runTestsAndGenerateExec" depends="startJavaService">
<exec executable="java">
<arg line="-javaagent:/home/wd/ApplicationTest/jacocoagent.jar=includes=com.wd.test.*,output=file,destfile=/home/wd/ApplicationTest/coverage.exec -cp /home/wd/ApplicationTest/junit-4.10.jar:/home/wd/ApplicationTest/JunitClass:/home/wd/ApplicationTest/JUTest.jar org.junit.runner.JUnitCore com.wd.test.JUTest"/>
</exec>
</target>
<!-- Target to generate JaCoCo report -->
<target name="generateReport" depends="runTestsAndGenerateExec">
<exec executable="java">
<arg line="-jar /home/wd/jacoco-0.8.10/lib/jacococli.jar report /home/wd/ApplicationTest/coverage.exec --classfiles /home/wd/ApplicationTest/JunitClass --sourcefiles /home/wd/ApplicationTest/Junit --html coverage_report --xml report.xml --encoding=utf-8"/>
</exec>
</target>
</project>
3、ant generateReport