You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2015/04/09 13:48:34 UTC

svn commit: r1672300 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/analysis/ lucene/tools/ lucene/tools/junit4/ solr/

Author: rmuir
Date: Thu Apr  9 11:48:34 2015
New Revision: 1672300

URL: http://svn.apache.org/r1672300
Log:
LUCENE-5439: add jacoco coverage

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/build.xml
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_5x/lucene/analysis/build.xml
    lucene/dev/branches/branch_5x/lucene/build.xml   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/common-build.xml   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/tools/   (props changed)
    lucene/dev/branches/branch_5x/lucene/tools/junit4/solr-tests.policy
    lucene/dev/branches/branch_5x/lucene/tools/junit4/tests.policy
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/build.xml   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/common-build.xml   (contents, props changed)

Modified: lucene/dev/branches/branch_5x/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/build.xml (original)
+++ lucene/dev/branches/branch_5x/build.xml Thu Apr  9 11:48:34 2015
@@ -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" />

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Apr  9 11:48:34 2015
@@ -53,6 +53,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

Modified: lucene/dev/branches/branch_5x/lucene/analysis/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/analysis/build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/analysis/build.xml (original)
+++ lucene/dev/branches/branch_5x/lucene/analysis/build.xml Thu Apr  9 11:48:34 2015
@@ -154,4 +154,8 @@
     <forall-analyzers target="check-forbidden-apis"/>
   </target>
 
+  <target name="jacoco">
+    <forall-analyzers target="jacoco"/>
+  </target>
+
 </project>

Modified: lucene/dev/branches/branch_5x/lucene/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/build.xml (original)
+++ lucene/dev/branches/branch_5x/lucene/build.xml Thu Apr  9 11:48:34 2015
@@ -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
    -->

Modified: lucene/dev/branches/branch_5x/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/common-build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/common-build.xml (original)
+++ lucene/dev/branches/branch_5x/lucene/common-build.xml Thu Apr  9 11:48:34 2015
@@ -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" />
@@ -869,6 +872,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. -->
@@ -896,6 +902,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" />
@@ -966,7 +981,7 @@
 
             dynamicAssignmentRatio="${tests.dynamicAssignmentRatio}"
             shuffleOnSlave="true"
-            leaveTemporary="${tests.leaveTemporary}"
+            leaveTemporary="${junit4.leaveTemporary}"
             seed="${tests.seed}"
 
             heartbeat="${tests.heartbeat}"
@@ -982,6 +997,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 -->
@@ -1364,6 +1380,54 @@ ${tests-output}/junit4-*.suites     - pe
   <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}"/>

Modified: lucene/dev/branches/branch_5x/lucene/tools/junit4/solr-tests.policy
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/tools/junit4/solr-tests.policy?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/tools/junit4/solr-tests.policy (original)
+++ lucene/dev/branches/branch_5x/lucene/tools/junit4/solr-tests.policy Thu Apr  9 11:48:34 2015
@@ -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";
   

Modified: lucene/dev/branches/branch_5x/lucene/tools/junit4/tests.policy
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/tools/junit4/tests.policy?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/tools/junit4/tests.policy (original)
+++ lucene/dev/branches/branch_5x/lucene/tools/junit4/tests.policy Thu Apr  9 11:48:34 2015
@@ -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";

Modified: lucene/dev/branches/branch_5x/solr/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/build.xml (original)
+++ lucene/dev/branches/branch_5x/solr/build.xml Thu Apr  9 11:48:34 2015
@@ -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"/>

Modified: lucene/dev/branches/branch_5x/solr/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/common-build.xml?rev=1672300&r1=1672299&r2=1672300&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/common-build.xml (original)
+++ lucene/dev/branches/branch_5x/solr/common-build.xml Thu Apr  9 11:48:34 2015
@@ -32,6 +32,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"/>