<?xml version="1.0"?>
<!--

    Copyright (c) 2018 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="CommonProps" basedir=".">

    <!-- 
    This is a common import file that contains properties that are shared
    by all build files.  
    -->
    
    <property environment="env"/>
    
    <dirname property="CommonProps.basedir" file="${ant.file.CommonProps}"/>
    
    <!--<condition property="dir.path.sep" value="\\"
                                       else="/">
        <os family="windows"/>
    </condition>
-->
    <property name="dir.sep"       value="${file.separator}"/>
    <property name="dirsep"        value="${file.separator}"/>

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

    <!--<condition property="pathsep" value=";"
                                  else=":">
        <os family="windows"/>
    </condition>
-->

    <!-- Set ts.home based upon whether this file is in the install dir 
         or not
    -->
    <condition property="ts.home" 
               value="${CommonProps.basedir}${file.separator}..${file.separator}..${file.separator}..${file.separator}.."
               else="${CommonProps.basedir}${file.separator}..${file.separator}..">
        <contains string="${CommonProps.basedir}" 
                 substring="install${file.separator}common${file.separator}bin${file.separator}xml"/>
    </condition>
    <echo message="ts.home = ${ts.home}"/>
    
    <!-- Need to set jdk.home in case java.home points to a JRE -->
    <condition property="jdk.home" 
               value="${java.home}"
               else="${java.home}${file.separator}..">
        <available file="${java.home}${file.separator}lib${file.separator}tools.jar"/>
    </condition>
    
    <!-- Common properties -->
    <property name="dist.dir"        value="${ts.home}/dist"/>
    <property name="src.dir"         value="${ts.home}/src"/>
    <property name="lib.dir"         value="${ts.home}/lib"/>
    <property name="tmp.dir"         value="${ts.home}/tmp"/>
    <property name="weblib.dir"      value="${ts.home}/weblib"/>
    <property name="install.dir"     value="${ts.home}/install"/>
    <property name="common.bin.dir"  value="${ts.home}/bin"/>
    
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpath="${lib.dir}/ant-contrib-1.0b3.jar"/>
    
    <property name="ant.jars" value="${ant.home}/lib/ant.jar:
                                     ${ant.home}/lib/ant-launcher.jar:
                                     ${ant.home}/lib/ant-nodeps.jar"/>

    <!--
         checkPlatform determines which OS is being utilized.
    -->
    <target name="checkPlatform" >
        <condition property ="isUnixPlatform">
           <os family="unix"/>
        </condition>
        <condition property ="isWindowsPlatform">
           <os family="windows"/>
        </condition>
        <condition property ="os" value="unix">
           <os family="unix"/>
        </condition>
        <condition property ="os" value="windows">
           <os family="windows"/>
        </condition>
        <condition property ="isMac">
           <os family="mac"/>
        </condition>
        
        <!-- Is the the Java EE RI? -->
        <condition property="is.ri">
           <and>
              <available file="${server.home}/README.install"/>
              <available file="${server.home}/setup.xml"/>
           </and>
        </condition>
        <propertyregex property="bit.mode"
                  input="${os.arch}"
                  regexp="(^.*)(64)$"
                  select="\2"
                  casesensitive="false"
                  />
        <if>
            <and>
                <isset property="bit.mode"/>
                <equals arg1="${bit.mode}" arg2="64"/>
            </and>
        <then>
            <var name="jvm.64bit" value="true"/>
        </then>
        <else>
            <var name="jvm.64bit" value="false"/>
        </else>
        </if>
    </target>
                                     
    <target name="get.deliverable.version.number"/>
    
    <!-- Set class.dir based on the setting of build.vi-->
    <if>
        <equals arg1="${build.vi}" arg2="true"/>
    <then>
        <property name="class.dir" value="${ts.home}/classes_vi_built"/>
    </then>
    <else>
        <property name="build.vi" value="false"/>
        <property name="class.dir" value="${ts.home}/classes"/>
    </else>
    </if>
  
    <mkdir dir="${class.dir}"/>
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${tmp.dir}"/>
    <mkdir dir="${weblib.dir}"/>
    
    <!-- Set the deliverable bin dir based on whether ant setup was run
         (as in a bundle) or we're in the install deliverable dir -->
    <if>
        <available file="${CommonProps.basedir}/../ts.jte"/>
    <then>
        <property name="in.workspace" value="false"/>
        <property file="${CommonProps.basedir}/../ts.jte"/>
        <property name="bin.dir" value="${ts.home}${file.separator}bin"/>
        
        <!-- Set the deliverable.dir and deliverabledir properties to none since
        we're in a bundle.  This is to prevent the recursive definition error
        when passing in deliverable.dir as a system property to JavaTest.  When
        the AbstractPropertyManager looks up the system props, since we're in a
        bundle, the prop is set to "${deliverable.dir} and results in a
        recursive definition error when Javatest calls back into ant during
        AutoDeployment.  Thus we'll just set it here so the error doesn't occur.
        The prop is not used when in a bundle, so the value doesn't matter-->
        <property name="deliverable.dir" value="none"/>
        <property name="deliverabledir" value="none"/>
        <echo message="In a bundle"/>
        <echo message="The deliverable currently in use is ${bin.dir}."/>
    </then>
    <else>
        <property name="in.workspace" value="true"/>
        <if>
            <isset property="env.deliverabledir"/>
        <then>
            <property name="deliverable.dir" value="${env.deliverabledir}"/>
            <property name="deliverabledir" value="${env.deliverabledir}"/>
        </then>
        <elseif>
            <isset property="deliverabledir"/>
          <then>
              <property name="deliverable.dir" value="${deliverabledir}"/>
          </then>
        </elseif>
        <else>
            <!-- Let's try and figure out the deliverable.dir based on what 
            src dir we're in
            -->
            <if>
                <contains string="${basedir}" 
                          substring="signaturetest"/>
                <then>
                    <echo message="basedir = ${basedir}"/>
                    
                    <propertyregex property="deliverable.dir"
                                   input="${basedir}${file.separator}"
                                   regexp=".*[\/|\\]sun[\/|\\]ts[\/|\\]tests[\/|\\]signaturetest[\/|\\](.*?)[\/|\\]"
                                   select="\1"
                                   casesensitive="false" />
                </then>
                <elseif>
                    <contains string="${basedir}" 
                              substring="${file.separator}install${file.separator}"/>
                    <then>
                        <propertyregex property="deliverable.dir"
                                       input="${basedir}${file.separator}"
                                       regexp=".*[\/|\\]install[\/|\\](.*?)[\/|\\]"
                                       select="\1"
                                       casesensitive="false" />
                    </then>    
                </elseif>
                <elseif>
                    <contains string="${basedir}" 
                              substring="com${file.separator}sun${file.separator}ts${file.separator}lib"/>
                    <then>
                        <property name="deliverable.dir" value="j2ee"/>
                    </then>    
                </elseif>
                <else>
                    <propertyregex property="deliverable.dir"
                                   input="${basedir}${file.separator}"
                                   regexp=".*[\/|\\]sun[\/|\\]ts[\/|\\]tests[\/|\\](.*?)[\/|\\]"
                                   select="\1"
                                   casesensitive="false" />
                </else>
            </if>  
        </else>
        </if>
          
        <if>
            <equals arg1="${deliverable.dir}" arg2="javaee"/>
        <then>
            <var name="deliverable.dir" value="j2ee"/>
        </then>
        </if>
        
        <if>
          <not>
            <available file="${ts.home}${file.separator}install${file.separator}${deliverable.dir}" type="dir"/>
          </not>
          <then>
            <fail message="There is no deliverabledir by the name of ${deliverable.dir} under ${ts.home}${file.separator}install.  Please set deliverabledir in your environment"/>
          </then>
        </if>
        
        <if>
            <available file="${ts.home}${file.separator}install${file.separator}${deliverable.dir}${file.separator}bin${file.separator}ts.jte"/>
        <then>
            <echo message="The deliverable currently in use is ${ts.home}${file.separator}install${file.separator}${deliverable.dir}."/>
        </then>
        <else>
            <fail message="There is no ts.jte under ${ts.home}${file.separator}install${file.separator}bin. Please set your java test environment"/>
        </else>
        </if>
        
        <property name="bin.dir" value="${CommonProps.basedir}/../../install/${deliverable.dir}/bin"/>
        <property file="${bin.dir}/ts.jte"/>
        
        <copy file="${bin.dir}/../other/testsuite.jtt" todir="${src.dir}"
              overwrite="true" failonerror="false"/>
        <delete file="${src.dir}/vehicle.properties" failonerror="false"/>
        <copy file="${bin.dir}/../other/vehicle.properties" todir="${src.dir}"
              overwrite="true" failonerror="false"/>
    </else>
    </if>
    
    <!-- Set this until we get rid of it for the bundle xml files to use-->
    <property name="deliverable.name" value="${deliverable.dir}"/>
    
    <!-- Presetdef for tasks using ant_sun.jar -->
    <presetdef name="ts.taskdef">
        <taskdef classpath="${lib.dir}/ant_sun.jar"/>
    </presetdef>

    <presetdef name="ts.verbose">
        <!--
          The ts.verbose task is used to print messages only when running ant with the -v  or debug options.
        -->
        <echo level="verbose"/>
    </presetdef>
    
    <presetdef name="ts.echo">
        <echo/>
    </presetdef>
    
    <!-- Override antcall so that deliverable.dir maintains its value across projects -->
    <!--<presetdef name="antcall">
        <antcall>
            <param name="deliverable.dir" value="${deliverable.dir}"/>
        </antcall>
    </presetdef>
    -->
    <!-- FindBugs and PMD related files are removed -->
    <!-- Findbugs home directory -->
    <!-- property name="findbugs.dir"   value="${ts.home}/tools/findbugs"/ -->
	
    <!-- PMD home directory -->
    <!-- property name="pmd.dir"   value="${ts.home}/tools/pmd"/ -->
    
    <!-- Common tasks used across the workspace and packaged in ant_sun.jar -->
    <ts.taskdef name="translatepath" 
                classname="com.sun.ant.taskdefs.common.PathTranslator"/>
    <ts.taskdef name="elementappend" 
                classname="com.sun.ant.taskdefs.common.ElementAppend"/>
    <ts.taskdef name="dosubdirs" 
                classname="com.sun.ant.taskdefs.common.DoSubdirs"/>
    <ts.taskdef name="dotarget" 
                classname="com.sun.ant.taskdefs.common.DoTarget"/>
    <ts.taskdef name="appendafter" 
                classname="com.sun.ant.taskdefs.common.AppendAfter"/>
    <ts.taskdef name="insertbefore" 
                classname="com.sun.ant.taskdefs.common.InsertBefore"/>
    <ts.taskdef name="propertyindex" 
                classname="com.sun.ant.taskdefs.common.PropertyIndex"/>
    <ts.taskdef name="undeployall" 
                classname="com.sun.ant.taskdefs.common.UndeployAll"/>
    <ts.taskdef name="encode" classname="com.sun.ant.taskdefs.common.Encoder"/>
    <ts.taskdef name="string" classname="com.sun.ant.taskdefs.common.MyString"/>
    <ts.taskdef name="spawn" classname="com.sun.ant.taskdefs.s1as.SpawnTask"/>
    <ts.taskdef name="runcts" classname="com.sun.ant.taskdefs.common.RunCTS"/>
    <taskdef name="modifyxml" classname="com.sun.ant.taskdefs.xml.ModifyXML"
             classpath="${lib.dir}/ant_sun.jar:${lib.dir}/jdom-1.1.3.jar:${lib.dir}/jaxen-core-1.0.jar:${lib.dir}/jaxen-1.1.6.jar:${lib.dir}/saxpath.jar"/>
    <taskdef name="configctsjcov" 
             classname="com.sun.ant.taskdefs.common.JCOVCTSConfig"
             classpath="${lib.dir}/ant_sun.jar:${lib.dir}/jdom-1.1.3.jar"/>
    <taskdef name="configctsemma" 
             classname="com.sun.ant.taskdefs.common.EMMACTSConfig"
             classpath="${lib.dir}/ant_sun.jar:${lib.dir}/jdom-1.1.3.jar"/>
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
             classpath="${findbugs.dir}/lib/findbugs-ant.jar"
             onerror="ignore"/>
	<ts.taskdef name="props.sanitizer" 
		classname="com.sun.ant.taskdefs.common.PropsSanitizer" />
    <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"
             classpath="${pmd.dir}/lib/pmd-4.3.jar"
             onerror="ignore"/>
    
    <property file="${src.dir}/vehicle.properties"/>
                             
    <property name="ejbvehicle.classes"         value=""/>
    <property name="servletvehicle.classes"     value=""/>
    <property name="jspvehicle.classes"         value=""/>
    <property name="appclientvehicle.classes"   value=""/>
    
    <!-- Package directories -->
    <property name="lib.pkg.dir"     value="com/sun/ts/lib"/>
    <property name="tests.pkg.dir"   value="com/sun/ts/tests"/>
    <property name="sig.pkg.dir"     value="${tests.pkg.dir}/signaturetest"/>
    <property name="harness.pkg.dir" value="${lib.pkg.dir}/harness"/>
    <property name="impl.pkg.dir"    value="${lib.pkg.dir}/implementation"/>
    <property name="util.pkg.dir"    value="${lib.pkg.dir}/util"/>
    <property name="porting.pkg.dir" value="${lib.pkg.dir}/porting"/>
    
    <property name="vehicle.pkg.dir" value="${tests.pkg.dir}/common/vehicle"/>
    <property name="webservices.pkg.dir" value="${tests.pkg.dir}/common/webservices"/>
    <property name="vehicle.src.dir" value="${ts.home}/src/${vehicle.pkg.dir}"/>
        
    <!-- Rebuildable directory related properties -->
    <property name="vi.build.string" value="vi_built"/>
    <property file="${src.dir}/${harness.pkg.dir}/rebuildable.properties"/>
    <property name="rebuildable" value="false"/>
    <property name="rebuildable.prop.name" value=""/>
    <property name="saved.pkg.dir" value=""/>

    <!--
    <property name="vi.xml.impl.dir" value="${common.bin.dir}/xml/implementation/${vi.implementation}"/>
    <property name="ri.xml.impl.dir" value="${common.bin.dir}/xml/implementation/${ri.implementation}"/>
