<project name="removeNodeMetadata" default="removeNodeMetadata" basedir=".">

    <taskdef name="wscmtlog"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>

    <target name="detectCurrentOSFamily"
            description="Detecs the current OS family (UNIX or Windows)">

        <!-- OS/400 setting must come before the unix setting -->
        <condition property="currentOSFamily" value="os/400">
            <equals arg1="${os.name}" arg2="OS/400"/>
        </condition>

        <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="setCurrentOSFamily"
            description="Detects the current OS family (UNIX or Windows)">

        <!-- OS/400 setting must come before the unix setting -->
        <condition property="isCurrentOSOS400" value="true">
            <equals arg1="${os.name}" arg2="OS/400"/>
        </condition>

        <condition property="isCurrentOSWindows" value="true">
            <os family="windows"/>
        </condition>

        <condition property="isCurrentOSUNIX" value="true">
            <os family="unix"/>
        </condition>
    </target>

    <target name="resolveRemoveMetadataExecutableForTheCurrentPlatform"
            description="Sets REMOVE_METADATA to the right script for the current platform">

        <condition property="REMOVE_METADATA" value="${basedir}/scripts/removeNodeMetadata">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>

        <condition property="REMOVE_METADATA" value="${basedir}/scripts/removeNodeMetadata.sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>

        <condition property="REMOVE_METADATA" value="${basedir}/scripts/removeNodeMetadata.bat">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>

        <wscmtlog>removeNodeMetadata interpretor set to: ${REMOVE_METADATA}</wscmtlog>
    </target>

    <target name="resolveSetupCmdLineName">
        <available property="setupCmdLineName"
            value="setupCmdLine"
            file="${WAS_HOME}/bin/setupCmdLine"/>

        <available property="setupCmdLineName"
            value="setupCmdLine.bat"
            file="${WAS_HOME}/bin/setupCmdLine.bat"/>

        <available property="setupCmdLineName"
            value="setupCmdLine.sh"
            file="${WAS_HOME}/bin/setupCmdLine.sh"/>

        <wscmtlog>Detected setupCmdLine script name to be: ${setupCmdLineName}</wscmtlog>
    </target>

    <target name="runRemoveNodeMetadata"
            description="removes the node metadata and writes to local repository">

        <exec executable="${REMOVE_METADATA}"
                output="${profilePath}/logs/remove_metadata.log" failonerror="true">
            <arg value=""/>
		<env key="WAS_USER_SCRIPT" value="${profilePath}/bin/${setupCmdLineName}"/>
            <env key="PROFILE_CONFIG_ACTION" value="true"/>
        </exec>

        <wscmtlog>Done.</wscmtlog>
    </target>

    <target name="removeNodeMetadata"
        description="Removes Node Metadata"
        depends="detectCurrentOSFamily,
            setCurrentOSFamily,
            resolveRemoveMetadataExecutableForTheCurrentPlatform,
		resolveSetupCmdLineName,
		runRemoveNodeMetadata"/>

</project>

