build.xml revision 1696:b13b36ca5821
11590Srgrimes<?xml version="1.0" encoding="UTF-8"?>
21590Srgrimes
31590Srgrimes<!--
41590Srgrimes Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
51590Srgrimes DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
61590Srgrimes
71590Srgrimes This code is free software; you can redistribute it and/or modify it
81590Srgrimes under the terms of the GNU General Public License version 2 only, as
91590Srgrimes published by the Free Software Foundation.
101590Srgrimes
111590Srgrimes This code is distributed in the hope that it will be useful, but WITHOUT
121590Srgrimes ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131590Srgrimes FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141590Srgrimes version 2 for more details (a copy is included in the LICENSE file that
151590Srgrimes accompanied this code).
161590Srgrimes
171590Srgrimes You should have received a copy of the GNU General Public License version
181590Srgrimes 2 along with this work; if not, write to the Free Software Foundation,
191590Srgrimes Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201590Srgrimes
211590Srgrimes Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221590Srgrimes or visit www.oracle.com if you need additional information or have any
231590Srgrimes questions.
241590Srgrimes-->
251590Srgrimes
261590Srgrimes<project name="nashorn" default="test" basedir="..">
271590Srgrimes  <import file="build-nasgen.xml"/>
281590Srgrimes  <import file="code_coverage.xml"/>
291590Srgrimes
301590Srgrimes  <target name="init-conditions">
3141568Sarchie    <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
321590Srgrimes    <property file="${user.home}/.nashorn.project.local.properties"/>
331590Srgrimes
3487244Smarkm    <loadproperties srcFile="make/project.properties"/>
351590Srgrimes    <path id="nashorn.jar.path">
3687628Sdwmalone         <pathelement location="${nashorn.jar}"/>
371590Srgrimes    </path>
3887628Sdwmalone    <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
3987244Smarkm      <available file="/usr/local/bin/svn"/>
4087628Sdwmalone    </condition>
411590Srgrimes    <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
4287628Sdwmalone      <available file="/usr/local/bin/hg"/>
4387628Sdwmalone    </condition>
4487628Sdwmalone    <condition property="git.executable" value="/usr/local/bin/git" else="git">
451590Srgrimes      <available file="/usr/local/bin/git"/>
4626960Scharnier    </condition>
47200462Sdelphij    <!-- check if TestNG and dependencies are available, and download them if they aren't -->
48200462Sdelphij    <antcall target="get-testng"/>
49132831Stjr    <condition property="testng.available" value="true">
501590Srgrimes      <and>
511590Srgrimes        <available file="${file.reference.testng.jar}"/>
52200462Sdelphij        <available file="${file.reference.jcommander.jar}"/>
5323690Speter        <available file="${file.reference.bsh.jar}"/>
54132831Stjr        <available file="${file.reference.snakeyaml.jar}"/>
551590Srgrimes      </and>
561590Srgrimes    </condition>
571590Srgrimes
5892920Simp    <!-- check if asmtools-6.0.jar is available, and download it if it isn't -->
5992920Simp    <!--
601590Srgrimes    <available property="asmtools.already.present" file="${file.reference.asmtools.jar}"/>
611590Srgrimes    <antcall target="get-asmtools"/>
62100817Sdwmalone    <available property="asmtools.available" file="${file.reference.asmtools.jar}"/>
631590Srgrimes    -->
6487244Smarkm
65132831Stjr    <!-- check if Jemmy ang TestNG are avaiable -->
661590Srgrimes    <condition property="jemmy.jfx.testng.available" value="true">
671590Srgrimes      <and>
68132831Stjr        <available file="${file.reference.jemmyfx.jar}"/>
69132831Stjr        <available file="${file.reference.jemmycore.jar}"/>
7024360Simp        <available file="${file.reference.jemmyawtinput.jar}"/>
711590Srgrimes        <available file="${file.reference.jfxrt.jar}"/>
721590Srgrimes        <isset property="testng.available"/>
731590Srgrimes      </and>
741590Srgrimes    </condition>
751590Srgrimes
761590Srgrimes    <!-- enable/disable make code coverage -->
771590Srgrimes    <condition property="cc.enabled">
781590Srgrimes        <istrue value="${make.code.coverage}" />
791590Srgrimes    </condition>
801590Srgrimes
811590Srgrimes    <!-- exclude tests in exclude lists -->
821590Srgrimes    <condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt">
831590Srgrimes      <istrue value="${make.code.coverage}" />
8426960Scharnier    </condition>
851590Srgrimes
861590Srgrimes    <condition property="jfr.options" value="${run.test.jvmargs.jfr}" else="">
871590Srgrimes      <istrue value="${jfr}"/>
881590Srgrimes    </condition>
8926960Scharnier
901590Srgrimes    <condition property="test-sys-prop-no-security.os.not.windows">
911590Srgrimes      <not>
921590Srgrimes        <os family="windows"/>
931590Srgrimes      </not>
941590Srgrimes    </condition>
951590Srgrimes
961590Srgrimes    <!--set windows cygwin/cmd specific properties-->
971590Srgrimes    <property environment="env"/>
9826960Scharnier    <condition property="test-sys-prop-no-security.os.not.windows.cmd">
991590Srgrimes     <not>
1001590Srgrimes      <and>
101132831Stjr        <os family="windows"/>
102132831Stjr        <not>
1031590Srgrimes          <isset property="env.SHELL"/>
1041590Srgrimes        </not>
1051590Srgrimes      </and>
1061590Srgrimes     </not>
1071590Srgrimes    </condition>
1081590Srgrimes   </target>
1091590Srgrimes  
1101590Srgrimes
1111590Srgrimes  <!-- check minimum ant version required to be 1.8.4 -->
1121590Srgrimes  <target name="check-ant-version">
1131590Srgrimes    <property name="ant.version.required" value="1.8.4"/>
1141590Srgrimes    <antversion property="ant.current.version" />
1151590Srgrimes    <fail message="The current ant version, ${ant.current.version}, is too old. Please use 1.8.4 or above.">
116132831Stjr        <condition>
117132831Stjr            <not>
1181590Srgrimes                <antversion atleast="${ant.version.required}"/>
1191590Srgrimes            </not>
1201590Srgrimes        </condition>
12132069Salex    </fail>
122132831Stjr  </target>
1231590Srgrimes
1241590Srgrimes  <target name="check-java-version">
1251590Srgrimes    <!-- look for a Class that is available only in jdk1.8 or above -->
1261590Srgrimes    <!-- core/exposed API class is better than an implementation class -->
1271590Srgrimes    <available property="jdk1.8+" classname="java.util.stream.Stream"/>
128100817Sdwmalone
1291590Srgrimes    <!-- need jdk1.8 or above -->
1301590Srgrimes    <fail message="Unsupported Java version: ${ant.java.version}. Please use Java version 1.8 or greater." unless="jdk1.8+">
1311590Srgrimes    </fail>
1321590Srgrimes  </target>
13326960Scharnier
1341590Srgrimes  <target name="init" depends="check-ant-version, check-java-version, init-conditions, init-cc">
1351590Srgrimes    <!-- extends jvm args -->
1361590Srgrimes    <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
137100817Sdwmalone    <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
1381590Srgrimes
1391590Srgrimes    <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
1401590Srgrimes    <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
1411590Srgrimes    <echo message="run.test.xms=${run.test.xms}"/>
1421590Srgrimes    <echo message="run.test.xmx=${run.test.xmx}"/>
143
144  </target>
145
146  <target name="prepare" depends="init">
147    <mkdir dir="${build.dir}"/>
148    <mkdir dir="${build.classes.dir}"/>
149    <mkdir dir="${nashorn.module.classes.dir}"/>
150    <mkdir dir="${dynalink.module.classes.dir}"/>
151    <mkdir dir="${nashorn.shell.module.classes.dir}"/>
152    <mkdir dir="${nashorn.module.classes.dir}/META-INF/services"/>
153    <mkdir dir="${build.test.classes.dir}"/>
154    <mkdir dir="${dist.dir}"/>
155    <mkdir dir="${dist.javadoc.dir}"/>
156  </target>
157
158  <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
159    <delete includeemptydirs="true">
160      <fileset dir="${build.dir}" erroronmissingdir="false"/>
161    </delete>
162    <delete dir="${dist.dir}"/>
163  </target>
164
165  <target name="compile" depends="prepare" description="Compiles nashorn">
166    <javac srcdir="${dynalink.module.src.dir}"
167           destdir="${dynalink.module.classes.dir}"
168           source="${javac.source}"
169           target="${javac.target}"
170           debug="${javac.debug}"
171           encoding="${javac.encoding}"
172           includeantruntime="false" fork="true">
173      <compilerarg value="-Xlint:all"/>
174      <compilerarg value="-XDignore.symbol.file"/>
175      <compilerarg value="-Xdiags:verbose"/>
176      <compilerarg value="-parameters"/>
177    </javac>
178    <!-- -Xpatch does not like module-info.class files! -->
179    <delete>
180      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
181    </delete>
182    <javac srcdir="${nashorn.module.src.dir}"
183           destdir="${nashorn.module.classes.dir}"
184           source="${javac.source}"
185           target="${javac.target}"
186           debug="${javac.debug}"
187           encoding="${javac.encoding}"
188           includeantruntime="false" fork="true">
189      <compilerarg value="-Xlint:all"/>
190      <compilerarg value="-XDignore.symbol.file"/>
191      <compilerarg value="-Xdiags:verbose"/>
192      <compilerarg value="-parameters"/>
193      <compilerarg line="${nashorn.override.option}"/>
194    </javac>
195    <!-- -Xpatch does not like module-info.class files! -->
196    <delete>
197      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
198    </delete>
199    <javac srcdir="${nashorn.shell.module.src.dir}"
200           destdir="${nashorn.shell.module.classes.dir}"
201           source="${javac.source}"
202           target="${javac.target}"
203           debug="${javac.debug}"
204           encoding="${javac.encoding}"
205           includeantruntime="false" fork="true">
206      <compilerarg value="-Xlint:all"/>
207      <compilerarg value="-XDignore.symbol.file"/>
208      <compilerarg value="-Xdiags:verbose"/>
209      <compilerarg value="-parameters"/>
210      <compilerarg line="${nashorn.override.option}"/>
211    </javac>
212    <!-- -Xpatch does not like module-info.class files! -->
213    <delete>
214      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
215    </delete>
216     <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/api/scripting/resources">
217       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/api/scripting/resources/"/>
218    </copy>
219    <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources">
220       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/internal/runtime/resources/"/>
221    </copy>
222    <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/tools/resources">
223       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/tools/resources/"/>
224    </copy>
225    <copy file="${dynalink.module.src.dir}/jdk/dynalink/support/messages.properties" todir="${dynalink.module.classes.dir}/jdk/dynalink/support"/>
226    <copy file="${nashorn.module.src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/codegen"/>
227
228    <echo message="version_string=${nashorn.fullversion}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
229    <echo file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
230    <echo message="version_short=${nashorn.version}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
231  </target>
232
233  <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
234    <jar jarfile="${dynalink.jar}">
235      <fileset dir="${dynalink.module.classes.dir}"/>
236    </jar>
237    <jar jarfile="${nashorn.jar}" index="true" filesetmanifest="merge">
238      <fileset dir="${nashorn.module.classes.dir}"/>
239      <manifest>
240        <attribute name="Archiver-Version" value="n/a"/>
241        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
242        <attribute name="Built-By" value="n/a"/>
243        <attribute name="Created-By" value="Ant jar task"/>
244        <section name="jdk/nashorn/">
245          <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
246          <attribute name="Implementation-Version" value="${nashorn.version}"/>
247        </section>
248      </manifest>
249    </jar>
250    <jar jarfile="${jjs.jar}">
251      <fileset dir="${nashorn.shell.module.classes.dir}"/>
252    </jar>
253  </target>
254
255  <target name="use-promoted-nashorn" depends="init">
256    <delete file="${dist.dir}/nashorn.jar"/>
257    <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
258    <property name="compile.suppress.jar" value="defined"/>
259  </target>
260
261  <!-- generate javadoc for all Nashorn and ASM classes -->
262  <target name="javadoc" depends="jar">
263    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html"
264        windowtitle="${nashorn.product.name} ${nashorn.version}"
265        additionalparam="-quiet" failonerror="true" useexternalfile="true">
266      <arg value="${javadoc.option}"/>
267      <classpath>
268        <pathelement location="${build.classes.dir}"/>
269      </classpath>
270      <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/>
271      <fileset dir="${nashorn.shell.module.src.dir}" includes="**/*.java"/>
272      <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/>
273      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
274      <!-- The following tags are used only in ASM sources - just ignore these -->
275      <tag name="label" description="label tag in ASM sources" enabled="false"/>
276      <tag name="linked" description="linked tag in ASM sources" enabled="false"/>
277      <tag name="associates" description="associates tag in ASM sources" enabled="false"/>
278    </javadoc>
279  </target>
280
281  <!-- generate javadoc for Nashorn classes -->
282  <target name="javadocnh" depends="jar">
283    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html"
284        windowtitle="${nashorn.product.name} ${nashorn.version}"
285        additionalparam="-quiet" failonerror="true" useexternalfile="true">
286      <arg value="${javadoc.option}"/>
287      <classpath>
288        <pathelement location="${build.classes.dir}"/>
289      </classpath>
290      <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
291      <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/>
292      <fileset dir="${nashorn.shell.module.src.dir}" includes="**/*.java"/>
293      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
294    </javadoc>
295  </target>
296
297  <!-- generate javadoc only for nashorn extension api classes -->
298  <target name="javadocapi" depends="jar">
299    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html"
300        extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
301        additionalparam="-quiet" failonerror="true" useexternalfile="true">
302      <arg value="${javadoc.option}"/>
303      <classpath>
304        <pathelement location="${build.classes.dir}"/>
305      </classpath>
306      <fileset dir="${nashorn.module.src.dir}" includes="jdk/nashorn/api/**/*.java"/>
307      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
308    </javadoc>
309  </target>
310
311  <!-- generate javadoc only for Dynalink API classes -->
312  <target name="dynalinkapi" depends="jar">
313    <javadoc destdir="${dist.javadoc.dir}" use="yes"
314        windowtitle="Dynalink"
315        additionalparam="-quiet" failonerror="true" useexternalfile="true">
316      <arg value="${javadoc.option}"/>
317      <classpath>
318        <pathelement location="${build.classes.dir}"/>
319      </classpath>
320      <fileset dir="${dynalink.module.src.dir}" includes="**/*.java" excludes="jdk/dynalink/internal/*.java"/>
321      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
322    </javadoc>
323  </target>
324
325  <!-- generate shell.html for shell tool documentation -->
326  <target name="shelldoc" depends="jar">
327    <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
328      <jvmarg line="${nashorn.override.option}"/>
329      <arg value="-scripting"/>
330      <arg value="docs/genshelldoc.js"/>
331    </java>
332  </target>
333
334  <!-- generate all docs -->
335  <target name="docs" depends="javadoc, shelldoc"/>
336
337  <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
338  <target name="dist" depends="jar">
339      <zip destfile="${build.zip}" basedir=".."
340          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
341      <tar destfile="${build.gzip}" basedir=".." compression="gzip"
342          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
343  </target>
344
345  <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
346    <!-- testng task -->
347    <taskdef name="testng" classname="org.testng.TestNGAntTask"
348        classpath="${testng.ant.classpath}"/>
349
350    <javac srcdir="${test.src.dir}"
351           destdir="${build.test.classes.dir}"
352           classpath="${javac.test.classpath}"
353           source="${javac.source}"
354           target="${javac.target}"
355           debug="${javac.debug}"
356           encoding="${javac.encoding}"
357           includeantruntime="false" fork="true">
358        <compilerarg line="${nashorn.override.option}"/>
359        <compilerarg value="-Xlint:unchecked"/>
360        <compilerarg value="-Xlint:deprecation"/>
361        <compilerarg value="-Xdiags:verbose"/>
362        <compilerarg line="${test.module.imports}"/>
363    </javac>
364
365    <copy todir="${build.test.classes.dir}/META-INF/services">
366       <fileset dir="${test.src.dir}/META-INF/services/"/>
367    </copy>
368
369    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/test/resources">
370       <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/test/resources"/>
371    </copy>
372
373    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources">
374      <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources"/>
375    </copy>
376
377    <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/test/resources">
378       <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/test/resources"/>
379    </copy>
380
381    <!-- tests that check nashorn internals and internal API -->
382    <jar jarfile="${nashorn.internal.tests.jar}">
383      <fileset dir="${build.test.classes.dir}" includes="**/internal/**"/>
384      <fileset dir="${build.test.classes.dir}" includes="**/test/tools/**"/>
385      <fileset dir="${build.test.classes.dir}" includes="**/models/**"/>
386      <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/test/Trusted**"/>
387      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
388    </jar>
389
390    <!-- tests that check nashorn script engine (jsr-223) API and dynalink API -->
391    <jar jarfile="${nashorn.api.tests.jar}">
392      <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/**" excludes="**/jdk/dynalink/test/Trusted**"/>
393      <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
394      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
395      <fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
396      <fileset dir="${build.test.classes.dir}" includes="**/UnnamedPackage**"/>
397    </jar>
398
399  </target>
400
401  <target name="generate-policy-file" depends="prepare">
402    <echo file="${build.dir}/nashorn.policy">
403
404grant codeBase "file:/${basedir}/${dynalink.module.classes.dir}" {
405    permission java.security.AllPermission;
406};
407
408grant codeBase "file:/${basedir}/${nashorn.module.classes.dir}" {
409    permission java.security.AllPermission;
410};
411
412grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
413    permission java.security.AllPermission;
414};
415
416grant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" {
417    permission java.util.PropertyPermission "parserapitest.*", "read";
418    permission java.util.PropertyPermission "test.*", "read";
419    permission java.util.PropertyPermission "test262.*", "read";
420    permission java.io.FilePermission "${basedir}/test/-","read";
421    permission java.io.FilePermission "$${user.dir}", "read";
422    permission java.util.PropertyPermission "user.dir", "read";
423};
424
425grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
426    permission java.security.AllPermission;
427};
428grant codeBase "file:/${basedir}/${file.reference.jcommander.jar}" {
429    permission java.security.AllPermission;
430};
431grant codeBase "file:/${basedir}/${file.reference.bsh.jar}" {
432    permission java.security.AllPermission;
433};
434grant codeBase "file:/${basedir}/${file.reference.snakeyaml.jar}" {
435    permission java.security.AllPermission;
436};
437//// in case of absolute path:
438grant codeBase "file:/${nashorn.internal.tests.jar}" {
439    permission java.security.AllPermission;
440};
441
442grant codeBase "file:/${file.reference.testng.jar}" {
443    permission java.security.AllPermission;
444};
445grant codeBase "file:/${file.reference.jcommander.jar}" {
446    permission java.security.AllPermission;
447};
448grant codeBase "file:/${file.reference.bsh.jar}" {
449    permission java.security.AllPermission;
450};
451grant codeBase "file:/${file.reference.snakeyaml.jar}" {
452    permission java.security.AllPermission;
453};
454
455
456grant codeBase "file:/${basedir}/test/script/trusted/*" {
457    permission java.security.AllPermission;
458};
459
460grant codeBase "file:/${basedir}/test/script/maptests/*" {
461    permission java.io.FilePermission "${basedir}/test/script/maptests/*","read";
462    permission java.lang.RuntimePermission "nashorn.debugMode";
463};
464
465grant codeBase "file:/${basedir}/test/script/basic/*" {
466    permission java.io.FilePermission "${basedir}/test/script/-", "read";
467    permission java.io.FilePermission "$${user.dir}", "read";
468    permission java.util.PropertyPermission "user.dir", "read";
469    permission java.util.PropertyPermission "nashorn.test.*", "read";
470};
471
472grant codeBase "file:/${basedir}/test/script/basic/apply_to_call/*" {
473    permission java.io.FilePermission "${basedir}/test/script/-", "read";
474    permission java.io.FilePermission "$${user.dir}", "read";
475    permission java.util.PropertyPermission "user.dir", "read";
476    permission java.util.PropertyPermission "nashorn.test.*", "read";
477};
478
479grant codeBase "file:/${basedir}/test/script/basic/parser/*" {
480    permission java.io.FilePermission "${basedir}/test/script/-", "read";
481    permission java.io.FilePermission "$${user.dir}", "read";
482    permission java.util.PropertyPermission "user.dir", "read";
483    permission java.util.PropertyPermission "nashorn.test.*", "read";
484};
485
486grant codeBase "file:/${basedir}/test/script/basic/es6/*" {
487    permission java.io.FilePermission "${basedir}/test/script/-", "read";
488    permission java.io.FilePermission "$${user.dir}", "read";
489    permission java.util.PropertyPermission "user.dir", "read";
490    permission java.util.PropertyPermission "nashorn.test.*", "read";
491};
492
493grant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
494    permission java.util.PropertyPermission "java.security.policy", "read";
495};
496
497grant codeBase "file:/${basedir}/test/script/basic/classloader.js" {
498    permission java.lang.RuntimePermission "nashorn.JavaReflection";
499};
500
501grant codeBase "file:/${basedir}/test/script/markdown.js" {
502    permission java.io.FilePermission "${basedir}/test/script/external/showdown/-", "read";
503};
504
505    </echo>
506
507    <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace>    <!--hack for Windows - to make URLs with normal path separators -->
508    <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace>   <!--hack for Unix - to avoid leading // in URLs -->
509
510  </target>
511
512  <target name="check-external-tests">
513      <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
514      <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
515      <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
516      <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
517      <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
518      <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
519      <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
520      <available file="${test.external.dir}/showdown" property="test-sys-prop.external.markdown"/>
521  </target>
522
523  <target name="check-testng" unless="testng.available">
524    <echo message="WARNING: TestNG not available, will not run tests. Please copy TestNG and dependency JARs to the ${test.lib} directory."/>
525  </target>
526
527  <!-- only to be invoked as dependency of "test" target -->
528  <target name="-test-classes-all" depends="jar" unless="test.class">
529      <fileset id="test.classes" dir="${build.test.classes.dir}">
530          <include name="**/dynalink/test/*Test.class"/>
531          <include name="**/dynalink/beans/test/*Test.class"/>
532          <include name="**/api/javaaccess/test/*Test.class"/>
533          <include name="**/api/scripting/test/*Test.class"/>
534          <include name="**/api/tree/test/*Test.class"/>
535          <include name="**/codegen/test/*Test.class"/>
536          <include name="**/parser/test/*Test.class"/>
537          <include name="**/runtime/test/*Test.class"/>
538          <include name="**/runtime/regexp/test/*Test.class"/>
539          <include name="**/runtime/regexp/joni/test/*Test.class"/>
540          <include name="**/runtime/doubleconv/test/*Test.class"/>
541          <include name="**/framework/*Test.class"/>
542     </fileset>
543  </target>
544
545  <!-- only to be invoked as dependency of "test" target -->
546  <target name="-test-classes-single" depends="jar" if="test.class">
547     <fileset id="test.classes" dir="${build.test.classes.dir}">
548         <include name="${test.class}*"/>
549     </fileset>
550  </target>
551
552  <!-- only to be invoked as dependency of "test" target -->
553  <target name="-test-nosecurity" unless="test.class">
554    <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
555      <include name="**/framework/ScriptTest.class"/>
556    </fileset>
557    <testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
558       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
559      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
560      <sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
561      <propertyset>
562        <propertyref prefix="nashorn."/>
563      </propertyset>
564      <propertyset>
565        <propertyref prefix="test-sys-prop-no-security."/>
566        <mapper from="test-sys-prop-no-security.*" to="*" type="glob"/>
567      </propertyset>
568      <sysproperty key="optimistic.override" value="${optimistic}"/>
569      <classpath>
570          <pathelement path="${run.test.classpath}"/>
571      </classpath>
572    </testng>
573  </target>
574
575  <!-- only to be invoked as dependency of "test" target -->
576  <target name="-test-security">
577    <delete dir="${build.dir}/nashorn_code_cache"/>
578    <property name="debug.test.jvmargs" value=""/>
579    <testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
580            verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
581      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
582      <jvmarg line="${debug.test.jvmargs}"/>
583      <propertyset>
584        <propertyref prefix="nashorn."/>
585      </propertyset>
586      <propertyset>
587        <propertyref prefix="test-sys-prop."/>
588        <mapper from="test-sys-prop.*" to="*" type="glob"/>
589      </propertyset>
590      <sysproperty key="optimistic.override" value="${optimistic}"/>
591      <sysproperty key="test.js.excludes.file" value="${exclude.list}"/>
592      <classpath>
593          <pathelement path="${run.test.classpath}"/>
594      </classpath>
595    </testng>
596  </target>
597
598  <target name="test" depends="prepare, test-pessimistic, test-optimistic"/>
599
600  <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">
601    <echo message="Running test suite in OPTIMISTIC mode..."/>
602    <antcall target="-test-nosecurity" inheritRefs="true">
603      <param name="optimistic" value="true"/>
604      <param name="testResultsSubDir" value="optimistic"/>
605    </antcall>
606    <antcall target="-test-security" inheritRefs="true">
607      <param name="optimistic" value="true"/>
608      <param name="testResultsSubDir" value="optimistic"/>
609    </antcall>
610  </target>
611
612  <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">
613    <echo message="Running test suite in PESSIMISTIC mode..."/>
614    <antcall target="-test-nosecurity" inheritRefs="true">
615      <param name="optimistic" value="false"/>
616      <param name="testResultsSubDir" value="pessimistic"/>
617    </antcall>
618    <antcall target="-test-security" inheritRefs="true">
619      <param name="optimistic" value="false"/>
620      <param name="testResultsSubDir" value="pessimistic"/>
621    </antcall>
622  </target>
623
624  <target name="check-jemmy.jfx.testng" unless="jemmy.jfx.testng.available">
625    <echo message="WARNING: Jemmy or JavaFX or TestNG not available, will not run tests. Please copy TestNG and dependency JARs, JemmyCore.jar, JemmyFX.jar, JemmyAWTInput.jar to the test${file.separator}lib directory. And make sure you have jfxrt.jar in ${java.home}${file.separator}lib${file.separator}ext dir."/>
626  </target>
627
628  <target name="testjfx" depends="jar, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available">
629    <fileset id="test.classes" dir="${build.test.classes.dir}">
630       <include name="**/framework/*Test.class"/>
631    </fileset>
632
633    <copy file="${file.reference.jfxrt.jar}" todir="dist"/>
634
635    <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
636        <not>
637            <os family="mac"/>
638        </not>
639    </condition>
640
641    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
642       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
643      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
644      <propertyset>
645        <propertyref prefix="testjfx-test-sys-prop."/>
646        <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
647      </propertyset>
648      <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
649      <classpath>
650          <pathelement path="${testjfx.run.test.classpath}"/>
651      </classpath>
652    </testng>
653  </target>
654
655  <target name="testmarkdown" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
656    <fileset id="test.classes" dir="${build.test.classes.dir}">
657       <include name="**/framework/*Test.class"/>
658    </fileset>
659
660    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
661       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
662      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
663      <propertyset>
664        <propertyref prefix="testmarkdown-test-sys-prop."/>
665        <mapper from="testmarkdown-test-sys-prop.*" to="*" type="glob"/>
666      </propertyset>
667      <classpath>
668          <pathelement path="${run.test.classpath}"/>
669      </classpath>
670    </testng>
671  </target>
672
673  <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
674    <fileset id="test.classes" dir="${build.test.classes.dir}">
675       <include name="**/framework/*Test.class"/>
676    </fileset>
677
678    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
679       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
680      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
681      <propertyset>
682        <propertyref prefix="nashorn."/>
683      </propertyset>
684      <propertyset>
685        <propertyref prefix="test262-test-sys-prop."/>
686        <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
687      </propertyset>
688      <classpath>
689          <pathelement path="${run.test.classpath}"/>
690      </classpath>
691    </testng>
692  </target>
693
694  <target name="test262parallel" depends="test262-parallel"/>
695
696  <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
697    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
698    <java classname="${parallel.test.runner}" dir="${basedir}" fork="true" failonerror="true">
699      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
700      <!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
701      <jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
702      <classpath>
703          <pathelement path="${run.test.classpath}"/>
704      </classpath>
705      <syspropertyset>
706          <propertyref prefix="test262-test-sys-prop."/>
707          <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
708      </syspropertyset>
709    </java>
710  </target>
711
712  <target name="testparallel" depends="test-parallel"/>
713
714  <target name="test-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
715      <!-- use just build.test.classes.dir to avoid referring to TestNG -->
716      <java classname="${parallel.test.runner}" dir="${basedir}"
717        failonerror="true"
718        fork="true">
719      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
720      <classpath>
721          <pathelement path="${run.test.classpath}"/>
722      <pathelement path="${build.test.classes.dir}"/>
723      </classpath>
724      <syspropertyset>
725          <propertyref prefix="test-sys-prop."/>
726          <mapper type="glob" from="test-sys-prop.*" to="*"/>
727      </syspropertyset>
728      </java>
729  </target>
730
731  <target name="all" depends="test, docs"
732      description="Build, test and generate docs for nashorn"/>
733
734  <target name="run" depends="jar"
735      description="Run the shell with a sample script">
736    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
737        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
738        <arg value="-dump-on-error"/>
739        <arg value="test.js"/>
740    </java>
741  </target>
742
743  <target name="debug" depends="jar"
744      description="Debug the shell with a sample script">
745    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
746        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
747        <arg value="--print-code"/>
748        <arg value="--verify-code"/>
749        <arg value="--print-symbols"/>
750        <jvmarg value="-Dnashorn.codegen.debug=true"/>
751        <arg value="test.js"/>
752    </java>
753  </target>
754
755  <!-- targets to get external script tests -->
756
757  <!-- test262 test suite -->
758  <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
759    <!-- clone test262 git repo -->
760    <exec executable="${git.executable}">
761       <arg value="clone"/>
762       <arg value="--branch"/>
763       <arg value="es5-tests"/>
764       <arg value="https://github.com/tc39/test262"/>
765       <arg value="${test.external.dir}/test262"/>
766    </exec>
767  </target>
768  <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
769    <!-- update test262 git repo -->
770    <exec executable="${git.executable}" dir="${test.external.dir}/test262">
771       <arg value="pull"/>
772    </exec>
773  </target>
774
775  <!-- octane benchmark -->
776  <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
777    <!-- checkout octane benchmarks -->
778    <exec executable="${git.executable}">
779       <arg value="clone"/>
780       <arg value="https://github.com/chromium/octane"/>
781       <arg value="${test.external.dir}/octane"/>
782    </exec>
783  </target>
784  <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
785    <!-- update octane benchmarks -->
786    <exec executable="${git.executable}" dir="${test.external.dir}/octane">
787       <arg value="pull"/>
788    </exec>
789  </target>
790
791  <!-- sunspider benchmark -->
792  <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
793    <!-- checkout sunspider -->
794    <exec executable="${svn.executable}">
795       <arg value="--non-interactive"/>
796       <arg value="--trust-server-cert"/>
797       <arg value="checkout"/>
798       <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
799       <arg value="${test.external.dir}/sunspider"/>
800    </exec>
801  </target>
802  <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
803    <!-- update sunspider -->
804    <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
805       <arg value="--non-interactive"/>
806       <arg value="--trust-server-cert"/>
807       <arg value="update"/>
808    </exec>
809  </target>
810
811  <!-- get all external test scripts -->
812  <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider">
813    <!-- make external test dir -->
814    <mkdir dir="${test.external.dir}"/>
815
816    <!-- jquery -->
817    <mkdir dir="${test.external.dir}/jquery"/>
818    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
819    <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
820
821    <!-- prototype -->
822    <mkdir dir="${test.external.dir}/prototype"/>
823    <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"/>
824
825    <!-- underscorejs -->
826    <mkdir dir="${test.external.dir}/underscore"/>
827    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
828    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
829
830    <!-- yui -->
831    <mkdir dir="${test.external.dir}/yui"/>
832    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
833    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
834
835    <!-- showdown -->
836    <mkdir dir="${test.external.dir}/showdown"/>
837    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
838    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
839
840  </target>
841
842  <!-- update external test suites that are pulled from source control systems -->
843  <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>
844
845  <!-- run all perf tests -->
846  <target name="perf" depends="externals, update-externals, sunspider, octane"/>
847
848  <!-- download and install testng.jar -->
849  <target name="get-testng">
850    <get dest="${test.lib}" skipexisting="true">
851      <url url="http://central.maven.org/maven2/org/testng/testng/6.8/testng-6.8.jar"/>
852      <url url="http://central.maven.org/maven2/com/beust/jcommander/1.27/jcommander-1.27.jar"/>
853      <url url="http://central.maven.org/maven2/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar"/>
854      <url url="http://central.maven.org/maven2/org/yaml/snakeyaml/1.6/snakeyaml-1.6.jar"/>
855    </get>
856  </target>
857
858  <!-- download and install asmtools.jar -->
859  <target name="get-asmtools" unless="asmtools.already.present">
860    <get src="https://adopt-openjdk.ci.cloudbees.com/view/OpenJDK/job/asmtools/lastSuccessfulBuild/artifact/asmtools-6.0.tar.gz" dest="${test.lib}" skipexisting="true" ignoreerrors="true"/>
861    <untar src="${test.lib}${file.separator}asmtools-6.0.tar.gz" dest="${test.lib}" compression="gzip"/>
862    <!-- they are tar.gz'ing a .zip file! -->
863    <unzip src="${test.lib}${file.separator}asmtools-6.0.zip" dest="${test.lib}">
864      <patternset>
865        <include name="asmtools-6.0/lib/asmtools.jar"/>
866      </patternset>
867    </unzip>
868    <move file="${test.lib}${file.separator}asmtools-6.0${file.separator}lib${file.separator}asmtools.jar" tofile="${test.lib}${file.separator}asmtools.jar"/>
869    <delete dir="${test.lib}${file.separator}asmtools-6.0"/>
870  </target>
871
872  <!-- run all tests -->
873  <target name="alltests" depends="externals, update-externals, test, test262parallel, testmarkdown, perf"/>
874
875  <import file="build-benchmark.xml"/>
876
877</project>
878