<project name="removeBusinessGridVariablesProject" default="removeBusinessGridVariables" 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="removeBusinessGridVariables"
            description="sets variables needed by Business Grid"
            depends="detectCurrentOSFamily,
            convertWASHomeToUNIXStylePath,
            resolveWSADMINExecutableForTheCurrentPlatform">

        <exec executable="${WSADMIN_EXECUTABLE}"
              failonerror="true"
                output="${profilePath}/logs/removeBusinessGridVariables.log">
            <arg value="-conntype"/>
            <arg value="NONE"/>
            <arg value="-lang"/>
            <arg value="jython"/>
            <arg value="-f"/>
            <arg value="${WAS_HOME}/profileTemplates/xd_augment/actions/setupBusinessGridVariables.py"/>
            <arg value="-cleanup"/>
        </exec>
    </target>

</project>
