<project name="removeForeignServerVariablesProject" default="removeForeignServerVariables" basedir=".">

    <target name="detectCurrentOSFamily"
            description="Detecs the current OS family (UNIX or Windows)">

        <condition property="currentOSFamily" value="windows">
            <os family="windows"/>
        </condition>

        <condition property="currentOSFamily" value="unix">
            <os family="unix"/>
        </condition>

        <wscmtlog>Detected current OS family to be: ${currentOSFamily}</wscmtlog>
    </target>

    <target name="convertWASHomeToUNIXStylePath">
        <path id="id.was.home">
            <pathelement location="${WAS_HOME}"/>
        </path>

        <pathconvert targetos="unix"
            property="WAS_HOME_UNIX_STYLE"
            refid="id.was.home"/>
    </target>

    <target name="setScriptExtension"
            description="Sets the current script  for this platform (file.separator is unreliable on ANT 1.5.4)">

        <condition property="scriptExtension" value="sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>

        <condition property="scriptExtension" value="bat">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
    </target>


    <target name="resolveWSADMINExecutableForTheCurrentPlatform"
            description="Sets WSADMIN_EXECUTABLE to the WAS Java interpretor for the current platform">

        <condition property="WSADMIN_EXECUTABLE" value="${profilePath}/bin/wsadmin.sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>

        <condition property="WSADMIN_EXECUTABLE" value="${profilePath}/bin/wsadmin.bat">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>

        <wscmtlog>wsadmin interpretor set to: ${WSADMIN_EXECUTABLE}</wscmtlog>
    </target>

    <target name="removeForeignServerVariables"
            description="sets variables needed by the default foreign server templates"
            depends="detectCurrentOSFamily,
            convertWASHomeToUNIXStylePath,
            resolveWSADMINExecutableForTheCurrentPlatform">

        <exec executable="${WSADMIN_EXECUTABLE}"
              failonerror="true"
                output="${WS_CMT_LOG_HOME}/${profileName}/removeForeignServerVariables.log">
            <arg value="-conntype"/>
            <arg value="NONE"/>
            <arg value="-lang"/>
            <arg value="jython"/>
            <arg value="-f"/>
            <arg value="${templatePath}/actions/setupForeignServerVariables.py"/>
            <arg value="-cleanup"/>
        </exec>
    </target>

</project>
