<?xml version='1.0' encoding='ISO-8859-1' ?>
<!--
  Copyright (c) 2006, 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.  Oracle designates this
  particular file as subject to the "Classpath" exception as provided
  by Oracle in the LICENSE file that accompanied this code.

  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="jtharness" default="build" basedir=".."
         xmlns:if="ant:if"
         xmlns:unless="ant:unless"
         xmlns:ivy="antlib:org.apache.ivy.ant">

    <import file="build-i18ncheck.xml"/>
    <import file="check-dependencies.xml"/>

    <property file="build/local.properties"/>
    <property file="build/build.properties"/>

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

    <property environment="env"/>

    <patternset id="helpset">
        <include name="**/*.hs"/>
        <include name="**/default/**"/>
        <include name="**/images/**"/>
        <exclude name="com/sun/javatest/tool/images/spl_*.gif"/>
    </patternset>

    <target name="build" depends="jar"/>

    <target name="clean" description="Removes the entire build-distribution directory.">
        <delete dir="${BUILD_DIR}"/>
    </target>

    <target name="stamp" description="Set up build time properties.">
        <tstamp>
            <format property="build.date" pattern="MMMMM dd, yyyy" locale="en"/>
            <format property="build.date.time" pattern="MMMMM dd, yyyy hh:mm aa" locale="en"/>
        </tstamp>

    </target>

    <!-- yet if it's been already defined externally it won't be redefined -->
    <property name="jdk.builder.home" value="${env.JAVA_HOME}"/>

    <exec executable="${jdk.builder.home}/bin/java" outputproperty="jdk.builder.version">
        <arg value="-version"/>
        <redirector>
            <outputfilterchain>
                <headfilter lines="1"/>
            </outputfilterchain>
        </redirector>
    </exec>

    <presetdef name="buildinfo">
        <echo file="${build.classes}/META-INF/buildInfo.txt"># Build info
