build.xml revision 1527:3fc9a15406c9
192108Sphk<?xml version="1.0" encoding="UTF-8"?>
292108Sphk
392108Sphk<!--
492108Sphk Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
592108Sphk DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
692108Sphk
792108Sphk This code is free software; you can redistribute it and/or modify it
892108Sphk under the terms of the GNU General Public License version 2 only, as
992108Sphk published by the Free Software Foundation.
1092108Sphk
1192108Sphk This code is distributed in the hope that it will be useful, but WITHOUT
1292108Sphk ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1392108Sphk FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1492108Sphk version 2 for more details (a copy is included in the LICENSE file that
1592108Sphk accompanied this code).
1692108Sphk
1792108Sphk You should have received a copy of the GNU General Public License version
1892108Sphk 2 along with this work; if not, write to the Free Software Foundation,
1992108Sphk Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2092108Sphk
2192108Sphk Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2292108Sphk or visit www.oracle.com if you need additional information or have any
2392108Sphk questions.
2492108Sphk-->
2592108Sphk
2692108Sphk<project name="nashorn" default="test" basedir="..">
2792108Sphk  <import file="build-nasgen.xml"/>
2892108Sphk  <import file="code_coverage.xml"/>
2992108Sphk
3092108Sphk  <target name="init-conditions">
3192108Sphk    <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
3292108Sphk    <property file="${user.home}/.nashorn.project.local.properties"/>
3392108Sphk
3492108Sphk    <loadproperties srcFile="make/project.properties"/>
3592108Sphk    <path id="dist.path">
3692108Sphk         <pathelement location="${dist.dir}"/>
3792108Sphk    </path>
3895276Sphk    <path id="nashorn.boot.prefix.path">
3995276Sphk      <pathelement location="${dist.jar}"/>
4095276Sphk    </path>
4192108Sphk    <property name="boot.class.path" value="-Xbootclasspath/p:${toString:nashorn.boot.prefix.path}"/>
4292108Sphk    <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
4392108Sphk      <available file="/usr/local/bin/svn"/>
4492108Sphk    </condition>
4595323Sphk    <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
46219950Smav      <available file="/usr/local/bin/hg"/>
4795323Sphk    </condition>
48115473Sphk    <condition property="git.executable" value="/usr/local/bin/git" else="git">
4992108Sphk      <available file="/usr/local/bin/git"/>
5093248Sphk    </condition>
5192108Sphk    <!-- check if testng.jar is avaiable -->
5292108Sphk    <available property="testng.available" file="${file.reference.testng.jar}"/>
5392108Sphk    <!-- check if Jemmy ang testng.jar are avaiable -->
54110541Sphk    <condition property="jemmy.jfx.testng.available" value="true">
5592108Sphk      <and>
5692108Sphk        <available file="${file.reference.jemmyfx.jar}"/>
5792108Sphk        <available file="${file.reference.jemmycore.jar}"/>
58112709Sphk        <available file="${file.reference.jemmyawtinput.jar}"/>
59106518Sphk        <available file="${file.reference.jfxrt.jar}"/>
6092108Sphk        <isset property="testng.available"/>
61106518Sphk      </and>
62115624Sphk    </condition>
63112709Sphk
64112709Sphk    <!-- enable/disable make code coverage -->
65113876Sphk    <condition property="cc.enabled">
66115473Sphk        <istrue value="${make.code.coverage}" />
67115473Sphk    </condition>
68119660Sphk
69138732Sphk    <!-- exclude tests in exclude lists -->
7092108Sphk    <condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt">
7192108Sphk      <istrue value="${make.code.coverage}" />
7292108Sphk    </condition>
7392108Sphk
7492108Sphk    <condition property="jfr.options" value="${run.test.jvmargs.jfr}" else="">
7593250Sphk      <istrue value="${jfr}"/>
7692108Sphk    </condition>
7792108Sphk  </target>
7892108Sphk
79107953Sphk  <!-- check minimum ant version required to be 1.8.4 -->
8092108Sphk  <target name="check-ant-version">
8192108Sphk    <property name="ant.version.required" value="1.8.4"/>
8292108Sphk    <antversion property="ant.current.version" />
8393248Sphk    <fail message="The current ant version, ${ant.current.version}, is too old. Please use 1.8.4 or above.">
8493248Sphk        <condition>
8593248Sphk            <not>
8693248Sphk                <antversion atleast="${ant.version.required}"/>
87106518Sphk            </not>
8892108Sphk        </condition>
8993248Sphk    </fail>
90107953Sphk  </target>
91133312Sphk
9292108Sphk  <target name="check-java-version">
93106518Sphk    <!-- look for a Class that is available only in jdk1.8 or above -->
94115624Sphk    <!-- core/exposed API class is better than an implementation class -->
95115473Sphk    <available property="jdk1.8+" classname="java.util.stream.Stream"/>
96115473Sphk
97112709Sphk    <!-- need jdk1.8 or above -->
9893776Sphk    <fail message="Unsupported Java version: ${ant.java.version}. Please use Java version 1.8 or greater." unless="jdk1.8+">
99149757Sphk    </fail>
100133312Sphk  </target>
101133312Sphk
102133312Sphk  <target name="init" depends="check-ant-version, check-java-version, init-conditions, init-cc">
103133312Sphk    <!-- extends jvm args -->
104133312Sphk    <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
105133312Sphk    <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
106133312Sphk
107133312Sphk    <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
108115468Sphk    <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
109115468Sphk    <echo message="run.test.xms=${run.test.xms}"/>
11093248Sphk    <echo message="run.test.xmx=${run.test.xmx}"/>
11192108Sphk
11292108Sphk  </target>
11392108Sphk
114133312Sphk  <target name="prepare" depends="init">
115138732Sphk    <mkdir dir="${build.dir}"/>
116138732Sphk    <mkdir dir="${build.classes.dir}"/>
117133312Sphk    <mkdir dir="${build.classes.dir}/META-INF/services"/>
11892108Sphk    <mkdir dir="${build.test.classes.dir}"/>
11993248Sphk    <mkdir dir="${dist.dir}"/>
12092108Sphk    <mkdir dir="${dist.javadoc.dir}"/>
12192108Sphk  </target>
12292108Sphk
12393248Sphk  <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
12492108Sphk    <delete includeemptydirs="true">
12592108Sphk      <fileset dir="${build.dir}" erroronmissingdir="false"/>
12692108Sphk    </delete>
12792108Sphk    <delete dir="${dist.dir}"/>
12892108Sphk  </target>
12992108Sphk
13092108Sphk  <target name="compile" depends="prepare" description="Compiles nashorn">
13192108Sphk    <javac srcdir="${src.dir}"
13293776Sphk           destdir="${build.classes.dir}"
13393776Sphk           classpath="${javac.classpath}"
134119660Sphk           source="${javac.source}"
13592108Sphk           target="${javac.target}"
13692108Sphk           debug="${javac.debug}"
13792108Sphk           encoding="${javac.encoding}"
138195195Strasz           includeantruntime="false" fork="true">
13992108Sphk      <compilerarg value="-Xlint:all"/>
14092108Sphk      <compilerarg value="-XDignore.symbol.file"/>
14192108Sphk      <compilerarg value="-Xdiags:verbose"/>
14292108Sphk      <compilerarg value="-parameters"/>
14392108Sphk    </javac>
14492108Sphk    <copy todir="${build.classes.dir}/META-INF/services">
14592108Sphk       <fileset dir="${meta.inf.dir}/services/"/>
14692108Sphk    </copy>
14792108Sphk     <copy todir="${build.classes.dir}/jdk/nashorn/api/scripting/resources">
14892108Sphk       <fileset dir="${src.dir}/jdk/nashorn/api/scripting/resources/"/>
14992108Sphk    </copy>
15092108Sphk    <copy todir="${build.classes.dir}/jdk/nashorn/internal/runtime/resources">
15192108Sphk       <fileset dir="${src.dir}/jdk/nashorn/internal/runtime/resources/"/>
15292108Sphk    </copy>
15392108Sphk    <copy todir="${build.classes.dir}/jdk/nashorn/tools/resources">
15492108Sphk       <fileset dir="${src.dir}/jdk/nashorn/tools/resources/"/>
15592108Sphk    </copy>
15692108Sphk    <copy file="${src.dir}/jdk/internal/dynalink/support/messages.properties" todir="${build.classes.dir}/jdk/internal/dynalink/support"/>
15792108Sphk    <copy file="${src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${build.classes.dir}/jdk/nashorn/internal/codegen"/>
15892108Sphk
15992108Sphk    <echo message="version_string=${nashorn.fullversion}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
16092108Sphk    <echo file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
16192108Sphk    <echo message="version_short=${nashorn.version}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
16292108Sphk  </target>
16392108Sphk
16492108Sphk  <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
165112370Sphk    <jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
166112026Sphk      <fileset dir="${build.classes.dir}"/>
167125743Sphk      <manifest>
168125743Sphk        <attribute name="Archiver-Version" value="n/a"/>
169125743Sphk        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
170125743Sphk        <attribute name="Built-By" value="n/a"/>
17192108Sphk        <attribute name="Created-By" value="Ant jar task"/>
17292108Sphk        <section name="jdk/nashorn/">
17392108Sphk          <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
17492108Sphk          <attribute name="Implementation-Version" value="${nashorn.version}"/>
17592108Sphk        </section>
17692108Sphk      </manifest>
17792108Sphk    </jar>
17892108Sphk  </target>
17992108Sphk
18092108Sphk  <target name="use-promoted-nashorn" depends="init">
18192108Sphk    <delete file="${dist.dir}/nashorn.jar"/>
18292108Sphk    <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
18392108Sphk    <property name="compile.suppress.jar" value="defined"/>
18493778Sphk  </target>
185105542Sphk
186110710Sphk  <target name="build-fxshell" depends="jar">
187110710Sphk    <description>Builds the javafx shell.</description>
188112370Sphk    <mkdir dir="${fxshell.classes.dir}"/>
189112026Sphk    <javac srcdir="${fxshell.dir}"
190110690Sphk           destdir="${fxshell.classes.dir}"
191110690Sphk           classpath="${dist.jar}${path.separator}${javac.classpath}"
192120851Sphk           debug="${javac.debug}"
193123233Sphk           encoding="${javac.encoding}"
194125743Sphk           includeantruntime="false">
195125743Sphk    </javac>
196125743Sphk    <jar jarfile="${fxshell.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
197125743Sphk      <fileset dir="${fxshell.classes.dir}"/>
19892108Sphk      <manifest>
19992108Sphk        <attribute name="Archiver-Version" value="n/a"/>
200193981Sluigi        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
201193981Sluigi        <attribute name="Built-By" value="n/a"/>
202193981Sluigi        <attribute name="Created-By" value="Ant jar task"/>
203193981Sluigi        <section name="jdk/nashorn/">
204193981Sluigi          <attribute name="Implementation-Title" value="Oracle Nashorn FXShell"/>
205193981Sluigi          <attribute name="Implementation-Version" value="${nashorn.version}"/>
206193981Sluigi        </section>
207193981Sluigi      </manifest>
208193981Sluigi    </jar>
209193981Sluigi  </target>
210193981Sluigi
211219970Smav  <target name="javadoc" depends="jar">
212219970Smav    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${src.dir}/overview.html"
213219970Smav        extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
214219970Smav        additionalparam="-quiet" failonerror="true">
215219970Smav      <classpath>
216219970Smav        <pathelement location="${build.classes.dir}"/>
217105947Sphk      </classpath>
218130585Sphk      <fileset dir="${src.dir}" includes="**/*.java"/>
219115960Sphk      <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/>
220130585Sphk      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
221105947Sphk      <!-- The following tags are used only in ASM sources - just ignore these -->
22292108Sphk      <tag name="label" description="label tag in ASM sources" enabled="false"/>
223107953Sphk      <tag name="linked" description="linked tag in ASM sources" enabled="false"/>
22492108Sphk      <tag name="associates" description="associates tag in ASM sources" enabled="false"/>
22592108Sphk    </javadoc>
22692108Sphk  </target>
22792108Sphk
22893090Sphk  <!-- generate javadoc only for nashorn extension api classes -->
22992108Sphk  <target name="javadocapi" depends="jar">
230113937Sphk    <javadoc destdir="${dist.javadoc.dir}" use="yes" extdirs="${nashorn.ext.path}"
231112989Sphk        windowtitle="${nashorn.product.name}" additionalparam="-quiet" failonerror="true">
232113937Sphk      <classpath>
233113940Sphk        <pathelement location="${build.classes.dir}"/>
234112989Sphk      </classpath>
23592108Sphk      <fileset dir="${src.dir}" includes="jdk/nashorn/api/**/*.java"/>
236137489Spjd      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
23792108Sphk    </javadoc>
23892108Sphk  </target>
239125755Sphk
24092108Sphk
241221101Smav  <!-- generate shell.html for shell tool documentation -->
24292108Sphk  <target name="shelldoc" depends="jar">
24392108Sphk    <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
24492108Sphk      <jvmarg line="${boot.class.path}"/>
24598066Sphk      <arg value="-scripting"/>
24692108Sphk      <arg value="docs/genshelldoc.js"/>
247115850Sphk    </java>
24894284Sphk  </target>
24994284Sphk
250187973Smarcel  <!-- generate all docs -->
251187973Smarcel  <target name="docs" depends="javadoc, shelldoc"/>
252107953Sphk
253107953Sphk  <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
254187973Smarcel  <target name="dist" depends="jar">
25592108Sphk      <zip destfile="${build.zip}" basedir=".."
256107953Sphk          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
257107953Sphk      <tar destfile="${build.gzip}" basedir=".." compression="gzip"
258177509Smarcel          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
25992108Sphk  </target>
26092108Sphk
26192108Sphk  <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
26292108Sphk    <!-- testng task -->
263114495Sphk    <taskdef name="testng" classname="org.testng.TestNGAntTask"
264137032Sphk        classpath="${file.reference.testng.jar}"/>
265157619Smarcel
26692108Sphk    <javac srcdir="${test.src.dir}"
267162326Spjd           destdir="${build.test.classes.dir}"
268162326Spjd           classpath="${javac.test.classpath}"
269162326Spjd           source="${javac.source}"
270126798Sphk           target="${javac.target}"
271126798Sphk           debug="${javac.debug}"
272126798Sphk           encoding="${javac.encoding}"
273126798Sphk           includeantruntime="false" fork="true">
274126798Sphk        <compilerarg value="${boot.class.path}"/>
275126798Sphk        <compilerarg value="-Xlint:unchecked"/>
276126798Sphk        <compilerarg value="-Xlint:deprecation"/>
277126798Sphk        <compilerarg value="-Xdiags:verbose"/>
278126798Sphk    </javac>
279126798Sphk
280126798Sphk    <copy todir="${build.test.classes.dir}/META-INF/services">
281126798Sphk       <fileset dir="${test.src.dir}/META-INF/services/"/>
282126798Sphk    </copy>
283126798Sphk
284126798Sphk    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/test/resources">
285126798Sphk       <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/test/resources"/>
286115473Sphk    </copy>
287115473Sphk
28892108Sphk    <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/test/resources">
28992108Sphk       <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/test/resources"/>
290159304Spjd    </copy>
29192108Sphk
292104195Sphk    <!-- tests that check nashorn internals and internal API -->
29394283Sphk    <jar jarfile="${nashorn.internal.tests.jar}">
294163832Spjd      <fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
295193981Sluigi    </jar>
296193981Sluigi
29792108Sphk    <!-- tests that check nashorn script engine (jsr-223) API -->
29892108Sphk    <jar jarfile="${nashorn.api.tests.jar}">
299134379Sphk      <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
30092108Sphk      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
301104194Sphk      <fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
302169283Spjd    </jar>
303125713Spjd
30492108Sphk  </target>
30592108Sphk
30692108Sphk  <target name="generate-policy-file" depends="prepare">
30792108Sphk    <echo file="${build.dir}/nashorn.policy">
30892108Sphk
309160301Spjdgrant codeBase "file:/${toString:dist.path}/nashorn.jar" {
310160301Spjd    permission java.security.AllPermission;
31195038Sphk};
31295038Sphk
31395038Sphkgrant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
314219950Smav    permission java.security.AllPermission;
31595038Sphk};
31695038Sphk
31792108Sphkgrant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" {
31892108Sphk    permission java.util.PropertyPermission "parserapitest.*", "read";
31992108Sphk    permission java.util.PropertyPermission "test.*", "read";
32092108Sphk    permission java.util.PropertyPermission "test262.*", "read";
32192108Sphk    permission java.io.FilePermission "${basedir}/test/-","read";
32292108Sphk    permission java.io.FilePermission "$${user.dir}", "read";
32392108Sphk    permission java.util.PropertyPermission "user.dir", "read";
32492108Sphk};
32592108Sphk
32692108Sphkgrant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
32792108Sphk    permission java.security.AllPermission;
32892108Sphk};
32992108Sphk//// in case of absolute path:
33092108Sphkgrant codeBase "file:/${nashorn.internal.tests.jar}" {
331126798Sphk    permission java.security.AllPermission;
332126798Sphk};
333160301Spjd
334160301Spjdgrant codeBase "file:/${file.reference.testng.jar}" {
335160301Spjd    permission java.security.AllPermission;
336160301Spjd};
337160301Spjd
338126798Sphkgrant codeBase "file:/${basedir}/test/script/trusted/*" {
33992108Sphk    permission java.security.AllPermission;
34092108Sphk};
34192108Sphk
34296987Sphkgrant codeBase "file:/${basedir}/test/script/maptests/*" {
34396987Sphk    permission java.io.FilePermission "${basedir}/test/script/maptests/*","read";
34496987Sphk    permission java.lang.RuntimePermission "nashorn.debugMode";
34596987Sphk};
34696987Sphk
34796987Sphkgrant codeBase "file:/${basedir}/test/script/basic/*" {
348139139Spjd    permission java.io.FilePermission "${basedir}/test/script/-", "read";
349139139Spjd    permission java.io.FilePermission "$${user.dir}", "read";
35096987Sphk    permission java.util.PropertyPermission "user.dir", "read";
35196987Sphk    permission java.util.PropertyPermission "nashorn.test.*", "read";
35296987Sphk};
35396987Sphk
35496987Sphkgrant codeBase "file:/${basedir}/test/script/basic/parser/*" {
35596987Sphk    permission java.io.FilePermission "${basedir}/test/script/-", "read";
35696987Sphk    permission java.io.FilePermission "$${user.dir}", "read";
35796987Sphk    permission java.util.PropertyPermission "user.dir", "read";
35896987Sphk    permission java.util.PropertyPermission "nashorn.test.*", "read";
35996987Sphk};
360125656Spjd
361125656Spjdgrant codeBase "file:/${basedir}/test/script/basic/es6/*" {
362125656Spjd    permission java.io.FilePermission "${basedir}/test/script/-", "read";
363125656Spjd    permission java.io.FilePermission "$${user.dir}", "read";
364125656Spjd    permission java.util.PropertyPermission "user.dir", "read";
365207671Sjh    permission java.util.PropertyPermission "nashorn.test.*", "read";
366207671Sjh};
367207671Sjh
368115473Sphkgrant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
369115473Sphk    permission java.util.PropertyPermission "java.security.policy", "read";
370115473Sphk};
371115473Sphk
372115473Sphkgrant codeBase "file:/${basedir}/test/script/basic/classloader.js" {
373105061Sphk    permission java.lang.RuntimePermission "nashorn.JavaReflection";
37495310Sphk};
37592108Sphk
376112709Sphkgrant codeBase "file:/${basedir}/test/script/markdown.js" {
377157581Smarcel    permission java.io.FilePermission "${basedir}/test/script/external/showdown/-", "read";
378157581Smarcel};
379112709Sphk
380115624Sphk    </echo>
381113892Sphk
382162352Spjd    <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace>    <!--hack for Windows - to make URLs with normal path separators -->
383115624Sphk    <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace>   <!--hack for Unix - to avoid leading // in URLs -->
384115624Sphk
385115624Sphk  </target>
386112709Sphk
38795276Sphk  <target name="check-external-tests">
388      <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
389      <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
390      <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
391      <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
392      <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
393      <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
394      <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
395      <available file="${test.external.dir}/showdown" property="test-sys-prop.external.markdown"/>
396  </target>
397
398  <target name="check-testng" unless="testng.available">
399    <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under ${test.lib} directory."/>
400  </target>
401
402  <!-- only to be invoked as dependency of "test" target -->
403  <target name="-test-classes-all" depends="jar" unless="test.class">
404      <fileset id="test.classes" dir="${build.test.classes.dir}">
405          <include name="**/api/javaaccess/test/*Test.class"/>
406          <include name="**/api/scripting/test/*Test.class"/>
407          <include name="**/api/tree/test/*Test.class"/>
408          <include name="**/codegen/test/*Test.class"/>
409          <include name="**/parser/test/*Test.class"/>
410          <include name="**/runtime/test/*Test.class"/>
411          <include name="**/runtime/regexp/test/*Test.class"/>
412          <include name="**/runtime/regexp/joni/test/*Test.class"/>
413          <include name="**/framework/*Test.class"/>
414     </fileset>
415  </target>
416
417  <!-- only to be invoked as dependency of "test" target -->
418  <target name="-test-classes-single" depends="jar" if="test.class">
419     <fileset id="test.classes" dir="${build.test.classes.dir}">
420         <include name="${test.class}*"/>
421     </fileset>
422  </target>
423
424  <!-- only to be invoked as dependency of "test" target -->
425  <target name="-test-nosecurity" unless="test.class">
426    <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
427      <include name="**/framework/ScriptTest.class"/>
428    </fileset>
429    <testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
430       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
431      <jvmarg line="${boot.class.path}"/>
432      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
433      <sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
434      <propertyset>
435        <propertyref prefix="nashorn."/>
436      </propertyset>
437      <propertyset>
438        <propertyref prefix="test-sys-prop-no-security."/>
439        <mapper from="test-sys-prop-no-security.*" to="*" type="glob"/>
440      </propertyset>
441      <sysproperty key="optimistic.override" value="${optimistic}"/>
442      <classpath>
443          <pathelement path="${run.test.classpath}"/>
444      </classpath>
445    </testng>
446  </target>
447
448  <!-- only to be invoked as dependency of "test" target -->
449  <target name="-test-security">
450    <delete dir="${build.dir}/nashorn_code_cache"/>
451    <property name="debug.test.jvmargs" value=""/>
452    <testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
453            verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
454      <jvmarg line="${boot.class.path}"/>
455      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
456      <jvmarg line="${debug.test.jvmargs}"/>
457      <propertyset>
458        <propertyref prefix="nashorn."/>
459      </propertyset>
460      <propertyset>
461        <propertyref prefix="test-sys-prop."/>
462        <mapper from="test-sys-prop.*" to="*" type="glob"/>
463      </propertyset>
464      <sysproperty key="optimistic.override" value="${optimistic}"/>
465      <sysproperty key="test.js.excludes.file" value="${exclude.list}"/>
466      <classpath>
467          <pathelement path="${run.test.classpath}"/>
468      </classpath>
469    </testng>
470  </target>
471
472  <target name="test" depends="get-testng, javadoc, test-pessimistic, test-optimistic"/>
473
474  <target name="test-optimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
475    <echo message="Running test suite in OPTIMISTIC mode..."/>
476    <antcall target="-test-nosecurity" inheritRefs="true">
477      <param name="optimistic" value="true"/>
478      <param name="testResultsSubDir" value="optimistic"/>
479    </antcall>
480    <antcall target="-test-security" inheritRefs="true">
481      <param name="optimistic" value="true"/>
482      <param name="testResultsSubDir" value="optimistic"/>
483    </antcall>
484  </target>
485
486  <target name="test-pessimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
487    <echo message="Running test suite in PESSIMISTIC mode..."/>
488    <antcall target="-test-nosecurity" inheritRefs="true">
489      <param name="optimistic" value="false"/>
490      <param name="testResultsSubDir" value="pessimistic"/>
491    </antcall>
492    <antcall target="-test-security" inheritRefs="true">
493      <param name="optimistic" value="false"/>
494      <param name="testResultsSubDir" value="pessimistic"/>
495    </antcall>
496  </target>
497
498  <target name="check-jemmy.jfx.testng" unless="jemmy.jfx.testng.available">
499    <echo message="WARNING: Jemmy or JavaFX or TestNG not available, will not run tests. Please copy testng.jar, JemmyCore.jar, JemmyFX.jar, JemmyAWTInput.jar under test${file.separator}lib directory. And make sure you have jfxrt.jar in ${java.home}${file.separator}lib${file.separator}ext dir."/>
500  </target>
501
502  <target name="testjfx" depends="jar, get-testng, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available">
503    <fileset id="test.classes" dir="${build.test.classes.dir}">
504       <include name="**/framework/*Test.class"/>
505    </fileset>
506
507    <copy file="${file.reference.jfxrt.jar}" todir="dist"/>
508
509    <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
510        <not>
511            <os family="mac"/>
512        </not>
513    </condition>
514
515    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
516       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
517      <jvmarg line="${boot.class.path}"/>
518      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
519      <propertyset>
520        <propertyref prefix="testjfx-test-sys-prop."/>
521        <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
522      </propertyset>
523      <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
524      <classpath>
525          <pathelement path="${testjfx.run.test.classpath}"/>
526      </classpath>
527    </testng>
528  </target>
529
530  <target name="testmarkdown" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
531    <fileset id="test.classes" dir="${build.test.classes.dir}">
532       <include name="**/framework/*Test.class"/>
533    </fileset>
534
535    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
536       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
537      <jvmarg line="${boot.class.path}"/>
538      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
539      <propertyset>
540        <propertyref prefix="testmarkdown-test-sys-prop."/>
541        <mapper from="testmarkdown-test-sys-prop.*" to="*" type="glob"/>
542      </propertyset>
543      <classpath>
544          <pathelement path="${run.test.classpath}"/>
545      </classpath>
546    </testng>
547  </target>
548
549  <target name="test262" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
550    <fileset id="test.classes" dir="${build.test.classes.dir}">
551       <include name="**/framework/*Test.class"/>
552    </fileset>
553
554    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
555       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
556      <jvmarg line="${boot.class.path}"/>
557      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
558      <propertyset>
559        <propertyref prefix="nashorn."/>
560      </propertyset>
561      <propertyset>
562        <propertyref prefix="test262-test-sys-prop."/>
563        <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
564      </propertyset>
565      <classpath>
566          <pathelement path="${run.test.classpath}"/>
567      </classpath>
568    </testng>
569  </target>
570
571  <target name="test262parallel" depends="test262-parallel"/>
572
573  <target name="test262-parallel" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
574    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
575    <java classname="${parallel.test.runner}" dir="${basedir}" fork="true">
576      <jvmarg line="${boot.class.path}"/>
577      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
578      <!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
579      <jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
580      <classpath>
581          <pathelement path="${run.test.classpath}"/>
582      </classpath>
583      <syspropertyset>
584          <propertyref prefix="test262-test-sys-prop."/>
585          <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
586      </syspropertyset>
587    </java>
588  </target>
589
590  <target name="testparallel" depends="test-parallel"/>
591
592  <target name="test-parallel" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
593      <!-- use just build.test.classes.dir to avoid referring to TestNG -->
594      <java classname="${parallel.test.runner}" dir="${basedir}"
595        failonerror="true"
596        fork="true">
597      <jvmarg line="${boot.class.path}"/>
598      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
599      <classpath>
600          <pathelement path="${run.test.classpath}"/>
601      <pathelement path="${build.test.classes.dir}"/>
602      </classpath>
603      <syspropertyset>
604          <propertyref prefix="test-sys-prop."/>
605          <mapper type="glob" from="test-sys-prop.*" to="*"/>
606      </syspropertyset>
607      </java>
608  </target>
609
610  <target name="all" depends="test, docs"
611      description="Build, test and generate docs for nashorn"/>
612
613  <target name="run" depends="jar"
614      description="Run the shell with a sample script">
615    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
616        <jvmarg line="${boot.class.path}"/>
617        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
618        <arg value="-dump-on-error"/>
619        <arg value="test.js"/>
620    </java>
621  </target>
622
623  <target name="debug" depends="jar"
624      description="Debug the shell with a sample script">
625    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
626        <jvmarg line="${boot.class.path}"/>
627        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
628        <arg value="--print-code"/>
629        <arg value="--verify-code"/>
630        <arg value="--print-symbols"/>
631        <jvmarg value="-Dnashorn.codegen.debug=true"/>
632        <arg value="test.js"/>
633    </java>
634  </target>
635
636  <!-- targets to get external script tests -->
637
638  <!-- test262 test suite -->
639  <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
640    <!-- clone test262 git repo -->
641    <exec executable="${git.executable}">
642       <arg value="clone"/>
643       <arg value="--branch"/>
644       <arg value="es5-tests"/>
645       <arg value="https://github.com/tc39/test262"/>
646       <arg value="${test.external.dir}/test262"/>
647    </exec>
648  </target>
649  <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
650    <!-- update test262 git repo -->
651    <exec executable="${git.executable}" dir="${test.external.dir}/test262">
652       <arg value="pull"/>
653    </exec>
654  </target>
655
656  <!-- octane benchmark -->
657  <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
658    <!-- checkout octane benchmarks -->
659    <exec executable="${svn.executable}">
660       <arg value="--non-interactive"/>
661       <arg value="--trust-server-cert"/>
662       <arg value="checkout"/>
663       <arg value="http://octane-benchmark.googlecode.com/svn/trunk/"/>
664       <arg value="${test.external.dir}/octane"/>
665    </exec>
666  </target>
667  <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
668    <!-- update octane benchmarks -->
669    <exec executable="${svn.executable}" dir="${test.external.dir}/octane">
670       <arg value="--non-interactive"/>
671       <arg value="--trust-server-cert"/>
672       <arg value="update"/>
673    </exec>
674  </target>
675
676  <!-- sunspider benchmark -->
677  <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
678    <!-- checkout sunspider -->
679    <exec executable="${svn.executable}">
680       <arg value="--non-interactive"/>
681       <arg value="--trust-server-cert"/>
682       <arg value="checkout"/>
683       <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
684       <arg value="${test.external.dir}/sunspider"/>
685    </exec>
686  </target>
687  <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
688    <!-- update sunspider -->
689    <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
690       <arg value="--non-interactive"/>
691       <arg value="--trust-server-cert"/>
692       <arg value="update"/>
693    </exec>
694  </target>
695
696  <!-- get all external test scripts -->
697  <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider, get-testng">
698    <!-- make external test dir -->
699    <mkdir dir="${test.external.dir}"/>
700
701    <!-- jquery -->
702    <mkdir dir="${test.external.dir}/jquery"/>
703    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
704    <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
705
706    <!-- prototype -->
707    <mkdir dir="${test.external.dir}/prototype"/>
708    <get src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.0/prototype.js" dest="${test.external.dir}/prototype" usetimestamp="true" skipexisting="true" ignoreerrors="true"/>
709
710    <!-- underscorejs -->
711    <mkdir dir="${test.external.dir}/underscore"/>
712    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
713    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
714
715    <!-- yui -->
716    <mkdir dir="${test.external.dir}/yui"/>
717    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
718    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
719
720    <!-- showdown -->
721    <mkdir dir="${test.external.dir}/showdown"/>
722    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
723    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
724
725  </target>
726
727  <!-- update external test suites that are pulled from source control systems -->
728  <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>
729
730  <!-- run all perf tests -->
731  <target name="perf" depends="externals, update-externals, sunspider, octane"/>
732
733  <!-- download and install testng.jar -->
734  <target name="get-testng" depends="prepare" unless="testng.available">
735    <get src="http://testng.org/testng-6.8.zip" dest="${test.lib}" skipexisting="true" ignoreerrors="true"/>
736    <unzip src="${test.lib}${file.separator}testng-6.8.zip" dest="${test.lib}">
737      <patternset>
738        <include name="testng-6.8/testng-6.8.jar"/>
739      </patternset>
740    </unzip>
741    <move file="${test.lib}${file.separator}testng-6.8${file.separator}testng-6.8.jar" tofile="${test.lib}${file.separator}testng.jar"/>
742    <delete dir="${test.lib}${file.separator}testng-6.8"/>
743  </target>
744
745  <!-- run all tests -->
746  <target name="alltests" depends="get-testng, externals, update-externals, test, test262parallel, testmarkdown, perf"/>
747
748  <import file="build-benchmark.xml"/>
749
750</project>
751