make/nashorn/build.xml
author kbarrett
Fri, 25 Jan 2019 00:27:51 -0500
changeset 53482 771b50dd0b08
parent 52804 28094715ae71
permissions -rw-r--r--
8216258: Make FreeIdSet semaphore-based Summary: Use semaphore-based blocking and notifying, instead of Mutex. Reviewed-by: tschatzl, sangheki

<?xml version="1.0" encoding="UTF-8"?>

<!--
 Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

 This code is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License version 2 only, as
 published by the Free Software Foundation.

 This code is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 version 2 for more details (a copy is included in the LICENSE file that
 accompanied this code).

 You should have received a copy of the GNU General Public License version
 2 along with this work; if not, write to the Free Software Foundation,
 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 or visit www.oracle.com if you need additional information or have any
 questions.
-->

<project name="nashorn" default="test" basedir="../..">
  <import file="build-nasgen.xml"/>
  <import file="code_coverage.xml"/>

  <target name="load-properties">
    <!-- set default values to run.test.jvmargs.external property -->
    <condition property="run.test.jvmargs.external" value="">
     <not><isset property="run.test.jvmargs.external"/></not>
    </condition>     
    <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
    <property file="${user.home}/.nashorn.project.local.properties"/>

    <loadproperties srcFile="make/nashorn/project.properties"/>
  </target>

  <target name="init-conditions" depends="load-properties">
    <path id="nashorn.jar.path">
         <pathelement location="${nashorn.jar}"/>
    </path>
    <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
      <available file="/usr/local/bin/svn"/>
    </condition>
    <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
      <available file="/usr/local/bin/hg"/>
    </condition>
    <condition property="git.executable" value="/usr/local/bin/git" else="git">
      <available file="/usr/local/bin/git"/>
    </condition>
    <!-- check if TestNG and dependencies are available, and download them if they aren't -->
    <antcall target="get-testng"/>
    <condition property="testng.available" value="true">
      <and>
        <available file="${file.reference.testng.jar}"/>
        <available file="${file.reference.jcommander.jar}"/>
        <available file="${file.reference.bsh.jar}"/>
        <available file="${file.reference.snakeyaml.jar}"/>
      </and>
    </condition>

    <!-- check if asmtools-6.0.jar is available, and download it if it isn't -->
    <!--
    <available property="asmtools.already.present" file="${file.reference.asmtools.jar}"/>
    <antcall target="get-asmtools"/>
    <available property="asmtools.available" file="${file.reference.asmtools.jar}"/>
    -->

    <!-- check if Jemmy ang TestNG are avaiable -->
    <condition property="jemmy.jfx.testng.available" value="true">
      <and>
        <available file="${file.reference.jemmyfx.jar}"/>
        <available file="${file.reference.jemmycore.jar}"/>
        <available file="${file.reference.jemmyawtinput.jar}"/>
        <available file="${file.reference.jfxrt.jar}"/>
        <isset property="testng.available"/>
      </and>
    </condition>

    <!-- enable/disable make code coverage -->
    <condition property="cc.enabled">
        <istrue value="${make.code.coverage}" />
    </condition>

    <!-- exclude tests in exclude lists -->
    <condition property="exclude.list" value="${nashorn.make.dir}/exclude/exclude_list_cc.txt" else="${nashorn.make.dir}/exclude/exclude_list.txt">
      <istrue value="${make.code.coverage}" />
    </condition>

    <condition property="jfr.options" value="${run.test.jvmargs.jfr}" else="">
      <istrue value="${jfr}"/>
    </condition>

    <condition property="test-sys-prop-no-security.os.not.windows">
      <not>
        <os family="windows"/>
      </not>
    </condition>

    <!--set windows cygwin/cmd specific properties-->
    <property environment="env"/>
    <condition property="test-sys-prop-no-security.os.not.windows.cmd">
     <not>
      <and>
        <os family="windows"/>
        <not>
          <isset property="env.SHELL"/>
        </not>
      </and>
     </not>
    </condition>
   </target>
  

  <!-- check minimum ant version required to be 1.9.5 -->
  <target name="check-ant-version">
    <property name="ant.version.required" value="1.9.5"/>
    <antversion property="ant.current.version" />
    <fail message="The current ant version, ${ant.current.version}, is too old. Please use 1.9.5 or above.">
        <condition>
            <not>
                <antversion atleast="${ant.version.required}"/>
            </not>
        </condition>
    </fail>
  </target>

  <target name="check-java-version">
    <!-- look for a Class that is available only in jdk1.8 or above -->
    <!-- core/exposed API class is better than an implementation class -->
    <available property="jdk1.8+" classname="java.util.stream.Stream"/>

    <!-- need jdk1.8 or above -->
    <fail message="Unsupported Java version: ${ant.java.version}. Please use Java version 1.8 or greater." unless="jdk1.8+">
    </fail>
  </target>

  <target name="init" depends="check-ant-version, check-java-version, init-conditions, init-cc">
    <!-- extends jvm args -->
    <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
    <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs} ${jfr.options}"/>

    <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
    <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
    <echo message="run.test.xms=${run.test.xms}"/>
    <echo message="run.test.xmx=${run.test.xmx}"/>

  </target>

  <target name="prepare" depends="init">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${nashorn.module.classes.dir}"/>
    <mkdir dir="${dynalink.module.classes.dir}"/>
    <mkdir dir="${nashorn.shell.module.classes.dir}"/>
    <mkdir dir="${nashorn.module.classes.dir}/META-INF/services"/>
    <mkdir dir="${build.test.classes.dir}"/>
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.javadoc.dir}"/>
  </target>

  <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
    <delete includeemptydirs="true">
      <fileset dir="${build.dir}" erroronmissingdir="false"/>
    </delete>
    <delete dir="${dist.dir}"/>
    <delete dir="${jdk.build.dir}/nashorn_code_cache"/>
    <delete file="${basedir}/NashornProfile.txt"/>
  </target>

  <target name="compile" depends="prepare" description="Compiles nashorn">
    <javac srcdir="${dynalink.module.src.dir}"
           destdir="${dynalink.module.classes.dir}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
      <compilerarg value="-Xlint:all"/>
      <compilerarg value="-XDignore.symbol.file"/>
      <compilerarg value="-Xdiags:verbose"/>
      <compilerarg value="-parameters"/>
    </javac>
    <!-- patch-module does not like module-info.class files! -->
    <delete>
      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
    </delete>
    <javac srcdir="${nashorn.module.src.dir}"
           destdir="${nashorn.module.classes.dir}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
      <compilerarg value="-Xlint:all"/>
      <compilerarg value="-XDignore.symbol.file"/>
      <compilerarg value="-Xdiags:verbose"/>
      <compilerarg value="-parameters"/>
      <compilerarg line="${nashorn.override.option}"/>
    </javac>
    <!-- patch-module does not like module-info.class files! -->
    <delete>
      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
    </delete>
    <javac srcdir="${nashorn.shell.module.src.dir}"
           destdir="${nashorn.shell.module.classes.dir}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
      <compilerarg value="-Xlint:all"/>
      <compilerarg value="-XDignore.symbol.file"/>
      <compilerarg value="-Xdiags:verbose"/>
      <compilerarg value="-parameters"/>
      <compilerarg line="${nashorn.override.option}"/>
    </javac>
    <!-- patch-module does not like module-info.class files! -->
    <delete>
      <fileset dir="${build.classes.dir}" includes="**/module-info.class"/>
    </delete>
     <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/api/scripting/resources">
       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/api/scripting/resources/"/>
    </copy>
    <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources">
       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/internal/runtime/resources/"/>
    </copy>
    <copy todir="${nashorn.module.classes.dir}/jdk/nashorn/tools/resources">
       <fileset dir="${nashorn.module.src.dir}/jdk/nashorn/tools/resources/"/>
    </copy>
    <copy file="${dynalink.module.src.dir}/jdk/dynalink/support/messages.properties" todir="${dynalink.module.classes.dir}/jdk/dynalink/support"/>
    <copy file="${nashorn.module.src.dir}/jdk/nashorn/internal/codegen/anchor.properties" todir="${nashorn.module.classes.dir}/jdk/nashorn/internal/codegen"/>
    <copy todir="${nashorn.shell.module.classes.dir}/jdk/nashorn/tools/jjs/resources">
       <fileset dir="${nashorn.shell.module.src.dir}/jdk/nashorn/tools/jjs/resources/"/>
    </copy>

    <echo message="version_string=${nashorn.fullversion}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
    <echo file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
    <echo message="version_short=${nashorn.version}" file="${nashorn.module.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
  </target>

  <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
    <jar jarfile="${dynalink.jar}">
      <fileset dir="${dynalink.module.classes.dir}"/>
    </jar>
    <jar jarfile="${nashorn.jar}" index="true" filesetmanifest="merge">
      <fileset dir="${nashorn.module.classes.dir}"/>
      <manifest>
        <attribute name="Archiver-Version" value="n/a"/>
        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
        <attribute name="Built-By" value="n/a"/>
        <attribute name="Created-By" value="Ant jar task"/>
        <section name="jdk/nashorn/">
          <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
          <attribute name="Implementation-Version" value="${nashorn.version}"/>
        </section>
      </manifest>
    </jar>
    <jar jarfile="${jjs.jar}">
      <fileset dir="${nashorn.shell.module.classes.dir}"/>
    </jar>
  </target>

  <target name="use-promoted-nashorn" depends="init">
    <delete file="${dist.dir}/nashorn.jar"/>
    <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
    <property name="compile.suppress.jar" value="defined"/>
  </target>

  <!-- generate javadoc for Nashorn classes -->
  <target name="javadoc" depends="jar" unless="test.class">
    <javadoc destdir="${dist.javadoc.dir}" use="yes"
        windowtitle="${nashorn.product.name} ${nashorn.version}"
        additionalparam="-quiet" failonerror="true" useexternalfile="true"> 
      <arg value="--patch-module"/>
      <arg value="jdk.scripting.nashorn=${basedir}/${nashorn.module.src.dir}"/>
      <arg value="--patch-module"/>
      <arg value="jdk.dynalink=${basedir}/${dynalink.module.src.dir}"/>
      <arg value="--module-source-path"/>
      <arg value="."/>
      <arg value="${javadoc.option}"/>
      <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/>
      <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.element.list}"/>
    </javadoc>
  </target>

  <!-- generate javadoc only for nashorn extension api classes -->
  <target name="nashornapi" depends="jar">
    <mkdir dir="${dist.nashornapi.javadoc.dir}"/>
    <javadoc destdir="${dist.nashornapi.javadoc.dir}" use="yes"
        windowtitle="${nashorn.product.name} ${nashorn.version}"
        additionalparam="-quiet" failonerror="true" useexternalfile="true">
      <arg value="--patch-module"/>
      <arg value="jdk.scripting.nashorn=${basedir}/${nashorn.module.src.dir}"/>
      <arg value="--patch-module"/>
      <arg value="jdk.dynalink=${basedir}/${dynalink.module.src.dir}"/>
      <arg value="--module-source-path"/>
      <arg value="."/>
      <arg value="${javadoc.option}"/>
      <fileset dir="${nashorn.module.src.dir}" includes="jdk/nashorn/api/**/*.java"/>
      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.element.list}"/>
    </javadoc>
  </target>

  <!-- generate javadoc only for Dynalink API classes -->
  <target name="dynalinkapi" depends="jar">
    <mkdir dir="${dist.dynalinkapi.javadoc.dir}"/>
    <javadoc destdir="${dist.dynalinkapi.javadoc.dir}" use="yes"
        windowtitle="Dynalink"
        additionalparam="-quiet" failonerror="true" useexternalfile="true">
      <arg value="--patch-module"/>
      <arg value="jdk.scripting.nashorn=${basedir}/${nashorn.module.src.dir}"/>
      <arg value="--patch-module"/>
      <arg value="jdk.dynalink=${basedir}/${dynalink.module.src.dir}"/>
      <arg value="--module-source-path"/>
      <arg value="."/>
      <arg value="${javadoc.option}"/>
      <fileset dir="${dynalink.module.src.dir}" includes="**/*.java"/>
      <link offline="true" href="${javadoc.base.url}" packagelistLoc="${javadoc.element.list}"/>
    </javadoc>
  </target>

  <target name="javadocapi" depends="nashornapi, dynalinkapi"/>

  <!-- generate all docs -->
  <target name="docs" depends="javadoc"/>

  <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
  <target name="dist" depends="jar">
      <zip destfile="${build.zip}" basedir=".."
          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
      <tar destfile="${build.gzip}" basedir=".." compression="gzip"
          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
  </target>

  <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
    <!-- testng task -->
    <taskdef name="testng" classname="org.testng.TestNGAntTask"
        classpath="${testng.ant.classpath}"/>

    <javac srcdir="${test.src.dir}"
           destdir="${build.test.classes.dir}"
           classpath="${javac.test.classpath}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
        <compilerarg line="${nashorn.override.option}"/>
        <compilerarg value="-Xlint:unchecked"/>
        <compilerarg value="-Xlint:deprecation"/>
        <compilerarg value="-Xdiags:verbose"/>
        <compilerarg line="${test.module.imports.compile.time}"/>
    </javac>

    <copy todir="${build.test.classes.dir}/META-INF/services">
       <fileset dir="${test.src.dir}/META-INF/services/"/>
    </copy>

    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/test/resources">
       <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/test/resources"/>
    </copy>

    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources">
      <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/doubleconv/test/resources"/>
    </copy>

    <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/test/resources">
       <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/test/resources"/>
    </copy>

    <!-- tests that check nashorn internals and internal API -->
    <jar jarfile="${nashorn.internal.tests.jar}">
      <fileset dir="${build.test.classes.dir}" includes="**/internal/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/test/tools/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/models/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/test/Trusted**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
    </jar>

    <!-- tests that check nashorn script engine (jsr-223) API and dynalink API -->
    <jar jarfile="${nashorn.api.tests.jar}">
      <fileset dir="${build.test.classes.dir}" includes="**/jdk/dynalink/**" excludes="**/jdk/dynalink/test/Trusted**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
      <fileset dir="${build.test.classes.dir}" includes="**/UnnamedPackage**"/>
    </jar>

  </target>

  <target name="generate-security-config" depends="generate-policy-file, generate-security-properties-file"/>

  <target name="generate-security-properties-file" depends="prepare">
    <echo file="${build.dir}/nashorn.security.properties">