date=${build.date}
version=${build.version}
milestone=${build.milestone}
build=${build.number}
commit=${BUILT_FROM_COMMIT}
java=${jdk.builder.version}
bundle-type=Classpath Loader
harness-variety=Full Bundle
</echo>
    </presetdef>

    <!-- ********** JT Harness *********************************************** -->

    <property name="src.javatest.help" location="${src.dir}/com/sun/javatest/help"/>
    <property name="src.javatestAgent.help" location="${src.dir}/com/sun/javatest/agent/help"/>
    <!--
    <property name="src.javatest.help" location="${doc.dir}/javatest/help"/>
    <property name="src.javatestAgent.help" location="${doc.dir}/javatest/agent/help"/>
    -->
    <property name="build.javatest.help" location="${build.classes}/com/sun/javatest/help"/>
    <property name="build.javatestAgent.help" location="${build.classes}/com/sun/javatest/agent/help"/>

    <patternset id="interview.resources">
        <include name="com/sun/interview/**/*.properties"/>
        <include name="com/sun/interview/wizard/*.gif"/>
        <include name="com/sun/interview/wizard/selectiontree/resources/*.gif"/>
    </patternset>

    <patternset id="javatest.resources">
        <include name="com/sun/javatest/**/*.properties"/>
        <include name="com/sun/javatest/**/*.xsd"/>
        <include name="com/sun/javatest/**/*.gif"/>
        <include name="com/sun/javatest/**/*.css"/>
        <exclude name="com/sun/javatest/tool/images/spl_*.gif"/>
    </patternset>

    <patternset id="javatest.junit.resources">
        <include name="com/sun/javatest/junit/**/*.properties"/>
    </patternset>

    <!-- set of packages which classes to be included in the built jar file  -->
    <patternset id="javatest.packages.jar">
        <include name="com/sun/interview/**"/>
        <include name="com/sun/javatest/**"/>
        <exclude name="com/sun/javatest/junit/**"/>
        <exclude name="com/sun/javatest/agent/SerialPort*.java" unless="jcomm.present"/>
        <exclude name="com/sun/javatest/servlets/*.java" unless="servlet.present"/>
    </patternset>

    <patternset id="javatest.packages.all">
        <patternset refid="javatest.packages.jar"/>
        <!-- needed for running a complete set of unit tests but not to be packed in javatest.jar -->
        <include name="com/sun/tck/**"/>
        <include name="com/oracle/**"/>
    </patternset>

        <patternset id="test.packages">
                <include name="com/sun/jct/utils/copyrightcheck/**" />
        </patternset>

    <patternset id="javatest.jdk11.files">
        <include name="com/sun/javatest/Command.java"/>
        <include name="com/sun/javatest/JavaTestSecurityManager.java"/>
        <include name="com/sun/javatest/ProductInfo.java"/>
        <include name="com/sun/javatest/Test.java"/>
        <include name="com/sun/javatest/Status.java "/>
        <include name="com/sun/javatest/tool/Main.java "/>
        <include name="com/sun/javatest/agent/*.java"/>
        <exclude name="com/sun/javatest/agent/AgentClassLoader2.java"/>
        <exclude name="com/sun/javatest/agent/AgentMonitorCommandManager.java"/>
        <exclude name="com/sun/javatest/agent/AgentMonitorBatchCommandManager.java"/>
        <exclude name="com/sun/javatest/agent/AgentMonitorTool.java"/>
        <exclude name="com/sun/javatest/agent/AgentMonitorToolManager.java"/>
        <include name="com/sun/javatest/util/*.java"/>
        <include name="com/sun/javatest/util/FileInfoCache.java"/>
        <include name="com/sun/javatest/util/ReadAheadIterator.java"/>
    </patternset>

    <patternset id="javatest.junit.packages">
        <include name="com/sun/javatest/junit/**"/>
    </patternset>

    <target name="dist" depends="jar,jar.junit,dist.doc,build-examples,lite,test-copyrights" description="Creates the build-distribution.">
        <property name="zip.prefix" value="jtharness-${build.version}"/>
        <property name="zip.root" location="${BUILD_DIR}/tmp/zip/${zip.prefix}"/>

        <mkdir dir="${zip.root}"/>
        <copy todir="${zip.root}">
            <fileset dir="${BUILD_DIR}/binaries"/>
        </copy>

        <mkdir dir="${BUILD_DIR}/bundles"/>
        <zip destfile="${BUILD_DIR}/bundles/${zip.prefix}.zip" filesOnly="true"
             basedir="${zip.root}/.." excludes="${zip.prefix}/examples/*, ${zip.prefix}/examples/"/>
        <zip destfile="${BUILD_DIR}/bundles/${zip.prefix}-examples.zip" filesOnly="true"
             basedir="${zip.root}/.."
             includes="${zip.prefix}/examples, ${zip.prefix}/examples/**, ${zip.prefix}/legal/*,
                       ${zip.prefix}/ReleaseNotes-jtharness.html"
             excludes="${zip.prefix}/examples/**/*.jar"/>
    </target>

    <target name="dist.doc" depends="javadoc">
        <property name="target.legal.dir" value="${BUILD_DIR}/binaries/legal"/>
        <mkdir dir="${target.legal.dir}"/>
        <copy todir="${target.legal.dir}">
            <fileset dir="${legal.dir}"/>
        </copy>
        <copy file="LICENSE" todir="${BUILD_DIR}/binaries"/>

        <property name="target.doc.dir" value="${BUILD_DIR}/binaries/doc"/>
        <mkdir dir="${target.doc.dir}"/>
        <copy todir="${target.doc.dir}">
            <fileset dir="${doc.dir}">
                <include name="classDepLists/**"/>
            </fileset>
        </copy>

        <property name="target.docshare.dir" value="${BUILD_DIR}/binaries/doc/shared"/>
        <mkdir dir="${target.doc.dir}/shared"/>
        <copy todir="${target.doc.dir}/shared">
            <fileset dir="${doc.dir}/deliverables/shared"/>
        </copy>

        <property name="target.javadoc.dir" value="${target.doc.dir}/api"/>
        <mkdir dir="${target.javadoc.dir}"/>
        <copy todir="${target.javadoc.dir}">
            <fileset dir="${javadoc.dir}"/>
        </copy>

        <!-- API docs -->
        <property name="target.javadoc.dir" value="${target.doc.dir}/api"/>
        <mkdir dir="${target.javadoc.dir}"/>
        <copy todir="${target.javadoc.dir}">
            <fileset dir="${javadoc.dir}"/>
        </copy>

        <!-- copy to top of binary -->
        <copy todir="${BUILD_DIR}/binaries/">
            <fileset dir="${doc.dir}/deliverables">
                <include name="ReleaseNotes-jtharness.html"/>
            </fileset>
        </copy>

        <replace file="${BUILD_DIR}/binaries/ReleaseNotes-jtharness.html">
           <replacetoken><![CDATA[href="../../legal/copyright.txt"]]></replacetoken>
           <replacevalue><![CDATA[href="legal/copyright.txt"]]></replacevalue>
        </replace>

        <replace file="${BUILD_DIR}/binaries/ReleaseNotes-jtharness.html">
           <replacetoken><![CDATA[href="../../document.css"]]></replacetoken>
           <replacevalue><![CDATA[href="doc/document.css"]]></replacevalue>
        </replace>

        <replace file="${BUILD_DIR}/binaries/ReleaseNotes-jtharness.html"
                token="BUILD_VERSION"
                value="${build.version}"/>

    <replace file="${BUILD_DIR}/binaries/ReleaseNotes-jtharness.html"
             token="BUILD_DATE"
             value="${build.date}"/>

        <!-- clone release notes as index.html for convenience -->
        <copy tofile="${BUILD_DIR}/binaries/index.html"
              file="${BUILD_DIR}/binaries/ReleaseNotes-jtharness.html"/>

        <!-- copy to doc/ directory -->
        <copy todir="${BUILD_DIR}/binaries/doc">
            <fileset dir="${doc.dir}/deliverables">
                <include name="junit.html"/>
                <include name="document.css"/>
            </fileset>
        </copy>


    </target>

    <!-- JAR Section -->

    <target name="jar" depends="jar.check,stamp, generate.release.file" unless="javatest.jar.ok" description="Build JAR.">
        <mkdir dir="${BUILD_DIR}/binaries/lib"/>
        <jar destfile="${BUILD_DIR}/binaries/lib/javatest.jar" basedir="${build.classes}" index="false">
            <manifest>
                <attribute name="Built-By"   value="${user.name}"/>
                <attribute name="Main-Class" value="${run.class}"/>
            </manifest>
            <include name="META-INF/buildInfo.txt"/>
            <include name="copyright.txt"/>
            <include name="META-INF/services/com.sun.javatest.tool.*.lst"/>
            <include name="META-INF/services/com.sun.javatest.report.ReportFormat"/>
            <patternset refid="javatest.packages.jar"/>
        </jar>
    </target>

    <target name="generate.release.file">
        <tstamp>
            <format property="BUILD_DATE" pattern="MMM dd, YYYY" locale="en,GB"/>
        </tstamp>
        <condition property="GIT_INFO_AVAILABLE">
            <and>
                <available file="git" type="file" filepath="${env.PATH}"/>
                <available file=".git" type="dir" filepath="${basedir}"/>
            </and>
          </condition>
        <exec if:set="GIT_INFO_AVAILABLE" executable="git"
              failonerror="true"
              failifexecutionfails="true"
              outputproperty="BUILT_FROM_COMMIT">
            <arg line="--git-dir=${basedir}/.git log -1 --format=%h"/>
        </exec>
        <echo unless:set="GIT_INFO_AVAILABLE">Warning: the latest git commit ID could not be determined</echo>
        <echo file="${BUILD_DIR}/binaries/release">JTHARNESS_VERSION=${build.version} ${build.number}${line.separator}</echo>
        <echo append="true" file="${BUILD_DIR}/binaries/release">BUILD_DATE=${BUILD_DATE}${line.separator}</echo>
        <echo if:set="BUILT_FROM_COMMIT" append="true" file="${BUILD_DIR}/binaries/release">SOURCE=jtharness:${BUILT_FROM_COMMIT}${line.separator}</echo>

        <loadfile property="release.file.content" srcfile="${BUILD_DIR}/binaries/release"/>
        <echo>generated ${BUILD_DIR}/binaries/release file:</echo>
        <echo>=================================================================</echo>
        <echo>${release.file.content}</echo>
    </target>

    <target name="jar.check" depends="compile">
        <dependset>
            <srcfileset dir="${build.classes}">
                <include name="META-INF/services/com.sun.javatest.tool.*.lst"/>
                <include name="META-INF/services/com.sun.javatest.report.ReportFormat"/>
                <patternset refid="javatest.packages.jar"/>
            </srcfileset>
            <targetfilelist dir="${BUILD_DIR}/binaries/lib" files="javatest.jar"/>
        </dependset>
        <available property="javatest.jar.ok" file="${BUILD_DIR}/binaries/lib/javatest.jar"/>
    </target>

    <!-- JAR - JUnit Support Section -->

    <target name="jar.junit" depends="jar.junit.check,stamp" if="jar.junit.dependencies.present" unless="jt-junit.jar.ok" description="Build JUnit JAR.">
        <mkdir dir="${BUILD_DIR}/binaries/lib"/>
        <jar destfile="${BUILD_DIR}/binaries/lib/jt-junit.jar" basedir="${build.junit.classes}" index="false">
            <manifest>
                <attribute name="Built-By"   value="${user.name}"/>
            </manifest>
            <include name="META-INF/buildInfo.txt"/>
            <include name="copyright.txt"/>
            <patternset refid="javatest.junit.packages"/>
        </jar>
    </target>

    <target name="jar.junit.check" if="jar.junit.dependencies.present" depends="compile.junit.classes">
        <dependset>
            <srcfileset dir="${build.junit.classes}">
                <patternset refid="javatest.junit.packages"/>
            </srcfileset>
            <targetfilelist dir="${BUILD_DIR}/binaries/lib" files="jt-junit.jar"/>
        </dependset>
        <available property="jt-junit.jar.ok" file="${BUILD_DIR}/binaries/lib/jt-junit.jar"/>
    </target>

    <!-- Compilation Section -->

    <target name="compile" depends="verify-dependencies, compile.classes,compile.resources,compile-javatest.help" description="Compile project."/>

    <target name="compile.classes">
        <echo>=================================================================</echo>
        <echo>jdk.builder.home set to ${jdk.builder.home}</echo>
        <echo>=================================================================</echo>
        <echo>Using ant.version=${ant.version}</echo>
        <echo>Using ant.home=${ant.home}</echo>
        <echo>Using ant.java.version=${ant.java.version}</echo>
        <echo>Using java.home=${java.home}</echo>
        <echo>=================================================================</echo>

        <depend srcdir="${src.dir}" destdir="${build.classes}"/>
        <mkdir dir="${build.classes}"/>
        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${src.dir}"
               sourcepath=""
               destdir="${build.classes}"
               classpath="${jdk14.classpath}:${jcommjar}">
            <patternset refid="javatest.packages.all"/>
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
        </javac>
        <copy todir="${build.classes}">
            <fileset dir="${legal.dir}">
                <include name="copyright.txt"/>
            </fileset>
        </copy>

    </target>

    <target name="compile.unit-tests" depends="compile.classes, setup-test-deps">
        <delete dir="${build.unit-tests}" quiet="true"/>
        <mkdir dir="${build.unit-tests}"/>
        <javac debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${unit-tests.src.dir}:${unit-tests.src-support.dir}"
               destdir="${build.unit-tests}">
            <classpath location="${build.classes}"/>
            <classpath refid="test-deps.classpath"/>
            <compilerarg value="-Xlint:all"/>
        </javac>
    </target>

    <!-- Using Apache Ivy to resolve and retrieve dependencies used by regression tests -->
    <target name="setup-test-deps">
        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivylib}"/>
        <ivy:resolve file="build/ivy.xml"/>
        <ivy:retrieve/>
        <ivy:cachepath pathid="test-deps.classpath"/>
    </target>

    <target name="compile.test.copyright.classes">
        <mkdir dir="${build.classes}"/>
        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${test.dir}"
               destdir="${build.classes}"
               classpath="${jdk14.classpath}">
            <patternset refid="test.packages"/>
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
                </javac>
        </target>

    <target name="compile.junit.classes" if="jar.junit.dependencies.present" depends="verify-dependencies, compile.classes,compile.junit.resources">
        <mkdir dir="${build.junit.classes}"/>
        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${src.dir}"
               destdir="${build.junit.classes}"
               classpath="${jdk14.classpath}:${build.classes}:${asmjar}:${asmcommonsjar}:${junitlib}">
            <patternset refid="javatest.junit.packages"/>
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
        </javac>

        <copy todir="${build.junit.classes}">
            <fileset dir="${legal.dir}">
                <include name="copyright.txt"/>
            </fileset>
        </copy>

    </target>

    <target name="compile-javatest.help" depends="compile-javatest.help.main,compile-javatestAgent.help"/>

    <target name="compile.resources" depends="stamp, generate.release.file">
    	<property name="gui-tests" value="gui-tests/src/gui/testsuite_src/src"/>
        <copy todir="${build.classes}">
            <fileset dir="${src.dir}">
                <patternset refid="interview.resources"/>
                <patternset refid="javatest.resources"/>
            </fileset>
        </copy>
        <mkdir dir="${build.classes}/META-INF/"/>
        <buildinfo/>
        <copy file="${src.dir}/com/sun/javatest/tool/i18n.properties"
              tofile="${build.classes}/com/sun/javatest/tool/i18n_fr.properties"/>
    	<copy file="${gui-tests}/com/sun/demots/i18n.properties"
    	      tofile="${build.classes}/com/sun/javatest/tool/i18n_jck.properties"/>
        <mkdir dir="${build.classes}/META-INF/services"/>
        <copy file="${build.dir}/JavaTest.cmdMgrs.lst" tofile="${build.classes}/META-INF/services/com.sun.javatest.tool.CommandManager.lst"/>
        <copy file="${build.dir}/JavaTest.toolMgrs.lst" tofile="${build.classes}/META-INF/services/com.sun.javatest.tool.ToolManager.lst"/>
        <copy file="${build.dir}/com.sun.javatest.report.ReportFormat" tofile="${build.classes}/META-INF/services/com.sun.javatest.report.ReportFormat"/>
    </target>

    <target name="compile.junit.resources" if="jar.junit.dependencies.present" depends="stamp, generate.release.file">
        <copy todir="${build.junit.classes}">
            <fileset dir="${src.dir}">
                <patternset refid="javatest.junit.resources"/>
            </fileset>
        </copy>
        <mkdir dir="${build.classes}/META-INF/"/>
        <buildinfo/>
    </target>


    <target name="run" depends="compile" description="Run application.">
        <fail unless="run.class">${run.class.missing}</fail>
        <java fork="true" classname="${run.class}" jvm="${jdk.builder.home}/bin/java">
            <classpath>
                <path path="${run.classpath}"/>
            </classpath>
        </java>
    </target>

    <target name="javadoc" description="Creates API documentation for the JT Harness source.">
        <condition property="javadoc.add" value="${javadoc.additionalparam} -Xdoclint:none" else="${javadoc.additionalparam}">
            <or>
                <contains string="${java.version}" substring="1.8" />
                <matches pattern="^9.*" string="${java.version}"/>
            </or>
        </condition>

        <mkdir dir="${javadoc.dir}"/>
        <javadoc executable="${jdk.builder.home}/bin/javadoc" destdir="${javadoc.dir}" encoding="${javadoc.encoding}" notree="${javadoc.notree}" use="${javadoc.use}"
                 nonavbar="${javadoc.nonavbar}"
                 noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}"
                 version="${javadoc.version}"
                 windowtitle="${javadoc.windowtitle}" private="${javadoc.private}"
                 additionalparam="${javadoc.add}" failonerror="true"
                 useexternalfile="true">
            <classpath>
                <path path="${jcommjar}:${ant.home}/lib/ant.jar"/>
            </classpath>
            <sourcepath>
                <pathelement location="${src.dir}"/>
            </sourcepath>
            <bottom><![CDATA[ ${javadoc.footer} ]]></bottom>
            <!-- list of packages with useful development doc -->
            <!-- expand if desired -->
            <package name="com.sun.javatest" />
            <package name="com.sun.interview" />
            <package name="com.sun.javatest.interview" />
            <package name="com.sun.javatest.finder" />
            <package name="com.sun.javatest.lib" />
            <package name="com.sun.javatest.util" />
            <package name="com.sun.javatest.tool" />
            <package name="com.sun.javatest.exec" />
            <package name="com.sun.javatest.report" />
        </javadoc>
    </target>

