Apache Lucene open-source search software
LUCENE-5439: add jacoco coverage
Robert Muir9527a31a2d71
diff --git a/build.xml b/build.xmlindex 5d7935e4409..802d670f448 100644--- a/build.xml+++ b/build.xml@@ -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" />diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 9491ee8d835..c225b31bc13 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -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 Featuresdiff --git a/lucene/analysis/build.xml b/lucene/analysis/build.xmlindex 0abd60ae6b6..0c3084105bb 100644--- a/lucene/analysis/build.xml+++ b/lucene/analysis/build.xml@@ -154,4 +154,8 @@<forall-analyzers target="check-forbidden-apis"/></target>+ <target name="jacoco">+ <forall-analyzers target="jacoco"/>+ </target>+</project>diff --git a/lucene/build.xml b/lucene/build.xmlindex c1e0971fdab..cc7662d7162 100644--- a/lucene/build.xml+++ b/lucene/build.xml@@ -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-->diff --git a/lucene/common-build.xml b/lucene/common-build.xmlindex a11c2c6f7aa..56da964dce0 100644--- a/lucene/common-build.xml+++ b/lucene/common-build.xml@@ -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}"/>diff --git a/lucene/tools/junit4/solr-tests.policy b/lucene/tools/junit4/solr-tests.policyindex c5968999b35..66a6b1c986c 100644--- a/lucene/tools/junit4/solr-tests.policy+++ b/lucene/tools/junit4/solr-tests.policy@@ -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";diff --git a/lucene/tools/junit4/tests.policy b/lucene/tools/junit4/tests.policyindex 1462e1c326d..8594c400654 100644--- a/lucene/tools/junit4/tests.policy+++ b/lucene/tools/junit4/tests.policy@@ -35,6 +35,7 @@ grant {// write only to sandboxpermission 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 itpermission 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";diff --git a/solr/build.xml b/solr/build.xmlindex d077946b3c1..581e5946003 100644--- a/solr/build.xml+++ b/solr/build.xml@@ -15,7 +15,10 @@See the License for the specific language governing permissions andlimitations 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"/>diff --git a/solr/common-build.xml b/solr/common-build.xmlindex 9d0735fc62f..66697adbfd3 100644--- a/solr/common-build.xml+++ b/solr/common-build.xml@@ -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"/>