1 <?xml version="1.0" encoding="UTF-8"?>
   2 
   3 <!--
   4  Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   5  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 
   7  This code is free software; you can redistribute it and/or modify it
   8  under the terms of the GNU General Public License version 2 only, as
   9  published by the Free Software Foundation.
  10 
  11  This code is distributed in the hope that it will be useful, but WITHOUT
  12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  version 2 for more details (a copy is included in the LICENSE file that
  15  accompanied this code).
  16 
  17  You should have received a copy of the GNU General Public License version
  18  2 along with this work; if not, write to the Free Software Foundation,
  19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 
  21  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  or visit www.oracle.com if you need additional information or have any
  23  questions.
  24 -->
  25 
  26 <project name="nashorn" default="test" basedir="..">
  27   <import file="build-nasgen.xml"/>
  28   <import file="code_coverage.xml"/>
  29 
  30   <target name="load-properties">
  31     <!-- set default values to run.test.jvmargs.external property -->
  32     <condition property="run.test.jvmargs.external" value="">
  33      <not><isset property="run.test.jvmargs.external"/></not>
  34     </condition>     
  35     <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
  36     <property file="${user.home}/.nashorn.project.local.properties"/>
  37 
  38     <loadproperties srcFile="make/project.properties"/>
  39   </target>
  40 
  41   <target name="init-conditions" depends="load-properties">
  42     <path id="nashorn.jar.path">
  43          <pathelement location="${nashorn.jar}"/>
  44     </path>
  45     <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
  46       <available file="/usr/local/bin/svn"/>
  47     </condition>
  48     <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
  49       <available file="/usr/local/bin/hg"/>
  50     </condition>
  51     <condition property="git.executable" value="/usr/local/bin/git" else="git">
  52       <available file="/usr/local/bin/git"/>
  53     </condition>
  54     <!-- check if TestNG and dependencies are available, and download them if they aren't -->
  55     <antcall target="get-testng"/>
  56     <condition property="testng.available" value="true">
  57       <and>
  58         <available file="${file.reference.testng.jar}"/>
  59         <available file="${file.reference.jcommander.jar}"/>
  60         <available file="${file.reference.bsh.jar}"/>
  61         <available file="${file.reference.snakeyaml.jar}"/>
  62       </and>
  63     </condition>
  64 
  65     <!-- check if asmtools-6.0.jar is available, and download it if it isn't -->
  66     <!--
  67     <available property="asmtools.already.present" file="${file.reference.asmtools.jar}"/>
  68     <antcall target="get-asmtools"/>
  69     <available property="asmtools.available" file="${file.reference.asmtools.jar}"/>
  70     -->
  71 
  72     <!-- check if Jemmy ang TestNG are avaiable -->
  73     <condition property="jemmy.jfx.testng.available" value="true">
  74       <and>
  75         <available file="${file.reference.jemmyfx.jar}"/>
  76         <available file="${file.reference.jemmycore.jar}"/>
  77         <available file="${file.reference.jemmyawtinput.jar}"/>
  78         <available file="${file.reference.jfxrt.jar}"/>
  79         <isset property="testng.available"/>
  80       </and>
  81     </condition>
  82 
  83     <!-- enable/disable make code coverage -->
  84     <condition property="cc.enabled">
  85         <istrue value="${make.code.coverage}" />
  86     </condition>
  87 
  88     <!-- exclude tests in exclude lists -->
  89     <condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt">
  90       <istrue value="${make.code.coverage}" />
  91     </condition>
  92 
  93     <condition property="jfr.options" value="${run.test.jvmargs.jfr}" else="">
  94       <istrue value="${jfr}"/>
  95     </condition>
  96 
  97     <condition property="test-sys-prop-no-security.os.not.windows">
  98       <not>
  99         <os family="windows"/>
 100       </not>
 101     </condition>
 102 
 103     <!--set windows cygwin/cmd specific properties-->
 104     <property environment="env"/>
 105     <condition property="test-sys-prop-no-security.os.not.windows.cmd">
 106      <not>
 107       <and>
 108         <os family="windows"/>
 109         <not>
 110           <isset property="env.SHELL"/>
 111         </not>
 112       </and>
 113      </not>
 114     </condition>
 115    </target>
 116   
 117 
 118   <!-- check minimum ant version required to be 1.8.4 -->
 119   <target name="check-ant-version">
 120     <property name="ant.version.required" value="1.8.4"/>
 121     <antversion property="ant.current.version" />
 122     <fail message="The current ant version, ${ant.current.version}, is too old. Please use 1.8.4 or above.">
 123         <condition>
 124             <not>
 125                 <antversion atleast="${ant.version.required}"/>
 126             </not>
 127         </condition>
 128     </fail>
 129   </target>
 130 
 131   <target name="check-java-version">
 132     <!-- look for a Class that is available only in jdk1.8 or above -->
 133     <!-- core/exposed API class is better than an implementation class -->
 134     <available property="jdk1.8+" classname="java.util.stream.Stream"/>
 135 
 136     <!-- need jdk1.8 or above -->
 137     <fail message="Unsupported Java version: ${ant.java.version}. Please use Java version 1.8 or greater." unless="jdk1.8+">
 138     </fail>
 139   </target>
 140 
 141   <target name="init" depends="check-ant-version, check-java-version, init-conditions, init-cc">
 142     <!-- extends jvm args -->
 143     <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
 144     <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
 145 
 146     <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
 147     <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
 148     <echo message="run.test.xms=${run.test.xms}"/>
 149     <echo message="run.test.xmx=${run.test.xmx}"/>
 150 
 151   </target>
 152 
 153   <target name="prepare" depends="init">
 154     <mkdir dir="${build.dir}"/>
 155     <mkdir dir="${build.classes.dir}"/>
 156     <mkdir dir="${nashorn.module.classes.dir}"/>
 157     <mkdir dir="${dynalink.module.classes.dir}"/>
 158     <mkdir dir="${nashorn.shell.module.classes.dir}"/>
 159     <mkdir dir="${nashorn.module.classes.dir}/META-INF/services"/>
 160     <mkdir dir="${build.test.classes.dir}"/>
 161     <mkdir dir="${dist.dir}"/>
 162     <mkdir dir="${dist.javadoc.dir}"/>
 163   </target>
 164 
 165   <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
 166     <delete includeemptydirs="true">
 167       <fileset dir="${build.dir}" erroronmissingdir="false"/>
 168     </delete>
 169     <delete dir="${dist.dir}"/>
 170   </target>
 171 
 172   <target name="compile" depends="prepare" description="Compiles nashorn">
 173     <javac srcdir="${dynalink.module.src.dir}"
 174            destdir="${dynalink.module.classes.dir}"
 175            source="${javac.source}"
 176            target="${javac.target}"
 177            debug="${javac.debug}"
 178            encoding="${javac.encoding}"
 179            includeantruntime="false" fork="true">
 180       <compilerarg value="-Xlint:all"/>
 181       <compilerarg value="-XDignore.symbol.file"/>
 182       <compilerarg value="-Xdiags:verbose"/>
 183       <compilerarg value="-parameters"/>
 184     </javac>
 185     <!-- patch-module does not like module-info.class files! -->
 186     <delete>
 187       <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
 188     </delete>
 189     <javac srcdir="${nashorn.module.src.dir}"
 190            destdir="${nashorn.module.classes.dir}"
 191            source="${javac.source}"
 192            target="${javac.target}"
 193            debug="${javac.debug}"
 194            encoding="${javac.encoding}"
 195            includeantruntime="false" fork="true">
 196       <compilerarg value="-Xlint:all"/>
 197       <compilerarg value="-XDignore.symbol.file"/>
 198       <compilerarg value="-Xdiags:verbose"/>
 199       <compilerarg value="-parameters"/>
 200       <compilerarg line="${nashorn.override.option}"/>
 201     </javac>
 202     <!-- patch-module does not like module-info.class files! -->
 203     <delete>
 204       <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
 205     </delete>
 206     <javac srcdir="${nashorn.shell.module.src.dir}"
 207            destdir="${nashorn.shell.module.classes.dir}"
 208            source="${javac.source}"
 209            target="${javac.target}"
 210            debug="${javac.debug}"
 211            encoding="${javac.encoding}"
 212            includeantruntime="false" fork="true">
 213       <compilerarg value="-Xlint:all"/>
 214       <compilerarg value="-XDignore.symbol.file"/>
 215       <compilerarg value="-Xdiags:verbose"/>
 216       <compilerarg value="-parameters"/>
 217       <compilerarg line="${nashorn.override.option}"/>
 218     </javac>
 219     <!-- patch-module does not like module-info.class files! -->
 220     <delete>
 221       <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
 222     </delete>
 223      <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/api/scripting/resources">
 224        <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/api/scripting/resources/"/>
 225     </copy>
 226     <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources">
 227        <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/internal/runtime/resources/"/>
 228     </copy>
 229     <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/tools/resources">
 230        <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/tools/resources/"/>
 231     </copy>
 232     <copy file="${dynalink.module.src.dir}/jdk/dynalink/support/messages.properties" todir="${dynalink.module.classes.dir}/jdk/dynalink/support"/>
 233     <copy file="${nashorn.module.src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/codegen"/>
 234 
 235     <echo message="version_string=${nashorn.fullversion}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
 236     <echo file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
 237     <echo message="version_short=${nashorn.version}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
 238   </target>
 239 
 240   <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
 241     <jar jarfile="${dynalink.jar}">
 242       <fileset dir="${dynalink.module.classes.dir}"/>
 243     </jar>
 244     <jar jarfile="${nashorn.jar}" index="true" filesetmanifest="merge">
 245       <fileset dir="${nashorn.module.classes.dir}"/>
 246       <manifest>
 247         <attribute name="Archiver-Version" value="n/a"/>
 248         <attribute name="Build-Jdk" value="${java.runtime.version}"/>
 249         <attribute name="Built-By" value="n/a"/>
 250         <attribute name="Created-By" value="Ant jar task"/>
 251         <section name="jdk/nashorn/">
 252           <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
 253           <attribute name="Implementation-Version" value="${nashorn.version}"/>
 254         </section>
 255       </manifest>
 256     </jar>
 257     <jar jarfile="${jjs.jar}">
 258       <fileset dir="${nashorn.shell.module.classes.dir}"/>
 259     </jar>
 260   </target>
 261 
 262   <target name="use-promoted-nashorn" depends="init">
 263     <delete file="${dist.dir}/nashorn.jar"/>
 264     <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
 265     <property name="compile.suppress.jar" value="defined"/>
 266   </target>
 267 
 268   <!-- generate javadoc for Nashorn classes -->
 269   <target name="javadoc" depends="jar">
 270     <javadoc destdir="${dist.javadoc.dir}" use="yes"
 271         windowtitle="${nashorn.product.name} ${nashorn.version}"
 272         additionalparam="-quiet" failonerror="true" useexternalfile="true">
 273       <arg value="--module-source-path"/>
 274       <arg value="${basedir}/src/*/share/classes"/>
 275       <arg value="${javadoc.option}"/>
 276       <classpath>
 277         <pathelement location="${build.classes.dir}"/>
 278       </classpath>
 279       <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
 280       <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/>
 281       <link href="http://docs.oracle.com/javase/8/docs/api/"/>
 282     </javadoc>
 283   </target>
 284 
 285   <!-- generate javadoc only for nashorn extension api classes -->
 286   <target name="nashornapi" depends="jar">
 287     <mkdir dir="${dist.nashornapi.javadoc.dir}"/>
 288     <javadoc destdir="${dist.nashornapi.javadoc.dir}" use="yes"
 289         extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
 290         additionalparam="-quiet" failonerror="true" useexternalfile="true">
 291       <arg value="--module-source-path"/>
 292       <arg value="${basedir}/src/*/share/classes"/>
 293       <arg value="${javadoc.option}"/>
 294       <classpath>
 295         <pathelement location="${build.classes.dir}"/>
 296       </classpath>
 297       <fileset dir="${nashorn.module.src.dir}" includes="jdk/nashorn/api/**/*.java"/>
 298       <link href="http://docs.oracle.com/javase/8/docs/api/"/>
 299     </javadoc>
 300   </target>
 301 
 302   <!-- generate javadoc only for Dynalink API classes -->
 303   <target name="dynalinkapi" depends="jar">
 304     <mkdir dir="${dist.dynalinkapi.javadoc.dir}"/>
 305     <javadoc destdir="${dist.dynalinkapi.javadoc.dir}" use="yes"
 306         windowtitle="Dynalink"
 307         additionalparam="-quiet" failonerror="true" useexternalfile="true">
 308       <arg value="--module-source-path"/>
 309       <arg value="${basedir}/src/*/share/classes"/>
 310       <arg value="${javadoc.option}"/>
 311       <classpath>
 312         <pathelement location="${build.classes.dir}"/>
 313       </classpath>
 314       <fileset dir="${dynalink.module.src.dir}" includes="**/*.java" excludes="jdk/dynalink/internal/*.java"/>
 315       <link href="http://docs.oracle.com/javase/8/docs/api/"/>
 316     </javadoc>
 317   </target>
 318 
 319   <target name="javadocapi" depends="nashornapi, dynalinkapi"/>
 320 
 321   <!-- generate shell.html for shell tool documentation -->
 322   <target name="shelldoc" depends="jar">
 323     <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
 324       <jvmarg line="${nashorn.override.option}"/>
 325       <arg value="-scripting"/>
 326       <arg value="docs/genshelldoc.js"/>
 327     </java>
 328   </target>
 329 
 330   <!-- generate all docs -->
 331   <target name="docs" depends="javadoc, shelldoc"/>
 332 
 333   <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
 334   <target name="dist" depends="jar">
 335       <zip destfile="${build.zip}" basedir=".."
 336           excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
 337       <tar destfile="${build.gzip}" basedir=".." compression="gzip"
 338           excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
 339   </target>
 340 
 341   <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
 342     <!-- testng task -->
 343     <taskdef name="testng" classname="org.testng.TestNGAntTask"
 344         classpath="${testng.ant.classpath}"/>
 345 
 346     <javac srcdir="${test.src.dir}"
 347            destdir="${build.test.classes.dir}"
 348            classpath="${javac.test.classpath}"
 349            source="${javac.source}"
 350            target="${javac.target}"
 351            debug="${javac.debug}"
 352            encoding="${javac.encoding}"
 353            includeantruntime="false" fork="true">
 354         <compilerarg line="${nashorn.override.option}"/>
 355         <compilerarg value="-Xlint:unchecked"/>
 356         <compilerarg value="-Xlint:deprecation"/>
 357         <compilerarg value="-Xdiags:verbose"/>
 358         <compilerarg line="${test.module.imports}"/>
 359     </javac>
 360 
 361     <copy todir="${build.test.classes.dir}/META-INF/services">
 362        <fileset dir="${test.src.dir}/META-INF/services/"/>
 363     </copy>
 364 
 365     <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/test/resources">
 366        <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/test/resources"/>
 367     </copy>
 368 
 369     <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources">
 370       <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources"/>
 371     </copy>
 372 
 373     <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/test/resources">
 374        <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/test/resources"/>
 375     </copy>
 376 
 377     <!-- tests that check nashorn internals and internal API -->
 378     <jar jarfile="${nashorn.internal.tests.jar}">
 379       <fileset dir="${build.test.classes.dir}" includes="**/internal/**"/>
 380       <fileset dir="${build.test.classes.dir}" includes="**/test/tools/**"/>
 381       <fileset dir="${build.test.classes.dir}" includes="**/models/**"/>
 382       <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/test/Trusted**"/>
 383       <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
 384     </jar>
 385 
 386     <!-- tests that check nashorn script engine (jsr-223) API and dynalink API -->
 387     <jar jarfile="${nashorn.api.tests.jar}">
 388       <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/**" excludes="**/jdk/dynalink/test/Trusted**"/>
 389       <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
 390       <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
 391       <fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
 392       <fileset dir="${build.test.classes.dir}" includes="**/UnnamedPackage**"/>
 393     </jar>
 394 
 395   </target>
 396 
 397   <target name="generate-policy-file" depends="prepare">
 398     <echo file="${build.dir}/nashorn.policy">
 399 
 400 grant codeBase "file:/${basedir}/${dynalink.module.classes.dir}" {
 401     permission java.security.AllPermission;
 402 };
 403 
 404 grant codeBase "file:/${basedir}/${nashorn.module.classes.dir}" {
 405     permission java.security.AllPermission;
 406 };
 407 
 408 grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
 409     permission java.security.AllPermission;
 410 };
 411 
 412 grant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" {
 413     permission java.util.PropertyPermission "parserapitest.*", "read";
 414     permission java.util.PropertyPermission "test.*", "read";
 415     permission java.util.PropertyPermission "test262.*", "read";
 416     permission java.io.FilePermission "${basedir}/test/-","read";
 417     permission java.io.FilePermission "$${user.dir}", "read";
 418     permission java.util.PropertyPermission "user.dir", "read";
 419 };
 420 
 421 grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
 422     permission java.security.AllPermission;
 423 };
 424 grant codeBase "file:/${basedir}/${file.reference.jcommander.jar}" {
 425     permission java.security.AllPermission;
 426 };
 427 grant codeBase "file:/${basedir}/${file.reference.bsh.jar}" {
 428     permission java.security.AllPermission;
 429 };
 430 grant codeBase "file:/${basedir}/${file.reference.snakeyaml.jar}" {
 431     permission java.security.AllPermission;
 432 };
 433 //// in case of absolute path:
 434 grant codeBase "file:/${nashorn.internal.tests.jar}" {
 435     permission java.security.AllPermission;
 436 };
 437 
 438 grant codeBase "file:/${file.reference.testng.jar}" {
 439     permission java.security.AllPermission;
 440 };
 441 grant codeBase "file:/${file.reference.jcommander.jar}" {
 442     permission java.security.AllPermission;
 443 };
 444 grant codeBase "file:/${file.reference.bsh.jar}" {
 445     permission java.security.AllPermission;
 446 };
 447 grant codeBase "file:/${file.reference.snakeyaml.jar}" {
 448     permission java.security.AllPermission;
 449 };
 450 
 451 
 452 grant codeBase "file:/${basedir}/test/script/trusted/*" {
 453     permission java.security.AllPermission;
 454 };
 455 
 456 grant codeBase "file:/${basedir}/test/script/maptests/*" {
 457     permission java.io.FilePermission "${basedir}/test/script/maptests/*","read";
 458     permission java.lang.RuntimePermission "nashorn.debugMode";
 459 };
 460 
 461 grant codeBase "file:/${basedir}/test/script/basic/*" {
 462     permission java.io.FilePermission "${basedir}/test/script/-", "read";
 463     permission java.io.FilePermission "$${user.dir}", "read";
 464     permission java.util.PropertyPermission "user.dir", "read";
 465     permission java.util.PropertyPermission "nashorn.test.*", "read";
 466 };
 467 
 468 grant codeBase "file:/${basedir}/test/script/basic/apply_to_call/*" {
 469     permission java.io.FilePermission "${basedir}/test/script/-", "read";
 470     permission java.io.FilePermission "$${user.dir}", "read";
 471     permission java.util.PropertyPermission "user.dir", "read";
 472     permission java.util.PropertyPermission "nashorn.test.*", "read";
 473 };
 474 
 475 grant codeBase "file:/${basedir}/test/script/basic/parser/*" {
 476     permission java.io.FilePermission "${basedir}/test/script/-", "read";
 477     permission java.io.FilePermission "$${user.dir}", "read";
 478     permission java.util.PropertyPermission "user.dir", "read";
 479     permission java.util.PropertyPermission "nashorn.test.*", "read";
 480 };
 481 
 482 grant codeBase "file:/${basedir}/test/script/basic/es6/*" {
 483     permission java.io.FilePermission "${basedir}/test/script/-", "read";
 484     permission java.io.FilePermission "$${user.dir}", "read";
 485     permission java.util.PropertyPermission "user.dir", "read";
 486     permission java.util.PropertyPermission "nashorn.test.*", "read";
 487 };
 488 
 489 grant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
 490     permission java.util.PropertyPermission "java.security.policy", "read";
 491 };
 492 
 493 grant codeBase "file:/${basedir}/test/script/basic/classloader.js" {
 494     permission java.lang.RuntimePermission "nashorn.JavaReflection";
 495 };
 496 
 497 grant codeBase "file:/${basedir}/test/script/markdown.js" {
 498     permission java.io.FilePermission "${basedir}/test/script/external/showdown/-", "read";
 499 };
 500 
 501 grant codeBase "file:/${basedir}/test/script/basic/JDK-8158467.js" {
 502     permission java.lang.RuntimePermission "nashorn.setConfig";
 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/beans/test/*Test.class"/>
 531           <include name="**/dynalink/linker/support/test/*Test.class"/>
 532           <include name="**/dynalink/support/test/*Test.class"/>
 533           <include name="**/dynalink/test/*Test.class"/>
 534           <include name="**/api/javaaccess/test/*Test.class"/>
 535           <include name="**/api/scripting/test/*Test.class"/>
 536           <include name="**/api/tree/test/*Test.class"/>
 537           <include name="**/codegen/test/*Test.class"/>
 538           <include name="**/parser/test/*Test.class"/>
 539           <include name="**/runtime/test/*Test.class"/>
 540           <include name="**/runtime/doubleconv/test/*Test.class"/>
 541           <include name="**/runtime/regexp/test/*Test.class"/>
 542           <include name="**/runtime/regexp/joni/test/*Test.class"/>
 543           <include name="**/framework/*Test.class"/>
 544      </fileset>
 545   </target>
 546 
 547   <!-- only to be invoked as dependency of "test" target -->
 548   <target name="-test-classes-single" depends="jar" if="test.class">
 549      <fileset id="test.classes" dir="${build.test.classes.dir}">
 550          <include name="${test.class}*"/>
 551      </fileset>
 552   </target>
 553 
 554   <!-- only to be invoked as dependency of "test" target -->
 555   <target name="-test-nosecurity" unless="test.class">
 556     <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
 557       <include name="**/framework/ScriptTest.class"/>
 558       <include name="**/runtime/linker/test/*Test.class"/>
 559     </fileset>
 560     <testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
 561        verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
 562       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
 563       <sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
 564       <propertyset>
 565         <propertyref prefix="nashorn."/>
 566       </propertyset>
 567       <propertyset>
 568         <propertyref prefix="test-sys-prop-no-security."/>
 569         <mapper from="test-sys-prop-no-security.*" to="*" type="glob"/>
 570       </propertyset>
 571       <sysproperty key="optimistic.override" value="${optimistic}"/>
 572       <classpath>
 573           <pathelement path="${run.test.classpath}"/>
 574       </classpath>
 575     </testng>
 576   </target>
 577 
 578   <!-- only to be invoked as dependency of "test" target -->
 579   <target name="-test-security">
 580     <delete dir="${build.dir}/nashorn_code_cache"/>
 581     <property name="debug.test.jvmargs" value=""/>
 582     <testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
 583             verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
 584       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
 585       <jvmarg line="${debug.test.jvmargs}"/>
 586       <propertyset>
 587         <propertyref prefix="nashorn."/>
 588       </propertyset>
 589       <propertyset>
 590         <propertyref prefix="test-sys-prop."/>
 591         <mapper from="test-sys-prop.*" to="*" type="glob"/>
 592       </propertyset>
 593       <sysproperty key="optimistic.override" value="${optimistic}"/>
 594       <sysproperty key="test.js.excludes.file" value="${exclude.list}"/>
 595       <classpath>
 596           <pathelement path="${run.test.classpath}"/>
 597       </classpath>
 598     </testng>
 599   </target>
 600 
 601   <target name="test" depends="prepare, javadoc, test-pessimistic, test-optimistic"/>
 602 
 603   <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">
 604     <echo message="Running test suite in OPTIMISTIC mode..."/>
 605     <antcall target="-test-nosecurity" inheritRefs="true">
 606       <param name="optimistic" value="true"/>
 607       <param name="testResultsSubDir" value="optimistic"/>
 608     </antcall>
 609     <antcall target="-test-security" inheritRefs="true">
 610       <param name="optimistic" value="true"/>
 611       <param name="testResultsSubDir" value="optimistic"/>
 612     </antcall>
 613   </target>
 614 
 615   <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">
 616     <echo message="Running test suite in PESSIMISTIC mode..."/>
 617     <antcall target="-test-nosecurity" inheritRefs="true">
 618       <param name="optimistic" value="false"/>
 619       <param name="testResultsSubDir" value="pessimistic"/>
 620     </antcall>
 621     <antcall target="-test-security" inheritRefs="true">
 622       <param name="optimistic" value="false"/>
 623       <param name="testResultsSubDir" value="pessimistic"/>
 624     </antcall>
 625   </target>
 626 
 627   <target name="check-jemmy.jfx.testng" unless="jemmy.jfx.testng.available">
 628     <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."/>
 629   </target>
 630 
 631   <target name="testjfx" depends="jar, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available">
 632     <fileset id="test.classes" dir="${build.test.classes.dir}">
 633        <include name="**/framework/*Test.class"/>
 634     </fileset>
 635 
 636     <copy file="${file.reference.jfxrt.jar}" todir="dist"/>
 637 
 638     <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
 639         <not>
 640             <os family="mac"/>
 641         </not>
 642     </condition>
 643 
 644     <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
 645        verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
 646       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
 647       <propertyset>
 648         <propertyref prefix="testjfx-test-sys-prop."/>
 649         <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
 650       </propertyset>
 651       <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
 652       <classpath>
 653           <pathelement path="${testjfx.run.test.classpath}"/>
 654       </classpath>
 655     </testng>
 656   </target>
 657 
 658   <target name="testmarkdown" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
 659     <fileset id="test.classes" dir="${build.test.classes.dir}">
 660        <include name="**/framework/*Test.class"/>
 661     </fileset>
 662 
 663     <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
 664        verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
 665       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
 666       <propertyset>
 667         <propertyref prefix="testmarkdown-test-sys-prop."/>
 668         <mapper from="testmarkdown-test-sys-prop.*" to="*" type="glob"/>
 669       </propertyset>
 670       <classpath>
 671           <pathelement path="${run.test.classpath}"/>
 672       </classpath>
 673     </testng>
 674   </target>
 675 
 676   <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
 677     <fileset id="test.classes" dir="${build.test.classes.dir}">
 678        <include name="**/framework/*Test.class"/>
 679     </fileset>
 680 
 681     <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
 682        verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
 683       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
 684       <propertyset>
 685         <propertyref prefix="nashorn."/>
 686       </propertyset>
 687       <propertyset>
 688         <propertyref prefix="test262-test-sys-prop."/>
 689         <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
 690       </propertyset>
 691       <classpath>
 692           <pathelement path="${run.test.classpath}"/>
 693       </classpath>
 694     </testng>
 695   </target>
 696 
 697   <target name="test262parallel" depends="test262-parallel"/>
 698 
 699   <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
 700     <!-- use just build.test.classes.dir to avoid referring to TestNG -->
 701     <java classname="${parallel.test.runner}" dir="${basedir}" fork="true" failonerror="true">
 702       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
 703       <!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
 704       <jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
 705       <classpath>
 706           <pathelement path="${run.test.classpath}"/>
 707       </classpath>
 708       <syspropertyset>
 709           <propertyref prefix="test262-test-sys-prop."/>
 710           <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
 711       </syspropertyset>
 712     </java>
 713   </target>
 714 
 715   <target name="testparallel" depends="test-parallel"/>
 716 
 717   <target name="test-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
 718       <!-- use just build.test.classes.dir to avoid referring to TestNG -->
 719       <java classname="${parallel.test.runner}" dir="${basedir}"
 720         failonerror="true"
 721         fork="true">
 722       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
 723       <classpath>
 724           <pathelement path="${run.test.classpath}"/>
 725       <pathelement path="${build.test.classes.dir}"/>
 726       </classpath>
 727       <syspropertyset>
 728           <propertyref prefix="test-sys-prop."/>
 729           <mapper type="glob" from="test-sys-prop.*" to="*"/>
 730       </syspropertyset>
 731       </java>
 732   </target>
 733 
 734   <target name="all" depends="test, docs"
 735       description="Build, test and generate docs for nashorn"/>
 736 
 737   <target name="run" depends="jar"
 738       description="Run the shell with a sample script">
 739     <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
 740         <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
 741         <arg value="-dump-on-error"/>
 742         <arg value="test.js"/>
 743     </java>
 744   </target>
 745 
 746   <target name="debug" depends="jar"
 747       description="Debug the shell with a sample script">
 748     <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
 749         <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
 750         <arg value="--print-code"/>
 751         <arg value="--verify-code"/>
 752         <arg value="--print-symbols"/>
 753         <jvmarg value="-Dnashorn.codegen.debug=true"/>
 754         <arg value="test.js"/>
 755     </java>
 756   </target>
 757 
 758   <!-- targets to get external script tests -->
 759 
 760   <!-- test262 test suite -->
 761   <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
 762     <!-- clone test262 git repo -->
 763     <exec executable="${git.executable}">
 764        <arg value="clone"/>
 765        <arg value="--branch"/>
 766        <arg value="es5-tests"/>
 767        <arg value="https://github.com/tc39/test262"/>
 768        <arg value="${test.external.dir}/test262"/>
 769     </exec>
 770   </target>
 771   <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
 772     <!-- update test262 git repo -->
 773     <exec executable="${git.executable}" dir="${test.external.dir}/test262">
 774        <arg value="pull"/>
 775     </exec>
 776   </target>
 777 
 778   <!-- octane benchmark -->
 779   <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
 780     <!-- checkout octane benchmarks -->
 781     <exec executable="${git.executable}">
 782        <arg value="clone"/>
 783        <arg value="https://github.com/chromium/octane"/>
 784        <arg value="${test.external.dir}/octane"/>
 785     </exec>
 786   </target>
 787   <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
 788     <!-- update octane benchmarks -->
 789     <exec executable="${git.executable}" dir="${test.external.dir}/octane">
 790        <arg value="pull"/>
 791     </exec>
 792   </target>
 793 
 794   <!-- sunspider benchmark -->
 795   <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
 796     <!-- checkout sunspider -->
 797     <exec executable="${svn.executable}">
 798        <arg value="--non-interactive"/>
 799        <arg value="--trust-server-cert"/>
 800        <arg value="checkout"/>
 801        <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
 802        <arg value="${test.external.dir}/sunspider"/>
 803     </exec>
 804   </target>
 805   <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
 806     <!-- update sunspider -->
 807     <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
 808        <arg value="--non-interactive"/>
 809        <arg value="--trust-server-cert"/>
 810        <arg value="update"/>
 811     </exec>
 812   </target>
 813 
 814   <!-- get all external test scripts -->
 815   <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider">
 816     <!-- make external test dir -->
 817     <mkdir dir="${test.external.dir}"/>
 818 
 819     <!-- jquery -->
 820     <mkdir dir="${test.external.dir}/jquery"/>
 821     <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
 822     <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
 823 
 824     <!-- prototype -->
 825     <mkdir dir="${test.external.dir}/prototype"/>
 826     <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"/>
 827 
 828     <!-- underscorejs -->
 829     <mkdir dir="${test.external.dir}/underscore"/>
 830     <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
 831     <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
 832 
 833     <!-- yui -->
 834     <mkdir dir="${test.external.dir}/yui"/>
 835     <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
 836     <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
 837 
 838     <!-- showdown -->
 839     <mkdir dir="${test.external.dir}/showdown"/>
 840     <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
 841     <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
 842 
 843   </target>
 844 
 845   <!-- update external test suites that are pulled from source control systems -->
 846   <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>
 847 
 848   <!-- run all perf tests -->
 849   <target name="perf" depends="externals, update-externals, sunspider, octane"/>
 850 
 851   <!-- download and install testng.jar -->
 852   <target name="get-testng">
 853     <get dest="${test.lib}" skipexisting="true">
 854       <url url="http://central.maven.org/maven2/org/testng/testng/6.8/testng-6.8.jar"/>
 855       <url url="http://central.maven.org/maven2/com/beust/jcommander/1.27/jcommander-1.27.jar"/>
 856       <url url="http://central.maven.org/maven2/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar"/>
 857       <url url="http://central.maven.org/maven2/org/yaml/snakeyaml/1.6/snakeyaml-1.6.jar"/>
 858     </get>
 859   </target>
 860 
 861   <!-- download and install asmtools.jar -->
 862   <target name="get-asmtools" unless="asmtools.already.present">
 863     <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"/>
 864     <untar src="${test.lib}${file.separator}asmtools-6.0.tar.gz" dest="${test.lib}" compression="gzip"/>
 865     <!-- they are tar.gz'ing a .zip file! -->
 866     <unzip src="${test.lib}${file.separator}asmtools-6.0.zip" dest="${test.lib}">
 867       <patternset>
 868         <include name="asmtools-6.0/lib/asmtools.jar"/>
 869       </patternset>
 870     </unzip>
 871     <move file="${test.lib}${file.separator}asmtools-6.0${file.separator}lib${file.separator}asmtools.jar" tofile="${test.lib}${file.separator}asmtools.jar"/>
 872     <delete dir="${test.lib}${file.separator}asmtools-6.0"/>
 873   </target>
 874 
 875   <!-- run all tests -->
 876   <target name="alltests" depends="externals, update-externals, test, test262parallel, testmarkdown, perf"/>
 877 
 878   <import file="build-benchmark.xml"/>
 879 
 880 </project>