<!-- FIXME:test-i18n,CODETOOLS-7902488 <target name="test" depends="jar,test-nohead,test-i18n,test-copyrights,test-sanity" description="Runs test on JT Harness.">-->
    <target name="test" depends="jar, run-regression-tests, test-copyrights, test-sanity" description="Runs test on JT Harness.">
        <java jvm="${jdk.builder.home}/bin/java" fork="true" failonerror="true" classname="${run.class}">
            <classpath>
                <path path="${BUILD_DIR}/binaries/lib/javatest.jar"/>
            </classpath>
            <arg value="-version"/>
        </java>
    </target>

        <target name="test-sanity" depends="test-sanity-version,test-sanity-simpletck" />

        <target name="test-sanity-version" depends="jar">
                <java jvm="${jdk.builder.home}/bin/java" fork="true" failonerror="false" classname="${run.class}"
                        outputproperty="test.sanity.version.output"
                        resultproperty="test.sanity.version.result">
                        <classpath>
                                <path path="${BUILD_DIR}/binaries/lib/javatest.jar"/>
                        </classpath>
                        <arg value="-version"/>
                </java>

                <property name="test-sanity-version-pattern" value="JT Harness, version ${build.version}.*\nCopyright \(C\) 1996-[0-9][0-9][0-9][0-9] Sun Microsystems, Inc\. All rights reserved" />

                <condition property="test.sanity.version.success">
                        <and>
                                <equals arg1="${test.sanity.version.result}" arg2="0" />
                                <!--<matches singleline="true" string="${test.sanity.version.output}" pattern="${test-sanity-version-pattern}" />-->
                        </and>
                </condition>
                <fail unless="test.sanity.version.success">
                        "java ${run.class} -version" exited with code "${test.sanity.version.result}"

                        The output:
                        ${test.sanity.version.output}

                        Pattern: ${test-sanity-version-pattern}</fail>
        </target>

        <target name="test-sanity-simpletck" depends="jar,build-examples">
                <property name="libs" value="${BUILD_DIR}/binaries/examples/tutorial/demots/lib" />
                <delete dir="${build.tmp}/sanity-demo-wd" />
            <property name="demo.jtx.path" location="${libs}/demo.jtx"/>
                <java jvm="${jdk.builder.home}/bin/java" fork="true" failonerror="false" jar="${BUILD_DIR}/binaries/lib/javatest.jar"
                        resultproperty="test.sanity.simpletck.result">
                        <classpath>
                                <path path="${libs}/demots.jar" />
                                <path path="${libs}/demoapi.jar" />
                        </classpath>
                        <arg line="-verbose:max -ts ${BUILD_DIR}/binaries/examples/tutorial/demots/ -wd -create ${build.tmp}/sanity-demo-wd -config ${libs}/demots.jti -set demoTS.jvm ${jdk.builder.home}/bin/java -excludelist ${demo.jtx.path} -runtests -writeReport report" />
                </java>

                <condition property="test.sanity.simpletck.success">
                        <and>
                                <equals arg1="${test.sanity.simpletck.result}" arg2="0" />
                                <!--<matches singleline="true" string="${test.sanity.simpletck.output}" pattern="${test-sanity-simpletck-pattern}" />-->
                        </and>
                </condition>
                <fail unless="test.sanity.simpletck.success">
                    Simple tck run exited with code "${test.sanity.simpletck.result}"
                </fail>
        </target>

    <target name="run-regression-tests" depends="compile.unit-tests, setup-test-deps" description="Runs all unit tests">
        <delete dir="${build.unit-tests.reports}"/>
        <mkdir dir="${build.unit-tests.reports}"/>
        <echo>jdk.builder.home: ${jdk.builder.home}</echo>
        <junit fork="yes" printsummary="yes" dir="${basedir}" forkmode="perTest">
            <formatter type="plain"/>
            <classpath>
                <path path="${build.classes}"/>
                <pathelement location="${build.unit-tests}"/>
            </classpath>
            <classpath refid="test-deps.classpath"/>
            <jvmarg value="-Dunit-tests.data.dir=${unit-tests.data.dir}"/>
            <jvmarg value="-Dbuild.tmp=${build.tmp}"/>
            <jvmarg value="-Dbuild.classes=${build.classes}"/>
            <jvmarg value="-Dbuild.java.home=${jdk.builder.home}"/>
            <jvmarg value="-DJAVAC=${jdk.builder.home}/bin/javac"/>
            <jvmarg value="-DJAVA=${jdk.builder.home}/bin/java"/>
            <batchtest haltonfailure="true" todir="${build.unit-tests.reports}">
                <fileset dir="${unit-tests.src.dir}" includes="**/*.java"/>
            </batchtest>
        </junit>

    </target>

    <target name="test-gui" depends="jar" description="Runs Jemmy-based UI tests">
        <property name="javatestjar_path" location="${BUILD_DIR}/binaries/lib/javatest.jar"/>
        <property name="jemmyjar_path" location="${jemmylib}"/>
        <property name="junitjar_path" location="${junitlib}"/>
        <ant antfile="build.xml" target="clean" inheritall="true" dir="gui-tests/src"/>
        <ant antfile="build.xml" target="run" inheritall="true" dir="gui-tests/src"/>
    </target>

    <target name="compile-javatest.help.main" unless="javatest.help.ok" >
        <!-- copy across the help files -->
        <mkdir dir="${build.tmp}"/>

        <copy todir="${build.javatest.help}" >
            <fileset dir="${src.dir}/com/sun/javatest/help/">
                <patternset refid="helpset"/>
            </fileset>
        </copy>
        <copy todir="${build.classes}">
            <fileset dir="${src.dir}">
                <patternset refid="helpset"/>
            </fileset>
        </copy>
    </target>

    <target name="check-javatest.help">
        <dependset>
            <srcfileset dir="${src.javatest.help}" />
            <targetfileset dir="${build.javatest.help}" />
        </dependset>
        <available property="javatest.help.ok" file="${build.javatest.help}/default/map.xml"/>
    </target>
    <target name="compile-javatestAgent.help" unless="javatestAgent.help.ok" >
        <!-- copy across the help files -->
        <copy todir="${build.javatestAgent.help}">
            <fileset dir="${src.dir}/com/sun/javatest/agent/help/">
                <patternset refid="helpset"/>
                <exclude name="**/*.tif"/>
            </fileset>
        </copy>
    </target>

    <target name="check-javatestAgent.help">
        <dependset>
            <srcfileset dir="${src.javatestAgent.help}" />
            <targetfileset dir="${build.javatestAgent.help}" />
        </dependset>
        <available property="javatestAgent.help.ok" file="${build.javatestAgent.help}/default/map.xml"/>
    </target>
    <!-- ********** jct-utils ********************************************** -->

    <target name="compile-jct.utils">
        <mkdir dir="${build.classes}"/>
        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${src.dir}"
               destdir="${build.classes}">
            <include name="com/sun/jct/utils/glossarygen/**"/>
            <include name="com/sun/jct/utils/indexgen/**"/>
            <include name="com/sun/jct/utils/mapmerge/**"/>
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
        </javac>
    </target>

    <!-- ********** examples ********************************************** -->
    <target name="build-examples" depends="build-tutorial, build-services-ts"/>

    <target name="build-tutorial" depends="jar">
        <property name="build.examples" location="${BUILD_DIR}/binaries/examples/tutorial"/>
        <mkdir dir="${build.tmp}/${exam.dir}/demoapi"/>
        <mkdir dir="${build.tmp}/${exam.dir}/simpleTags"/>
        <mkdir dir="${build.examples}/demots/lib"/>

        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${exam.dir}/tutorial/demoapi"
               destdir="${build.tmp}/${exam.dir}/demoapi">
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
        </javac>
        <jar destfile="${build.examples}/demots/lib/demoapi.jar"
             basedir="${build.tmp}/${exam.dir}/demoapi" index="false">
            <manifest>
                <attribute name="Built-By"   value="${user.name}"/>
                <attribute name="Main-Class" value="${run.class}"/>
            </manifest>
        </jar>
        <copy todir="${build.examples}/demots/lib">
            <fileset file="${BUILD_DIR}/binaries/lib/javatest.jar"/>
        </copy>


        <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
               fork="true" executable="${jdk.builder.home}/bin/javac"
               srcdir="${exam.dir}/tutorial/simpleTags"
               destdir="${build.tmp}/${exam.dir}/simpleTags"
               classpath="${BUILD_DIR}/binaries/lib/javatest.jar:${build.examples}/demots/lib/demoapi.jar">
            <compilerarg value="-version"/>
            <compilerarg value="-Xlint:rawtypes"/>
            <compilerarg value="-Xlint:cast"/>
            <compilerarg value="-Xlint:overrides"/>
        </javac>
        <copy todir="${build.tmp}/${exam.dir}/simpleTags">
            <fileset dir="${exam.dir}/tutorial/simpleTags/src">
                <include name="**/moreInfo/**"/>
                <include name="**/*.properties"/>
            </fileset>
        </copy>

        <jar destfile="${build.examples}/demots/lib/jtdemots.jar"
             basedir="${build.tmp}/${exam.dir}/simpleTags" index="false">
            <manifest>
                <attribute name="Built-By"   value="${user.name}"/>
                <attribute name="Main-Class" value="${run.class}"/>
            </manifest>
        </jar>
        <copy todir="${build.examples}/demots">
            <fileset dir="${exam.dir}/tutorial/simpleTags/demots"/>
        </copy>
        <copy todir="${build.examples}">
            <fileset dir="${exam.dir}/tutorial/doc"/>
        </copy>
        <copy todir="${build.examples}/demoapi">
            <fileset dir="${exam.dir}/tutorial/demoapi"/>
        </copy>


        </target>


        <target name="build-services-ts" depends="build-tutorial">
            <property name="services.ts" location="${BUILD_DIR}/binaries/examples/services_ts"/>
            <mkdir dir="${build.tmp}/${exam.dir}/services_demo/classes"/>
            <mkdir dir="${services.ts}/lib"/>

            <copy todir="${services.ts}/lib">
                <fileset file="${BUILD_DIR}/binaries/lib/javatest.jar"/>
                <fileset file="${build.examples}/demots/lib/demoapi.jar"/>
            </copy>


            <javac encoding="iso-8859-1" debug="true" source="${javac.source.level}" target="${javac.target.level}"
                   fork="true" executable="${jdk.builder.home}/bin/javac"
                   srcdir="${exam.dir}/services_demo/src"
                   destdir="${build.tmp}/${exam.dir}/services_demo/classes"
                   classpath="${BUILD_DIR}/binaries/lib/javatest.jar">
                <compilerarg value="-version"/>
                <compilerarg value="-Xlint:rawtypes"/>
                <compilerarg value="-Xlint:cast"/>
                <compilerarg value="-Xlint:overrides"/>
            </javac>
            <copy todir="${build.tmp}/${exam.dir}/services_demo/classes">
                <fileset dir="${exam.dir}/services_demo/src">
                    <include name="**/moreinfo/**"/>
                    <include name="**/*.properties"/>
                </fileset>
            </copy>

            <jar destfile="${services.ts}/lib/jtservices.jar"
                 basedir="${build.tmp}/${exam.dir}/services_demo/classes" index="false">
                 <manifest>
                     <attribute name="Built-By"   value="${user.name}"/>
                     <attribute name="Main-Class" value="${run.class}"/>
                 </manifest>
             </jar>

             <copy todir="${services.ts}">
                 <fileset dir="${exam.dir}/services_demo/services_ts"/>
             </copy>

         </target>


        <!--
        ********** copyright checker **********************************************
        -->
        <property file="build/copyright.properties"/>
        <target name="test-copyrights" depends="compile.test.copyright.classes">
                <taskdef name="checkCopyrights" classpath="${build.classes}" classname="com.sun.jct.utils.copyrightcheck.CheckCopyrights"/>
                <checkCopyrights pattern="${copyright.pattern}" dir="${src.dir}" includes="${copyright.includes}" excludes="${copyright.excludes}" failOnError="yes"/>
                <checkCopyrights pattern="${copyright.pattern}" dir="${unit-tests.src-support.dir}" includes="${copyright.includes}" excludes="${copyright.excludes}" failOnError="yes"/>
                <checkCopyrights pattern="${copyright.pattern}" dir="${unit-tests.src.dir}" includes="${copyright.includes}" excludes="${copyright.excludes}" failOnError="yes"/>
        </target>
</project>
