<project name="deploySIBdefault" default="deploySIBdefault" basedir=".">
    
    <taskdef name="wscmtlog"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>
    <taskdef name="replaceStringRegExp" 
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.ReplaceStringRegExpAntTask"/> 

    <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="setOSFileSeparator"
            description="Sets the current file separator for this platform (file.separator is unreliable on ANT 1.5.4)">
            
        <condition property="separatorFile" value="/">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>
        
        <condition property="separatorFile" value="/">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="separatorFile" value="\">
            <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="${WAS_HOME}/bin/wsadmin">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>
        
        <condition property="WSADMIN_EXECUTABLE" value="${WAS_HOME}/bin/wsadmin.sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="WSADMIN_EXECUTABLE" value="${WAS_HOME}/bin/wsadmin.bat">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
        
        <wscmtlog>wsadmin interpretor set to: ${WSADMIN_EXECUTABLE}</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="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii"
            description="Replaces all instances of the given token for the given file with the given value">

        <wscmtlog>Replacing token: ${token}, with ${tokenValue}, in file ${file}</wscmtlog>

        <replace file="${file}"
            token="${token}"
            encoding="UTF-8"
            value="${tokenValue}"/>
    </target>
    
    <target name="resolveProfilePathForPropertyFiles"
            description="Sets the property PROFILE_PATH_FOR_PROPERTY_FILES with slash characters etc. adjusted for property files">
         
        <replaceStringRegExp string="${profilePath}"
            regexp="\\"
            value="/"
            property="PROFILE_PATH_FOR_PROPERTY_FILES_FIRST_PASS"/>
             
        <replaceStringRegExp string="${PROFILE_PATH_FOR_PROPERTY_FILES_FIRST_PASS}"
            regexp="/:"
            value="\:/"
            property="PROFILE_PATH_FOR_PROPERTY_FILES"/>
             
        <wscmtlog>PROFILE_PATH_FOR_PROPERTY_FILES for property files was resolved to be: ${PROFILE_PATH_FOR_PROPERTY_FILES}</wscmtlog>
    </target>

    <target name="deploySIBdefault"
        description="Actions required to configure SIB component in a default profile"
        depends="detectCurrentOSFamily,
                 setOSFileSeparator,
                 resolveWSADMINExecutableForTheCurrentPlatform,
                 resolveSetupCmdLineName,
                 resolveProfilePathForPropertyFiles">
                 
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
           <param name="file" value="${profilePath}/properties/sib.client.ssl.properties"/>
           <param name="token" value="$$(WASROOT)"/>
           <param name="tokenValue" value="${PROFILE_PATH_FOR_PROPERTY_FILES}"/>
        </antcall>
    </target>

</project>

