| <!-- |
| |
| Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. |
| |
| This program and the accompanying materials are made available under the |
| terms of the Eclipse Public License v. 2.0, which is available at |
| http://www.eclipse.org/legal/epl-2.0. |
| |
| This Source Code may also be made available under the following Secondary |
| Licenses when the conditions for such availability set forth in the |
| Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| version 2 with the GNU Classpath Exception, which is available at |
| https://www.gnu.org/software/classpath/license.html. |
| |
| SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| |
| --> |
| |
| <target name="emma.usage"> |
| <echo><![CDATA[ |
| ************************************************************************************** |
| * Usage : (Take ejb component for example) * |
| * ant all -> ant enable.emma all emma.gen.coverage.report -Demma.enabled=true * |
| **************************************************************************************]]></echo> |
| </target> |
| |
| <property name="emma.port.used.by.server" value="34543" /> <!-- port number must not be 47653 --> |
| <property name="emma.coverage.out.file" value="${basedir}/coverage.ec" /> |
| |
| <property name="glassfish-zip-file" value="${env.GLASSFISH_ZIP_FILE}" /> |
| <property name="glassfish.src.dir" value="${env.GLASSFISH_SRC_DIR}" /> |
| <property name="glassfish.server.dir" value="${env.S1AS_HOME}" /> |
| |
| <property name="emma-filters-file" value="emma-filters.txt" /> |
| |
| <!--the direcotry in which the reports are placed--> |
| <property name="report.dir" value="${basedir}/report" /> |
| <!--the direcotry in which the coverage report is placed--> |
| <property name="coverage.dir" value="${report.dir}/coverage" /> |
| |
| <!-- directory that contains emma.jar and emma_ant.jar: --> |
| <property name="emma.lib.dir" value="${env.APS_HOME}/lib" /> |
| <property name="emma.jar.name" value="emma.jar" /> |
| <property name="emma.ant.jar.name" value="emma_ant.jar" /> |
| |
| <path id="emma.lib"> |
| <!-- use version 2.1.5320 of emma, otherwise, there is a Malformed data exception. --> |
| <pathelement location="${emma.lib.dir}/${emma.jar.name}" /> |
| <pathelement location="${emma.lib.dir}/${emma.ant.jar.name}" /> |
| </path> |
| |
| <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> |
| |
| <target name="emma.prerequsite.check" description="Checking Prerequsite ..."> |
| <condition property="emma.prerequsite.met"> |
| <and> |
| <isset property="emma.enabled" /> |
| <available file="${glassfish-zip-file}" type="file" /> |
| <antversion atleast="1.8"/> |
| </and> |
| </condition> |
| <fail message="Please make sure ant version is 1.8 or higher, emma.enabled property is set, and environment variable GLASSFISH_ZIP_FILE is exported."> |
| <condition> |
| <not> |
| <isset property="emma.prerequsite.met" /> |
| </not> |
| </condition> |
| </fail> |
| <echo>[EMMA] : The prerequisite conditions are satisfied.</echo> |
| </target> |
| |
| <target name="emma.init" depends="emma.prerequsite.check" if="emma.prerequsite.met" description="Initialize EMMA"> |
| <touch file="${emma-filters-file}"/> |
| <mkdir dir="${coverage.dir}"/> |
| <copy file="${emma.lib.dir}/${emma.jar.name}" todir="${glassfish.server.dir}/domains/domain1/lib/ext/" overwrite="true" /> |
| </target> |
| |
| <target name="emma.instrument" depends="emma.init" if="emma.prerequsite.met" description="Instrument Classes With EMMA"> |
| <property name="original.jar.dir" value="${glassfish.server.dir}/modules" /> |
| <echo>[EMMA] : Start to instrument the JAR files under ${original.jar.dir}/.</echo> |
| |
| <!--The temporary directory contains instrumented classes, and the jar files--> |
| <property name="instrumented.dir" value="${basedir}/.instrumented" /> |
| <mkdir dir="${instrumented.dir}" /> |
| <emma enabled="true" verbosity="quiet"> |
| <instr mode="fullcopy" |
| outdir="${instrumented.dir}" |
| merge="true" |
| metadatafile="${basedir}/metadata.em" |
| > |
| <instrpath> |
| <!-- There is a bug in EMMA that it instruments all JARs under ${original.jar.dir} --> |
| <fileset dir="${original.jar.dir}"> |
| <patternset refid="emma.instrument.jar.files" /> |
| </fileset> |
| </instrpath> |
| <filter file="${emma-filters-file}" /> |
| </instr> |
| </emma> |
| |
| <!-- copy instrumented jars to glassfish server's classpath to overwite the old ones--> |
| <copy todir="${original.jar.dir}" overwrite="true"> |
| <fileset dir="${instrumented.dir}/lib"> |
| <!-- we are not using '**/*.jar' to copy file due to the above bug, instead, copy one by one. --> |
| <patternset refid="emma.instrument.jar.files" /> |
| </fileset> |
| </copy> |
| <delete dir="${instrumented.dir}" /> |
| |
| <echo>[EMMA] : The JAR files under ${original.jar.dir}/ have been instrumented.</echo> |
| </target> |
| |
| <target name="emma.glassfish.settings" depends="emma.prerequsite.check" if="emma.prerequsite.met" description="Set port used by EMMA in GF, and let GF load EMMA's JARs"> |
| <replace file="${glassfish.server.dir}/domains/domain1/config/domain.xml"> |
| <replacetoken><![CDATA[ <jvm-options>-XX:NewRatio=2</jvm-options> |
| </java-config>]]></replacetoken> |
| <replacevalue expandProperties="true"><![CDATA[ <jvm-options>-XX:NewRatio=2</jvm-options> |
| <jvm-options>-Demma.rt.control.port=${emma.port.used.by.server}</jvm-options> |
| <jvm-options>-Demma.coverage.out.file=${emma.coverage.out.file}</jvm-options> |
| </java-config>]]></replacevalue> |
| </replace> |
| |
| <copy file="${glassfish.server.dir}/config/osgi.properties" todir="${glassfish.server.dir}/domains/domain1/config/" overwrite="true" /> |
| <property file="${glassfish.server.dir}/domains/domain1/config/osgi.properties" /> |
| <propertyfile |
| file="${glassfish.server.dir}/domains/domain1/config/osgi.properties" |
| comment="Adding EMMA settings"> |
| <entry key="org.osgi.framework.bootdelegation" value="${org.osgi.framework.bootdelegation}, com.vladium, com.vladium.*"/> |
| </propertyfile> |
| </target> |
| |
| <target name="emma.gen.coverage.report" depends="emma.prerequsite.check" if="emma.prerequsite.met" description="Generate Coverage Report With EMMA"> |
| <delete> |
| <fileset dir="${coverage.dir}"> |
| <include name="**/*.html" /> |
| </fileset> |
| </delete> |
| <emma enabled="true"> |
| <report sourcepath="${glassfish.src.dir}" |
| sort="+block,+name,+method,+class" |
| metrics="method:70,block:80,line:80,class:100"> |
| <fileset dir="${basedir}"> |
| <include name="**/*.em" /> |
| <include name="**/*.ec" /> |
| </fileset> |
| <html outfile="${coverage.dir}/coverage.html" |
| columns="name,class,method,block,line" |
| depth="method" |
| /> |
| </report> |
| </emma> |
| <echo>[EMMA] : Code coverage report has been generated.</echo> |
| <antcall target="emma.clean"/> |
| </target> |
| |
| <target name="emma.clean" description="Clean Temporary Files During Generating EMMA Code Coverage Report"> |
| <echo>[EMMA] : Cleaning Files Generated By EMMA.</echo> |
| |
| <replace file="${glassfish.server.dir}/domains/domain1/config/domain.xml"> |
| <replacetoken expandProperties="true"><![CDATA[ <jvm-options>-XX:NewRatio=2</jvm-options> |
| <jvm-options>-Demma.rt.control.port=${emma.port.used.by.server}</jvm-options> |
| <jvm-options>-Demma.coverage.out.file=${emma.coverage.out.file}</jvm-options> |
| </java-config>]]></replacetoken> |
| <replacevalue><![CDATA[ <jvm-options>-XX:NewRatio=2</jvm-options> |
| </java-config>]]></replacevalue> |
| </replace> |
| <delete file="${glassfish.server.dir}/domains/domain1/lib/ext/${emma.jar.name}"/> |
| <delete file="${glassfish.server.dir}/domains/domain1/config/osgi.properties" /> |
| <delete> |
| <fileset dir="${basedir}"> |
| <include name="**/*.ec" /> |
| <include name="**/*.em" /> |
| </fileset> |
| </delete> |
| |
| <!-- create a temporatory direcotry for exploding glassfish.zip --> |
| <property name="tmp.gf.exploded.dir" value="${basedir}/tmp_exploded_gf" /> |
| <mkdir dir="${tmp.gf.exploded.dir}/" /> |
| <!-- restore original EJB jar files --> |
| <unzip src="${glassfish-zip-file}" dest="${tmp.gf.exploded.dir}"/> |
| <copy todir="${glassfish.server.dir}/modules" overwrite="true"> |
| <fileset dir="${tmp.gf.exploded.dir}/glassfish6/glassfish/modules/"> |
| <include name="**/*.jar"/> |
| </fileset> |
| </copy> |
| <delete dir="${tmp.gf.exploded.dir}/" /> |
| </target> |
| |
| <target name="enable.emma" depends="emma.init, emma.instrument, emma.glassfish.settings" if="emma.prerequsite.met" description="Enable EMMA"> |
| <echo>[EMMA] : Enable EMMA to collect code coverage runtime data.</echo> |
| </target> |