1 <?xml version="1.0" encoding="UTF-8"?>
   2 <!--
   3  Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   4  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  
   6  This code is free software; you can redistribute it and/or modify it
   7  under the terms of the GNU General Public License version 2 only, as
   8  published by the Free Software Foundation.
   9  
  10  This code is distributed in the hope that it will be useful, but WITHOUT
  11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  version 2 for more details (a copy is included in the LICENSE file that
  14  accompanied this code).
  15  
  16  You should have received a copy of the GNU General Public License version
  17  2 along with this work; if not, write to the Free Software Foundation,
  18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  
  20  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  or visit www.oracle.com if you need additional information or have any
  22  questions.
  23 -->
  24 <project name="code-coverage" default="generate-code-coverage-report" basedir="..">
  25 
  26   <!-- CODE COVERAGE -->
  27   <target name="init-cc-enabled" if="${cc.enabled}">
  28 
  29     <echo message="initialize [${jcov}] java coverage"/>
  30 
  31 
  32     <property name="cc.report.dir" value="${cc.dir}/CC_${jcov}_report"/>
  33     <property name="cc.merged.xml" value="${cc.dir}/CC_${jcov}_result-merged.xml"/>
  34 
  35     <condition property="run.test.cc.jvmargs" value="${cc.dynamic.args}">
  36       <equals arg1="${jcov}" arg2="dynamic" trim="true"/>
  37     </condition>
  38 
  39     <condition property="cc.generate.template" value="true">
  40       <equals arg1="${cc.dynamic.genereate.template}" arg2="true" trim="true"/>
  41     </condition>
  42 
  43     <mkdir dir="${cc.dir}"/>
  44     <mkdir dir="${build.dir}/to_be_instrumented"/>
  45 
  46     <!-- info -->
  47     <echo message="jcov=${jcov}"/>
  48     <echo message="cc.generate.template=${cc.generate.template}"/>
  49     <echo message="cc.instrument=${cc.instrument}"/>
  50     <echo message="run.test.cc.jvmargs=${run.test.cc.jvmargs}"/>
  51     <echo message="cc.report.dir=${cc.report.dir}"/>
  52     <echo message="cc.merged.xml=${cc.merged.xml}"/>
  53   </target>
  54 
  55   <target name="init-cc-disabled" unless="${cc.enabled}">
  56     <property name="run.test.cc.jvmargs" value=""/>
  57   </target>
  58 
  59   <target name="prepare-to-be-instrumented" depends="compile" description="Prepares to_be_instrumented dir">
  60     <copy todir="${build.dir}/to_be_instrumented">
  61       <fileset dir="${build.classes.dir}">
  62         <include name="**/*.class"/>
  63       </fileset>
  64     </copy>
  65   </target>
  66 
  67   <target name="generate-cc-template" depends="prepare-to-be-instrumented" description="Generates code coverage template for dynamic CC" if="cc.generate.template">
  68     <property name="cc.instrumented.path" location="${build.dir}/to_be_instrumented"/>
  69     <java classname="com.sun.tdk.jcov.TmplGen">
  70       <arg value="-verbose"/>
  71       <arg line="-include ${cc.include}"/>
  72       <arg line="-type all"/>
  73       <arg line="-template ${cc.template}"/>
  74       <arg value="${cc.instrumented.path}"/>
  75       <classpath>
  76         <pathelement location="${jcov.jar}"/>
  77       </classpath>
  78     </java>
  79 
  80     <java classname="com.sun.tdk.jcov.RepGen">
  81       <arg value="-verbose"/>
  82       <arg line="-output ${cc.dir}/CC_template_report"/>
  83       <arg value="${cc.template}"/>
  84       <classpath>
  85         <pathelement location="${jcov.jar}"/>
  86       </classpath>
  87     </java>
  88   </target>
  89 
  90   <target name="init-cc" depends="init-cc-disabled, init-cc-enabled">
  91     <property name="run.test.cc.jvmargs" value=""/>
  92   </target>
  93 
  94   <target name="init-cc-cleanup" if="${cc.enabled}">
  95     <delete dir="${cc.dir}" failonerror="false" />
  96     <delete dir="${build.dir}/to_be_instrumented" failonerror="false" />
  97   </target>
  98 
  99   <target name="check-merging-files" depends="init">
 100         <echo message="checking avalibility of ${cc.template}"/>
 101     <condition property="nothing-to-merge" value="true">
 102                 <not>
 103               <available file="${cc.template}"/>
 104                 </not>
 105     </condition>
 106         <echo message="nothing-to-merge = ${nothing-to-merge}"/>
 107   </target>
 108 
 109   <target name="fix-merging-files" depends="check-merging-files" if="${nothing-to-merge}">
 110         <echo message="making pre-merge workaround due to missed template"/>
 111         <move todir="${cc.dir}" includeemptydirs="false">
 112                 <fileset dir="${cc.dir}">
 113                         <include name="*.xml"/>
 114                 </fileset>
 115                 <mapper type="glob" from="*.xml" to="CC_${jcov}_result-merged.xml"/>
 116         </move>
 117   </target>
 118  
 119   <target name="merge-code-coverage" depends="fix-merging-files" unless="${nothing-to-merge}">
 120         <echo message="merging files"/>
 121     <fileset dir="${cc.dir}" id="cc.xmls">
 122       <include name="**/*_${jcov}_*.xml"/>
 123       <include name="**/CC_template.xml"/>
 124     </fileset>
 125 
 126     <pathconvert pathsep=" " property="cc.all.xmls" refid="cc.xmls"/>
 127         <echo message="merging files - ${cc.all.xmls}" />
 128     <java classname="com.sun.tdk.jcov.Merger">
 129       <arg value="-verbose"/>
 130       <arg value="-output"/>
 131       <arg value="${cc.merged.xml}"/>
 132       <arg value="-exclude"/>
 133       <arg value="com\.oracle\.nashorn\.runtime\.ScriptRuntime*"/>
 134       <arg value="-exclude"/>
 135       <arg value="jdk\.nashorn\.javaadapters*"/>
 136       <arg value="-exclude"/>
 137       <arg value="jdk\.nashorn\.internal\.objects\.annotations*"/>
 138       <arg value="-exclude"/>
 139       <arg value="jdk\.nashorn\.internal\.scripts*"/>
 140       <arg value="-exclude"/>
 141       <arg value="jdk\.nashorn\.internal\.lookup\.MethodHandleFactory*"/>
 142       <arg value="-exclude"/>
 143       <arg value="jdk\.nashorn\.internal\.test\.framework*"/>
 144       <arg value="-exclude"/>
 145       <arg value="jdk\.nashorn\.test\.models*"/>
 146       <arg value="-exclude"/>
 147       <arg value="jdk\.nashorn\.internal\.ir\.debug*"/>
 148       <arg value="-exclude"/>
 149       <arg value="jdk\.nashorn\.internal\.runtime\.regexp\.joni\.bench*"/>
 150       <arg value="-exclude"/>
 151       <arg value="jdk\.nashorn\.internal\.runtime\.DebugLogger*"/>
 152       <arg value="-exclude"/>
 153       <arg value="jdk\.nashorn\.internal\.runtime\.Timing*"/>
 154       <arg value="-exclude"/>
 155       <arg value="jdk\.nashorn\.internal\.runtime\.Logging*"/>
 156       <arg value="-exclude"/>
 157       <arg value="jdk\.nashorn\.internal\.runtime\.Debug*"/>
 158       <arg value="-exclude"/>
 159       <arg value="jdk\.nashorn\.internal\.objects\.NativeDebug*"/>
 160       <arg line="${cc.all.xmls}"/>
 161       <classpath>
 162         <pathelement location="${jcov.jar}"/>
 163       </classpath>
 164     </java>
 165 
 166   </target>
 167 
 168   <target name="generate-code-coverage-report" depends="merge-code-coverage">
 169     <java classname="com.sun.tdk.jcov.RepGen">
 170       <arg value="-verbose"/>
 171 <!--      <arg line ="-exclude_list CC.report.exclude"/> -->
 172       <arg line="-output ${cc.report.dir}"/>
 173       <arg value="${cc.merged.xml}"/>
 174       <classpath>
 175         <pathelement location="${jcov.jar}"/>
 176       </classpath>
 177     </java>
 178   </target>
 179 
 180 
 181 </project>