-->

    <!-- Set JavvatestMaxOutputSize if it is not set yet in the ts.jte file -->
    <property name="harness.maxoutputsize"   value="200000"/>

    <!-- Extension list library version number -->
    <property name="extension.lib.version"   value="1.4"/>

    <propertyregex property="pkg.dir"
                   input="${basedir}"
                   regexp=".*src[\/|\\](.*)"
                   select="\1"
                   casesensitive="true"
                   override="true"/>
                   
    <!-- dynamically compute the java package for the current test directory, e.g.,
         com.sun.ts.tests.samples.ejb.ee.simpleHello  -->
    <propertyregex property="package"
                        input="${pkg.dir}"
                        regexp="[\/|\\]" replace="\."
                        casesensitive="true"
                        override="true"/>

    <!-- dynamically compute the default application client main class, e.g.,
         com.sun.ts.tests.ejb30.bb.session.stateless.basic.Client -->
    <property name="client" value="${package}.Client"/>

    <property name="default.vehicles" value="ejb servlet jsp appclient"/>
    <property name="test.base.classes"  
              value="${harness.pkg.dir}/EETest*.class"/>

    <pathconvert property="src.path">
        <path>
            <pathelement location="${src.dir}"/>
        </path>
    </pathconvert>
    
    <!-- Variables -->

    <!--
        Store the vehicles that are processed into a variable that is visible to the importing
        build files.  This allows leaf build files the ability to run specific sets of tasks
        based on the vehicles that were built.
    -->    
    <var name="vehicle.prop.name" value=""/>
    <var name="vehicles" value="${default.vehicles}"/>               

    <!--<if>
        <os family="windows"/>
    <then>
        <property name="dir.path.sep" value="\"/>
        <property name="pathsep" value=";"/>
    </then>
    <else>
        <property name="dir.path.sep" value="/"/>
        <property name="pathsep" value=":"/>
    </else>    
    </if>
    -->
    
    <!-- Set ts.home based upon whether this file is in the install dir 
         or not
    -->
    <!--
    <if>
        <contains string="${CommonProps.basedir}" 
                 substring="install${file.separator}common${file.separator}bin${file.separator}xml"/>
    <then>
        <property name="ts.home" 
        value="${CommonProps.basedir}${file.separator}..${file.separator}..${file.separator}..${file.separator}.."/>
    </then>
    <else>
        <property name="ts.home" 
        value="${CommonProps.basedir}${file.separator}..${file.separator}.."/>
    </else>
    </if>
    -->
 <property name="jdk9.compiler.arg" value="--add-modules java.activation --add-modules java.transaction --add-modules java.xml.bind --add-modules java.xml.ws --add-modules java.xml.ws.annotation --patch-module java.transaction=${s1as.modules}/jakarta.transaction-api.jar --patch-module java.xml.ws.annotation=${s1as.modules}/endorsed/javax.annotation-api.jar --add-exports java.xml.ws.annotation/javax.annotation.security=ALL-UNNAMED --add-exports java.xml.ws.annotation/javax.annotation=ALL-UNNAMED --add-exports java.xml.ws.annotation/javax.annotation.sql=ALL-UNNAMED" />
</project>
