LUCENE-5439: add jacoco coverage

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1672298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-04-09 11:47:57 +00:00
parent 6fb5921db3
commit 9527a31a2d
9 changed files with 155 additions and 2 deletions

View File

@ -61,6 +61,13 @@
<subant buildpath="." antfile="extra-targets.xml" target="-run-test" inheritall="false" failonerror="true" />
</target>
<target name="jacoco" description="Generates JaCoCo code coverage reports">
<subant target="jacoco" inheritall="false" failonerror="true">
<fileset dir="lucene" includes="build.xml" />
<fileset dir="solr" includes="build.xml" />
</subant>
</target>
<target name="pitest" description="Run PITest on both Lucene and Solr">
<subant target="pitest" inheritall="false" failonerror="true">
<fileset dir="lucene" includes="build.xml" />

View File

@ -82,6 +82,8 @@ Other
* LUCENE-6413: Test runner should report the number of suites completed/
remaining. (Dawid Weiss)
* LUCENE-5439: Add 'ant jacoco' build target. (Robert Muir)
======================= Lucene 5.1.0 =======================
New Features

View File

@ -154,4 +154,8 @@
<forall-analyzers target="check-forbidden-apis"/>
</target>
<target name="jacoco">
<forall-analyzers target="jacoco"/>
</target>
</project>

View File

@ -18,6 +18,7 @@
-->
<project name="lucene" default="default" basedir="."
xmlns:jacoco="antlib:org.jacoco.ant"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<import file="common-build.xml"/>
@ -464,6 +465,38 @@
<modules-crawl target="pitest" failonerror="false"/>
</target>
<target name="jacoco" description="Generates JaCoCo code coverage reports" depends="-jacoco-install">
<!-- run jacoco for each module -->
<ant dir="${common.dir}/core" target="jacoco" inheritAll="false">
<propertyset refid="uptodate.and.compiled.properties"/>
</ant>
<modules-crawl target="jacoco" failonerror="true"/>
<!-- produce aggregate report -->
<property name="jacoco.output.dir" location="${jacoco.report.dir}/lucene-all"/>
<!-- try to clean output dir to prevent any confusion -->
<delete dir="${jacoco.output.dir}" failonerror="false"/>
<mkdir dir="${jacoco.output.dir}"/>
<jacoco:report>
<executiondata>
<fileset dir="${common.dir}/build" includes="**/jacoco.db"/>
</executiondata>
<structure name="${Name} aggregate JaCoCo coverage report">
<classfiles>
<fileset dir="${common.dir}/build">
<include name="**/classes/java/**/*.class"/>
<exclude name="test-framework/**"/>
<exclude name="tools/**"/>
</fileset>
</classfiles>
<!-- TODO: trying to specify source files could maybe work, but would
double the size of the reports -->
</structure>
<html destdir="${jacoco.output.dir}" footer="Copyright ${year} Apache Software Foundation. All Rights Reserved."/>
</jacoco:report>
</target>
<!--
Committer helpers
-->

View File

