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

    Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<project name="activation-tck" default="default" basedir="." xmlns:if="ant:if">
    <description>Builds and runs the project activation-tck.</description>

    <property name="version" value="2.0"/>
    <property name="version.tck" value="2.0.1"/>


    <property environment="env"/>
    <dirname property="tck.basedir" file="${ant.file.activation-tck}"/>
    <property name="ts.home" value="${tck.basedir}"/>

    <property file="${ts.home}/lib/ts.jte"/>

    <property name="dir.sep"       value="${file.separator}"/>
    <property name="dirsep"        value="${file.separator}"/>

    <property name="pathsep"        value="${path.separator}"/>

    <property file="${bin.dir}/ts.jte"/>
    <property name="lib.dir" value="${ts.home}${file.separator}lib"/>
    <property name="class.dir" value="${ts.home}${file.separator}classes"/>
    <property name="tests.dir" value="${ts.home}${file.separator}tests"/>
    <property name="work.dir" value="${ts.home}/JTwork"/>
    <property name="report.dir" value="${ts.home}/JTreport"/>
    <mkdir dir="${class.dir}"/>
    <mkdir dir="${work.dir}"/>
    <mkdir dir="${report.dir}"/>

    <condition property="tests.arg" value="-tests ${tests}" else="">
            <isset property="tests"/>
    </condition>

    <condition property="tests.debug" value="-D" else="">
            <isset property="debug"/>
    </condition>

    <property name="class.path" value="${class.dir}${pathsep}${ts.home}/sigtest.jar${pathsep}${ts.home}/javatest.jar${pathsep}${JARPATH}/jakarta.activation.jar"/>

    <!-- Does the current runtime support modules? -->
    <condition property="jdk.modules" value="false" else="true">
	<or>
	    <contains string="${java.version}" substring="1.7" />
	    <contains string="${java.version}" substring="1.8" />
	</or>
	<!-- anything else is JDK9+ -->
    </condition>
    <condition property="java.classes.for.sig.ext"
		value="lib/modules"
                else="lib/rt.jar">
	<istrue value="${jdk.modules}"/>
    </condition>

    <target name="build"
            description="Compiles all sources to the classes directory">
		<javac includeantruntime="false" deprecation="yes"
			source="8" target="8"
			optimize="true" srcdir="tests"
			classpath="${class.path}" destdir="${class.dir}"
			debug="on" />
                <javac includeantruntime="false" deprecation="yes"
			source="8" target="8"
			optimize="true" srcdir="harness"
			classpath="${class.path}" destdir="${class.dir}"
			debug="on" />
    </target>


    <target name="clean"
            description="Cleans all classes from the classes directory">
        <delete failonerror="false" includeEmptyDirs="true">
            <fileset dir="${class.dir}" includes="*/**"/>
        </delete>
    </target>

    <target name="run"
            description="Executes the JAF TCK in batch mode">
        <javatest.batch/>
    </target>

    <target name="gui"
            description="Executes the JAF TCK in GUI mode">
        <javatest.gui/>
    </target>

    <target name="record.sigtest">
        <java fork="true" jar="./sigtestdev.jar">
                <arg value="Setup"/>
                <arg value="-Classpath"/>
                <arg value="${java.home}/${java.classes.for.sig.ext}${pathsep}${class.path}"/>
                <arg value="-Package"/>
                <arg value="jakarta.activation"/>
                <arg value="-FileName"/>
                <arg value="${ts.home}/tests/jakarta.activation_${version}_java_${java.specification.version}.sig"/>
                <arg value="-Static"/>
                <arg value="-Xjimage" if:true="${jdk.modules}"/>
                <arg value="${java.home}/bin/jimage" if:true="${jdk.modules}"/>
        </java>
    </target>

    <presetdef name="javatest">

        <!--
          The javatest task is a presetdef that sets many of the common
          attributes and elements used by both the GUI and batch mode
          invocations of javatest with the spider workspace.  To see the preset
          values, refer to the included XML below that shows the content of
          the javatest presetdef.
        -->

        <java classname="com.sun.javatest.tool.Main"
              failonerror="${failOnError}" fork="yes" >
            <classpath>
                <pathelement path="${class.path}"/>
            </classpath>	
	    <sysproperty key="testDebug" value="${tests.debug}"/>
        </java>
    </presetdef>

    <presetdef name="javatest.batch">

        <!--
          The javatest.batch task is a presetdef that calls the javatest
          presetdef passing the additional XML content needed to invoke
          javatest in batch mode.  To see the preset values, refer to the
          included XML below that shows the content of the javatest.batch
          presetdef.
        -->

        <javatest>
            <arg line=" -EsysProps" />
            <arg line=" -batch" />
            <arg line=" -ts tests/testsuite.html" />
            <arg line=" -workdir ${work.dir}" />
            <arg line=" -envFiles ${ts.home}/lib/ts.jte" />
            <arg line=" -env jafUnix" />
            <arg line=" -excludeList ${ts.home}/lib/ts.jtx" />
            <arg line=" -timeoutFactor 1" />
            <arg line=" ${tests.arg}" />
            <arg line=" -runtests -writereport ${report.dir}"/>
        </javatest>
    </presetdef>


    <presetdef name="javatest.gui">

        <!--
          The javatest.gui task is a presetdef that calls the javatest presetdef
          passing the additional XML content needed to invoke the javatest GUI.
          To see the preset values, refer to the included XML below that shows
          the content of the javatest.gui presetdef.
        -->

        <javatest>
            <arg    line="-open ${ts.home}/lib/ts.jti" />
            <arg    line="-EsysProps" />
        </javatest>
    </presetdef>

    <presetdef name="javatest.help">

        <javatest>
            <arg line="-help" />

        </javatest>
    </presetdef>

</project>