package.access=sun.misc.,\
    sun.reflect.,\
    jdk.nashorn.internal.

    </echo>
  </target>

  <target name="generate-policy-file" depends="prepare">
    <echo file="${build.dir}/nashorn.policy">

grant codeBase "file:/${basedir}/${dynalink.module.classes.dir}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${nashorn.module.classes.dir}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" {
    permission java.util.PropertyPermission "parserapitest.*", "read";
    permission java.util.PropertyPermission "test.*", "read";
    permission java.util.PropertyPermission "test262.*", "read";
    permission java.io.FilePermission "${basedir}/test/nashorn/-","read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
};

grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${basedir}/${file.reference.jcommander.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${basedir}/${file.reference.bsh.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${basedir}/${file.reference.snakeyaml.jar}" {
    permission java.security.AllPermission;
};
//// in case of absolute path:
grant codeBase "file:/${nashorn.internal.tests.jar}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${file.reference.testng.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${file.reference.jcommander.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${file.reference.bsh.jar}" {
    permission java.security.AllPermission;
};
grant codeBase "file:/${file.reference.snakeyaml.jar}" {
    permission java.security.AllPermission;
};


grant codeBase "file:/${basedir}/${test.script.dir}/trusted/*" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${test.script.dir}/maptests/*" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/maptests/*","read";
    permission java.lang.RuntimePermission "nashorn.debugMode";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/*" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/apply_to_call/*" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/parser/*" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/es6/*" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/JDK-8010946-privileged.js" {
    permission java.util.PropertyPermission "java.security.policy", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/classloader.js" {
    permission java.lang.RuntimePermission "nashorn.JavaReflection";
};

grant codeBase "file:/${basedir}/${test.script.dir}/markdown.js" {
    permission java.io.FilePermission "${basedir}/${test.script.dir}/external/showdown/-", "read";
};

grant codeBase "file:/${basedir}/${test.script.dir}/basic/JDK-8158467.js" {
    permission java.lang.RuntimePermission "nashorn.setConfig";
};

    </echo>

    <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace>    <!--hack for Windows - to make URLs with normal path separators -->
    <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace>   <!--hack for Unix - to avoid leading // in URLs -->

  </target>

  <target name="check-external-tests">
      <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
      <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
      <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
      <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
      <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
      <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
      <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
      <available file="${test.external.dir}/showdown" property="test-sys-prop.external.markdown"/>
  </target>

  <target name="check-testng" unless="testng.available">
    <echo message="WARNING: TestNG not available, will not run tests. Please copy TestNG and dependency JARs to the ${test.lib} directory."/>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-classes-all" depends="jar" unless="test.class">
      <fileset id="test.classes" dir="${build.test.classes.dir}">
          <include name="**/dynalink/beans/test/*Test.class"/>
          <include name="**/dynalink/linker/support/test/*Test.class"/>
          <include name="**/dynalink/support/test/*Test.class"/>
          <include name="**/dynalink/test/*Test.class"/>
          <include name="**/api/javaaccess/test/*Test.class"/>
          <include name="**/api/scripting/test/*Test.class"/>
          <include name="**/api/tree/test/*Test.class"/>
          <include name="**/codegen/test/*Test.class"/>
          <include name="**/parser/test/*Test.class"/>
          <include name="**/runtime/test/*Test.class"/>
          <include name="**/runtime/doubleconv/test/*Test.class"/>
          <include name="**/runtime/regexp/test/*Test.class"/>
          <include name="**/runtime/regexp/joni/test/*Test.class"/>
          <include name="**/framework/*Test.class"/>
     </fileset>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-classes-single" depends="jar" if="test.class">
     <fileset id="test.classes" dir="${build.test.classes.dir}">
         <include name="${test.class}*"/>
     </fileset>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-nosecurity" unless="test.class">
    <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
      <include name="**/framework/ScriptTest.class"/>
      <include name="**/runtime/linker/test/*Test.class"/>
    </fileset>
    <testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
      <sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test-sys-prop-no-security."/>
        <mapper from="test-sys-prop-no-security.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="optimistic.override" value="${optimistic}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-security">
    <delete dir="${build.dir}/nashorn_code_cache"/>
    <property name="debug.test.jvmargs" value=""/>
    <testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
            verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <jvmarg line="${debug.test.jvmargs}"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test-sys-prop."/>
        <mapper from="test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="optimistic.override" value="${optimistic}"/>
      <sysproperty key="test.js.excludes.file" value="${exclude.list}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test" depends="prepare, javadoc, test-pessimistic, test-optimistic"/>

  <target name="test-optimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
    <echo message="Running test suite in OPTIMISTIC mode..."/>
    <antcall target="-test-nosecurity" inheritRefs="true">
      <param name="optimistic" value="true"/>
      <param name="testResultsSubDir" value="optimistic"/>
    </antcall>
    <antcall target="-test-security" inheritRefs="true">
      <param name="optimistic" value="true"/>
      <param name="testResultsSubDir" value="optimistic"/>
    </antcall>
  </target>

  <target name="test-pessimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
    <echo message="Running test suite in PESSIMISTIC mode..."/>
    <antcall target="-test-nosecurity" inheritRefs="true">
      <param name="optimistic" value="false"/>
      <param name="testResultsSubDir" value="pessimistic"/>
    </antcall>
    <antcall target="-test-security" inheritRefs="true">
      <param name="optimistic" value="false"/>
      <param name="testResultsSubDir" value="pessimistic"/>
    </antcall>
  </target>

  <target name="check-jemmy.jfx.testng" unless="jemmy.jfx.testng.available">
    <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."/>
  </target>

  <target name="testjfx" depends="jar, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <copy file="${file.reference.jfxrt.jar}" todir="dist"/>

    <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
        <not>
            <os family="mac"/>
        </not>
    </condition>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="testjfx-test-sys-prop."/>
        <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
      <classpath>
          <pathelement path="${testjfx.run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="testmarkdown" depends="jar, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="testmarkdown-test-sys-prop."/>
        <mapper from="testmarkdown-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test262-test-sys-prop."/>
        <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test262parallel" depends="test262-parallel"/>

  <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
    <java classname="${parallel.test.runner}" dir="${basedir}" fork="true" failonerror="true">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
      <jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
      <syspropertyset>
          <propertyref prefix="test262-test-sys-prop."/>
          <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
      </syspropertyset>
    </java>
  </target>

  <target name="testparallel" depends="test-parallel"/>

  <target name="test-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-security-config" if="testng.available">
      <!-- use just build.test.classes.dir to avoid referring to TestNG -->
      <java classname="${parallel.test.runner}" dir="${basedir}"
        failonerror="true"
        fork="true">
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      <pathelement path="${build.test.classes.dir}"/>
      </classpath>
      <syspropertyset>
          <propertyref prefix="test-sys-prop."/>
          <mapper type="glob" from="test-sys-prop.*" to="*"/>
      </syspropertyset>
      </java>
  </target>

  <target name="all" depends="test, docs"
      description="Build, test and generate docs for nashorn"/>

  <target name="run" depends="jar"
      description="Run the shell with a sample script">
    <java classname="${nashorn.shell.tool}" fork="true" dir="${basedir}/src/sample/nashorn">
        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
        <arg value="-dump-on-error"/>
        <arg value="test.js"/>
    </java>
  </target>

  <target name="debug" depends="jar"
      description="Debug the shell with a sample script">
    <java classname="${nashorn.shell.tool}" fork="true" dir="${basedir}/src/sample/nashorn">
        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
        <arg value="--print-code"/>
        <arg value="--verify-code"/>
        <arg value="--print-symbols"/>
        <jvmarg value="-Dnashorn.codegen.debug=true"/>
        <arg value="test.js"/>
    </java>
  </target>

  <!-- targets to get external script tests -->

  <!-- test262 test suite -->
  <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
    <!-- clone test262 git repo -->
    <exec executable="${git.executable}">
       <arg value="clone"/>
       <arg value="--branch"/>
       <arg value="es5-tests"/>
       <arg value="https://github.com/tc39/test262"/>
       <arg value="${test.external.dir}/test262"/>
    </exec>
  </target>
  <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
    <!-- update test262 git repo -->
    <exec executable="${git.executable}" dir="${test.external.dir}/test262">
       <arg value="pull"/>
    </exec>
  </target>

  <!-- octane benchmark -->
  <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
    <!-- checkout octane benchmarks -->
    <exec executable="${git.executable}">
       <arg value="clone"/>
       <arg value="https://github.com/chromium/octane"/>
       <arg value="${test.external.dir}/octane"/>
    </exec>
  </target>
  <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
    <!-- update octane benchmarks -->
    <exec executable="${git.executable}" dir="${test.external.dir}/octane">
       <arg value="pull"/>
    </exec>
  </target>

  <!-- sunspider benchmark -->
  <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
    <!-- checkout sunspider -->
    <exec executable="${svn.executable}">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="checkout"/>
       <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
       <arg value="${test.external.dir}/sunspider"/>
    </exec>
  </target>
  <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
    <!-- update sunspider -->
    <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="update"/>
    </exec>
  </target>

  <!-- get all external test scripts -->
  <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider">
    <!-- make external test dir -->
    <mkdir dir="${test.external.dir}"/>

    <!-- jquery -->
    <mkdir dir="${test.external.dir}/jquery"/>
    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
    <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>

    <!-- prototype -->
    <mkdir dir="${test.external.dir}/prototype"/>
    <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"/>

    <!-- underscorejs -->
    <mkdir dir="${test.external.dir}/underscore"/>
    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>
    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>

    <!-- yui -->
    <mkdir dir="${test.external.dir}/yui"/>
    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>
    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true" tryGzipEncoding="true"/>

    <!-- showdown -->
    <mkdir dir="${test.external.dir}/showdown"/>
    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
    <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>

  </target>

  <!-- update external test suites that are pulled from source control systems -->
  <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>

  <!-- run all perf tests -->
  <target name="perf" depends="externals, update-externals, sunspider, octane"/>

  <!-- download and install testng.jar -->
  <target name="get-testng">
    <get dest="${test.lib}" skipexisting="true">
      <url url="http://central.maven.org/maven2/org/testng/testng/6.8/testng-6.8.jar"/>
      <url url="http://central.maven.org/maven2/com/beust/jcommander/1.27/jcommander-1.27.jar"/>
      <url url="http://central.maven.org/maven2/org/beanshell/bsh/2.0b4/bsh-2.0b4.jar"/>
      <url url="http://central.maven.org/maven2/org/yaml/snakeyaml/1.6/snakeyaml-1.6.jar"/>
    </get>
  </target>

  <!-- download and install asmtools.jar -->
  <target name="get-asmtools" unless="asmtools.already.present">
    <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"/>
    <untar src="${test.lib}${file.separator}asmtools-6.0.tar.gz" dest="${test.lib}" compression="gzip"/>
    <!-- they are tar.gz'ing a .zip file! -->
    <unzip src="${test.lib}${file.separator}asmtools-6.0.zip" dest="${test.lib}">
      <patternset>
        <include name="asmtools-6.0/lib/asmtools.jar"/>
      </patternset>
    </unzip>
    <move file="${test.lib}${file.separator}asmtools-6.0${file.separator}lib${file.separator}asmtools.jar" tofile="${test.lib}${file.separator}asmtools.jar"/>
    <delete dir="${test.lib}${file.separator}asmtools-6.0"/>
  </target>

  <!-- run all tests -->
  <target name="alltests" depends="externals, update-externals, test, test262parallel, testmarkdown, perf"/>

  <import file="build-benchmark.xml"/>

</project>