@ -20,6 +20,7 @@
<project name="common" xmlns:artifact="antlib:org.apache.maven.artifact.ant"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:junit4="antlib:com.carrotsearch.junit4"
xmlns:jacoco="antlib:org.jacoco.ant"
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
<description>
This file is designed for importing into a main build file, and not intended
@ -267,6 +268,8 @@
<property name="clover.db.dir" location="${common.dir}/build/clover/db"/>
<property name="clover.report.dir" location="${common.dir}/build/clover/reports"/>
<property name="jacoco.report.dir" location="${common.dir}/build/jacoco"/>
<property name="pitest.report.dir" location="${common.dir}/build/pitest/${name}/reports"/>
<property name="pitest.distance" value="0" />
<property name="pitest.threads" value="2" />
@ -851,6 +854,9 @@
<attribute name="tests.monster" default="${tests.monster}"/>
<attribute name="tests.slow" default="${tests.slow}"/>
<attribute name="tests.multiplier" default="${tests.multiplier}"/>
<attribute name="additional.vm.args" default=""/>
<!-- note this enables keeping junit4 files only (not test temp files) -->
<attribute name="runner.leaveTemporary" default="false"/>
<sequential>
<!-- Warn if somebody uses removed properties. -->
@ -878,6 +884,15 @@
<property name="tests.dynamicAssignmentRatio" value="0.50" /> <!-- 50% of suites -->
<property name="tests.haltonfailure" value="true" />
<property name="tests.leaveTemporary" value="false" />
<!--
keep junit4 runner files or not (independent of keeping test output files)
-->
<condition property="junit4.leaveTemporary">
<or>
<istrue value="${tests.leaveTemporary}"/>
<istrue value="@{runner.leaveTemporary}"/>
</or>
</condition>
<property name="tests.iters" value="" />
<property name="tests.dups" value="1" />
<property name="tests.useSecurityManager" value="true" />
@ -948,7 +963,7 @@
dynamicAssignmentRatio="${tests.dynamicAssignmentRatio}"
shuffleOnSlave="true"
leaveTemporary="${tests.leaveTemporary}"
leaveTemporary="${junit4.leaveTemporary}"
seed="${tests.seed}"
heartbeat="${tests.heartbeat}"
@ -964,6 +979,7 @@
<jvmarg line="${args}"/>
<jvmarg line="${tests.heapdump.args}"/>
<jvmarg line="${tests.clover.args}"/>
<jvmarg line="@{additional.vm.args}"/>
<jvmarg line="${tests.asserts.args}"/>
<!-- set the number of times tests should run -->
@ -1345,6 +1361,54 @@ ${tests-output}/junit4-*.suites - per-JVM executed suites
<target name="test" depends="clover,compile-test,install-junit4-taskdef,validate,-init-totals,-test,-check-totals" description="Runs unit tests"/>
<target name="beast" depends="clover,compile-test,install-junit4-taskdef,validate,-init-totals,-beast,-check-totals" description="Runs unit tests in a loop (-Dbeast.iters=n)"/>
<target name="-jacoco-install">
<!-- download jacoco from ivy if needed -->
<ivy:cachepath organisation="org.jacoco" module="org.jacoco.ant" type="jar" inline="true" revision="0.7.4.201502262128"
log="download-only" pathid="jacoco.classpath" />
<!-- install jacoco ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="jacoco.classpath"/>
</taskdef>
</target>
<target name="-jacoco-test" depends="clover,compile-test,install-junit4-taskdef,validate,-init-totals">
<!-- hack: ant task computes absolute path, but we need a relative path, so its per-testrunner -->
<jacoco:agent property="agentvmparam.raw"/>
<property name="agentvmparam" value="${agentvmparam.raw}destfile=jacoco.db,append=false"/>
<!-- create output dir if needed -->
<mkdir dir="${junit.output.dir}"/>
<!-- run tests, with agent vm args, and keep runner files around -->
<test-macro threadNum="${tests.jvms.override}" additional.vm.args="${agentvmparam}" runner.leaveTemporary="true"/>
</target>
<target name="-jacoco-report" depends="-check-totals">
<property name="jacoco.output.dir" location="${jacoco.report.dir}/${name}"/>
<!-- try to clean output dir to prevent any confusion -->
<delete dir="${jacoco.output.dir}" failonerror="false"/>
<mkdir dir="${jacoco.output.dir}"/>
<!-- print jacoco reports -->
<jacoco:report>
<executiondata>
<fileset dir="${junit.output.dir}" includes="**/jacoco.db"/>
</executiondata>
<structure name="${final.name} JaCoCo coverage report">
<classfiles>
<fileset dir="${build.dir}/classes/java"/>
</classfiles>
<sourcefiles>
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${jacoco.output.dir}" footer="Copyright ${year} Apache Software Foundation. All Rights Reserved."/>
</jacoco:report>
</target>
<target name="jacoco" depends="-jacoco-install,-jacoco-test,-jacoco-report" description="Generates JaCoCo coverage report"/>
<!-- Run the actual tests (must be wrapped with -init-totals, -check-totals) -->
<target name="-test">
<mkdir dir="${junit.output.dir}"/>

View File

@ -29,6 +29,7 @@ grant {
permission java.io.FilePermission "${junit4.childvm.cwd}", "read,execute";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp", "read,execute,write,delete";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp${/}-", "read,execute,write,delete";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}jacoco.db", "write";
permission java.io.FilePermission "${junit4.tempDir}${/}*", "read,execute,write,delete";
permission java.io.FilePermission "${clover.db.dir}${/}-", "read,execute,write,delete";

View File

@ -35,6 +35,7 @@ grant {
// write only to sandbox
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp", "read,write,delete";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}temp${/}-", "read,write,delete";
permission java.io.FilePermission "${junit4.childvm.cwd}${/}jacoco.db", "write";
permission java.io.FilePermission "${junit4.tempDir}${/}*", "read,write,delete";
permission java.io.FilePermission "${clover.db.dir}${/}-", "read,write,delete";
@ -72,6 +73,8 @@ grant {
permission java.lang.RuntimePermission "getClassLoader";
// needed to test unmap hack on platforms that support it
permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
// needed by jacoco to dump coverage
permission java.lang.RuntimePermission "shutdownHooks";
// read access to all system properties:
permission java.util.PropertyPermission "*", "read";

View File

@ -15,7 +15,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="solr" default="usage" xmlns:ivy="antlib:org.apache.ivy.ant">
<project name="solr" default="usage"
xmlns:jacoco="antlib:org.jacoco.ant"
xmlns:ivy="antlib:org.apache.ivy.ant">
<description>Solr</description>
<target name="usage" description="Prints out instructions">
@ -130,6 +133,41 @@
<target name="test" description="Validate, then run core, solrj, and contrib unit tests."
depends="-init-totals, test-core, test-contrib, -check-totals"/>
<target name="jacoco" description="Generates JaCoCo code coverage reports." depends="-jacoco-install">
<!-- run jacoco for each module -->
<ant dir="${common-solr.dir}/core" target="jacoco" inheritAll="false">
<propertyset refid="uptodate.and.compiled.properties"/>
</ant>
<ant dir="solrj" target="jacoco" inheritAll="false">
<propertyset refid="uptodate.and.compiled.properties"/>
</ant>
<contrib-crawl target="jacoco" failonerror="false"/>
<!-- produce aggregate report -->
<property name="jacoco.output.dir" location="${jacoco.report.dir}/solr-all"/>
<!-- try to clean output dir to prevent any confusion -->
<delete dir="${jacoco.output.dir}" failonerror="false"/>
<mkdir dir="${jacoco.output.dir}"/>
<jacoco:report>
<executiondata>
<fileset dir="${common-solr.dir}/build" includes="**/jacoco.db"/>
</executiondata>
<structure name="${Name} aggregate JaCoCo coverage report">
<classfiles>
<fileset dir="${common-solr.dir}/build">
<include name="**/classes/java/**/*.class"/>
<exclude name="solr-test-framework/**"/>
</fileset>
</classfiles>
<!-- TODO: trying to specify source files could maybe work, but would
double the size of the reports -->
</structure>
<html destdir="${jacoco.output.dir}" footer="Copyright ${year} Apache Software Foundation. All Rights Reserved."/>
</jacoco:report>
</target>
<!-- "-clover.load" is *not* a useless dependency. do not remove -->
<target name="test-core" description="Runs the core and solrj unit tests."
depends="-clover.load, test-solr-core, test-solrj"/>

View File

@ -33,6 +33,7 @@
<property name="dest" location="${common-solr.dir}/build" />
<property name="build.dir" location="${dest}/${ant.project.name}"/>
<property name="jacoco.report.dir" location="${dest}/jacoco"/>
<property name="dist" location="${common-solr.dir}/dist"/>
<property name="package.dir" location="${common-solr.dir}/package"/>
<property name="maven.dist.dir" location="${package.dir}/maven"/>