<project name="bootstrapWCCMFiles" default="bootstrapWCCMFiles" 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"/>
    <taskdef name="n2a" classname="com.ibm.ws.profile.anttasks.Native2AsciiAntTask"/>

    <!-- Determine whether the node name specified by the user
         is the (default) string "DefaultNode". If it is, there will not
         be any need to rename the node directory, because when
         it is created, its name is "DefaultNode" already. -->
    <target name="detectDefaultNodeName"
      description="Detects if the node name is DefaultNode" >
        <wscmtlog>Starting detectDefaultNodeName with nodeName ${nodeName}</wscmtlog>
        <!-- Set nodeNameIsDefaultNode true if the node name is DefaultNode. -->
        <condition property="nodeNameIsDefaultNode">
            <equals arg1="${nodeName}" arg2="DefaultNode"/>
        </condition>
        <wscmtlog>after condition nodeNameIsDefaultNode is now ${nodeNameIsDefaultNode}</wscmtlog>
        <!-- Set continueRenameNode if the node name is not DefaultNode 
             because the node move operation to rename the node must be 
             done. -->
        <condition property="continueRenameNode">
          <not>
            <isset property="nodeNameIsDefaultNode"/>
          </not>
        </condition>
        <wscmtlog>after condition continueRenameNode is now ${continueRenameNode}</wscmtlog>
    </target>

    <!-- Determine whether the cell name specified by the user
         is the (default) string "AdvancedDeploymentCell". If it is, 
         there will not be any need to rename the cell directory, because when
         it is created, its name is "AdvancedDeploymentCell" already. -->
    <target name="detectDefaultCellName"
      description="Detects if the cell name is AdvancedDeploymentCell" >
        <wscmtlog>Starting detectDefaultCellName with cellName ${cellName}</wscmtlog>
        <!-- Set cellNameIsDefaultCell true if the cell name is 
             AdvancedDeploymentCell. -->
        <condition property="cellNameIsDefaultCell">
            <equals arg1="${cellName}" arg2="AdvancedDeploymentCell"/>
        </condition>
        <wscmtlog>after condition cellNameIsDefaultCell is now ${cellNameIsDefaultCell}</wscmtlog>
        <!-- Set continueRenameCell if the cell name is not 
             AdvancedDeploymentCell because the cell move operation to 
             rename the cell must be done. -->
        <condition property="continueRenameCell">
          <not>
            <isset property="cellNameIsDefaultCell"/>
          </not>
        </condition>
        <wscmtlog>after condition continueRenameCell is now ${continueRenameCell}</wscmtlog>
    </target>

    <target name="detectCurrentOSFamily"
            description="Detects the current OS family (UNIX or Windows)">
        
        <wscmtlog>OS name is ${os.name}</wscmtlog>

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

        <!-- Determine if the OS is HP. -->
        <condition property="resetJvmArgumentsForHP" value="true">
            <equals arg1="${os.name}" arg2="HP-UX"/>
        </condition>

        <!-- Determine if the OS is Sun. -->
        <condition property="resetJvmArgumentsForSun" value="true">
            <equals arg1="${os.name}" arg2="SunOS"/>
        </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="Detecs 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>
        
        <!-- z/OS setting must come before the unix setting -->
        <condition property="isCurrentOSzOS" value="true">
            <os family="z/os"/>
        </condition>

        <condition property="isCurrentOSOS400orZOS" value="true">
          <or>
            <equals arg1="${os.name}" arg2="OS/400"/>
            <os family="z/os"/>
          </or>
        </condition>
        
        <condition property="isCurrentOSWindows" value="true">
            <os family="windows"/>
        </condition>
        
        <condition property="isCurrentOSUNIX" value="true">
            <os family="unix"/>
        </condition>
    </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>

    <!-- Note that the use of the condition if="continueRenameCell" will keep 
         this task from running if the node path with a cell name of 
         AdvancedDeploymentCell already exists. There is no need to run the 
         task because the cel directory already matches the incoming node 
         name. -->
    <target name="renameCellDirectoryToMatchCellName"
      description="Renames the cell directory to match the incoming cell name"
      if="continueRenameCell">
        <wscmtlog>Starting renameCellDirectoryToMatchCellName</wscmtlog>
            
        <!-- the move is done through a tmp file name to avoid an ant bug
             that causes move to fail when the source and target only differ in case -->
        <move toDir="${profilePath}/config/cells/tmp${cellName}">
            <fileset dir="${profilePath}/config/cells/AdvancedDeploymentCell"/>
        </move>
        <move toDir="${profilePath}/config/cells/${cellName}">
            <fileset dir="${profilePath}/config/cells/tmp${cellName}"/>
        </move>
    </target>
    
    <!-- Note that the use of the condition if="continueRenameNode" will keep 
         this task from runinng if the node path with a node name of 
         DefaultNode already exists. There is no need to run the task because
         the node directory already matches the incoming node name. -->
    <target name="renameNodeDirectoryToMatchNodeName"
      description="Renames the node directory to match the incoming node name"
      if="continueRenameNode">
            
        <!-- the move is done through a tmp file name to avoid an ant bug
             that causes move to fail when the source and target only differ in case -->
        <move toDir="${profilePath}/config/cells/${cellName}/nodes/tmp${nodeName}">
            <fileset dir="${profilePath}/config/cells/${cellName}/nodes/DefaultNode"/>
        </move>
        <move toDir="${profilePath}/config/cells/${cellName}/nodes/${nodeName}">
            <fileset dir="${profilePath}/config/cells/${cellName}/nodes/tmp${nodeName}"/>
        </move>
    </target>
    
    <target name="resolveSetupCmdLineName"
            description="Resolves the name of setupCmdLine script for the current platform">

        <condition property="setupCmdLineName" value="setupCmdLine">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>

        <condition property="setupCmdLineName" value="setupCmdLine.sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="setupCmdLineName" value="setupCmdLine.bat"> 
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
            
        <wscmtlog>Detected setupCmdLine script name to be: ${setupCmdLineName}</wscmtlog>
    </target>
    
    <target name="resolveWASHomeForOSShellScripts"
            description="Sets the property WAS_HOME_FOR_OS_SHELL_SCRIPTS with the slash characters set according to the current OS, so that the shell scripts work properly">        
        
        <path id="was.home.id">
            <pathelement location="${WAS_HOME}"/>
        </path>
        
        <pathconvert targetos="${currentOSFamily}" 
            property="WAS_HOME_FOR_OS_SHELL_SCRIPTS" 
            refid="was.home.id"/>
            
        <wscmtlog>WAS_HOME for shell scripts was resolved to be: ${WAS_HOME_FOR_OS_SHELL_SCRIPTS}</wscmtlog>
    </target>   
    
    <target name="resolveWASHomeForPropertyFiles"
            description="Sets the property WAS_HOME_FOR_PROPERTY_FILES with slash characters etc. adjusted for property files">        
        
        <replaceStringRegExp string="${WAS_HOME}"
            regexp="\\"
            value="/"
            property="WAS_HOME_FOR_PROPERTY_FILES_FIRST_PASS"/>
            
        <replaceStringRegExp string="${WAS_HOME_FOR_PROPERTY_FILES_FIRST_PASS}"
            regexp="/:"
            value="\:/"
            property="WAS_HOME_FOR_PROPERTY_FILES"/>
            
        <wscmtlog>WAS_HOME for property files was resolved to be: ${WAS_HOME_FOR_PROPERTY_FILES}</wscmtlog>
    </target>   

    <target name="resolveWASProfileLocationForPropertyFiles"
            description="Sets the property WAS_PROFILE_PATH_FOR_PROPERTY_FILES with slash characters etc. adjusted for property files">        
        
        <replaceStringRegExp string="${profilePath}"
            regexp="\\"
            value="/"
            property="WAS_PROFILE_PATH_FOR_PROPERTY_FILES"/>
         
        <wscmtlog>profilePath for property files was resolved to be: ${WAS_PROFILE_PATH_FOR_PROPERTY_FILES}</wscmtlog>
    </target>   

    <target name="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile"
            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}"
            value="${tokenValue}"/>
    </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="replaceAllNecessaryTokensWithRightValuesForPropertiesFiles"
            description="Bootstrap the wsadmin.properties and soap.client.props files"
            unless="isCurrentOSzOS">

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/properties/soap.client.props"/>
            <param name="token" value="$$(WASROOT)"/>
            <param name="tokenValue" value="${WAS_PROFILE_PATH_FOR_PROPERTY_FILES}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="$$(was.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME_FOR_PROPERTY_FILES}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="$$(instance.root)"/>
            <param name="tokenValue" value="${WAS_PROFILE_PATH_FOR_PROPERTY_FILES}"/>
        </antcall>

    </target>

    <target name="zReplaceAllNecessaryTokensWithRightValuesForPropertiesFiles"
            description="For z/OS only, bootstrap the wsadmin.properties and soap.client.props files using ASCII format"
            if="isCurrentOSzOS">

       <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/properties/soap.client.props"/>
            <param name="token" value="$$(WASROOT)"/>
            <param name="tokenValue" value="${WAS_PROFILE_PATH_FOR_PROPERTY_FILES}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="$$(was.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME_FOR_PROPERTY_FILES}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="$$(instance.root)"/>
            <param name="tokenValue" value="${WAS_PROFILE_PATH_FOR_PROPERTY_FILES}"/>
        </antcall>

    </target>

    
    <target name="replaceAllNecessaryTokensWithRightValuesForAllWCCMFiles"
            description="Bootstrap the entire set of WCCM files">
        
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
            <param name="token" value="$$(was.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
            <param name="token" value="$$(user.install.root)"/>
            <param name="tokenValue" value="${profilePath}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
            <param name="token" value="$$(java.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME}/java"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/serverindex.xml"/>
            <param name="token" value="$$(node.host.name)"/>
            <param name="tokenValue" value="${hostName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/node.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/cell.xml"/>
            <param name="token" value="$$(cell.name)"/>
            <param name="tokenValue" value="${cellName}"/>
        </antcall>

        <!-- D490429: change cellType from DISTRIBUTED to STANDALONE -->
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/cell.xml"/>
            <param name="token" value="cellType=&quot;DISTRIBUTED&quot;"/>
            <param name="tokenValue" value="cellType=&quot;STANDALONE&quot;"/>
        </antcall>
        <!-- D490429 end -->

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/default/server.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/DeveloperServer/server.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/defaultZOS/server.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/default_60X/server.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/defaultZOS_60X/server.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/default/server-component-templates.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/chains/webcontainer-chains.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>
        
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
     		<param name="file" value="${profilePath}/config/templates/chains/sipcontainer-chains.xml"/>
          	<param name="token" value="$$(node.name)"/>
  		<param name="tokenValue" value="${nodeName}"/>
  	  </antcall>

       <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/chains/hamanager-chains.xml"/>
            <param name="token" value="$$(node.name)"/>
            <param name="tokenValue" value="${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="$$(was.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME_FOR_OS_SHELL_SCRIPTS}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="$$(java.install.root)"/>
            <param name="tokenValue" value="${WAS_HOME_FOR_OS_SHELL_SCRIPTS}${separatorFile}java"/>
        </antcall>
        
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="WAS_CELL=$$(cell.name)"/>
            <param name="tokenValue" value="WAS_CELL=${cellName}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="WAS_NODE=$$(node.name)"/>
            <param name="tokenValue" value="WAS_NODE=${nodeName}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="$$(instance.root)"/>
            <param name="tokenValue" value="${profilePath}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
            <param name="token" value="$$(instance.script)"/>
            <param name="tokenValue" value="${profilePath}${separatorFile}bin${separatorFile}${setupCmdLineName}"/>
        </antcall>

    </target>

    <!-- genericJvmArguments should be -Xquickstart only for operating
         systems that use IBM JDKs. Solaris machines should use -client,
         while HP machines should use an empty string. Begin defect 352805 -->

    <target name="replaceJvmArgumentsForSun"
            description="Change genericJvmArguments for Sun machines to -client from -Xquickstart"
            if="resetJvmArgumentsForSun">
        <wscmtlog>replaceJvmArgumentsForSun profilePath is ${profilePath}</wscmtlog>
        <wscmtlog>Path is ${profilePath}/config/templates/servertypes/APPLICATION_SERVER/SERVERS/DeveloperServer/server.xml</wscmtlog>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/DeveloperServer/server.xml"/>
            <param name="token" value="-Xquickstart"/>
            <param name="tokenValue" value="-client"/>
        </antcall>
    </target>
            
    <target name="replaceJvmArgumentsForHP"
            description="Change genericJvmArguments for HP machines to empty from -Xquickstart"
            if="resetJvmArgumentsForHP">
        <wscmtlog>replaceJvmArgumentsForHP profilePath is ${profilePath}</wscmtlog>
        <wscmtlog>Path is ${profilePath}/config/templates/servertypes/APPLICATION_SERVER/SERVERS/DeveloperServer/server.xml</wscmtlog>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/DeveloperServer/server.xml"/>
            <param name="token" value="-Xquickstart"/>
            <param name="tokenValue" value=""/>
        </antcall>
    </target>
    <!-- End defect 352805 -->

    <!-- This target is not used and should be deleted -->
    <target name="zReplaceAllNecessaryTokensWithRightValuesForAllWCCMFiles"
            description="Bootstrap the z-specific entries in WCCM files"
            if="isCurrentOSzOS">

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.daemon.home)"/>
                        <param name="tokenValue" value="${z.daemon.home}"/>
        </antcall>
                        
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.daemon.instance.name)"/>
                        <param name="tokenValue" value="${z.daemon.instance.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.system.name)"/>
                        <param name="tokenValue" value="${z.system.name}"/>
        </antcall>
                        
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.node.short.name)"/>
                        <param name="tokenValue" value="${z.node.short.name}"/>
        </antcall>
            
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.smpe.home)"/>
                        <param name="tokenValue" value="${z.smpe.home}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.config.mount.point)"/>
                        <param name="tokenValue" value="${z.config.mount.point}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.control.proc)"/>
                        <param name="tokenValue" value="${z.control.proc}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.servant.proc)"/>
                        <param name="tokenValue" value="${z.servant.proc}"/>
        </antcall>
            
        
       <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
           <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/variables.xml"/>
                        <param name="token" value="$$(z.daemon.proc)"/>
                        <param name="tokenValue" value="${z.daemon.proc}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/serverindex.xml"/>
                        <param name="token" value="$$(z.server.short.name)"/>
                        <param name="tokenValue" value="${z.server.short.name}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/serverindex.xml"/>
                        <param name="token" value="$$(z.cluster.transition.name)"/>
                        <param name="tokenValue" value="${z.cluster.transition.name}"/>
        </antcall>
                
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/serverindex.xml"/>
                        <param name="token" value="$$(orb.listener.host)"/>
                        <param name="tokenValue" value="${orb.listener.host}"/>
        </antcall>
            
   
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodes/${nodeName}/node.xml"/>
                        <param name="token" value="$$(z.node.short.name)"/>
                        <param name="tokenValue" value="${z.node.short.name}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.cell.short.name)"/>
                        <param name="tokenValue" value="${z.cell.short.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.sysplex.name)"/>
                        <param name="tokenValue" value="${z.sysplex.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.name)"/>
                        <param name="tokenValue" value="${z.daemon.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.ip.name)"/>
                        <param name="tokenValue" value="${z.daemon.ip.name}"/>
        </antcall>
        
            <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.listen.ip.name)"/>
                        <param name="tokenValue" value="${z.daemon.listen.ip.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.ssl.port)"/>
                        <param name="tokenValue" value="${z.daemon.ssl.port}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.ip.port)"/>
                        <param name="tokenValue" value="${z.daemon.ip.port}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.job.name)"/>
                        <param name="tokenValue" value="${z.daemon.job.name}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/nodegroups/DefaultNodeGroup/nodegroup.xml"/>
                        <param name="token" value="$$(z.daemon.dns.option)"/>
                        <param name="tokenValue" value="${z.daemon.dns.option}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/admin-authz.xml"/>
                        <param name="token" value="$$(z.admin.userid)"/>
                        <param name="tokenValue" value="${z.admin.userid}"/>
                </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/admin-authz.xml"/>
                        <param name="token" value="$$(z.config.group)"/>
                        <param name="tokenValue" value="${z.config.group}"/>
                </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/cells/${cellName}/cell.xml"/>
                        <param name="token" value="$$(z.cell.short.name)"/>
                        <param name="tokenValue" value="${z.cell.short.name}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/variables.xml"/>
                        <param name="token" value="$$(z.ctrace.parms)"/>
                        <param name="tokenValue" value="${z.ctrace.parms}"/>
        </antcall>
                
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/variables.xml"/>
                        <param name="token" value="$$(z.smpe.home)"/>
                        <param name="tokenValue" value="${z.smpe.home}"/>
        </antcall>
                
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/variables.xml"/>
                        <param name="token" value="$$(cell.name)"/>
                        <param name="tokenValue" value="${cell.name}"/>
        </antcall>
                
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/variables.xml"/>
                        <param name="token" value="$$(z.cell.short.name)"/>
                        <param name="tokenValue" value="${z.cell.short.name}"/>
        </antcall>
                
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/config/cells/${cellName}/variables.xml"/>
                        <param name="token" value="$$(z.unauthenticated.userid)"/>
                        <param name="tokenValue" value="${z.unauthenticated.userid}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/default/server.xml"/>
            <param name="token" value="$$(LOG_ROOT)"/>
            <param name="tokenValue" value="${profilePath}/logs"/>
        </antcall>  
               
     
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/config/templates/servertypes/APPLICATION_SERVER/servers/defaultZOS/server.xml"/>
            <param name="token" value="$$(LOG_ROOT)"/>
            <param name="tokenValue" value="${profilePath}/logs"/>
        </antcall>  
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/sas.client.props"/>
                        <param name="token" value="$$(z.keyring)"/>
                        <param name="tokenValue" value="${z.keyring}"/>
        </antcall>

                    
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/soap.client.props"/>
                        <param name="token" value="$$(z.keyring)"/>
                        <param name="tokenValue" value="${z.keyring}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
                        <param name="token" value="$$(soap.port)"/>
                        <param name="tokenValue" value="${soap.port}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="$$(profilePath)"/>
            <param name="tokenValue" value="${profilePath}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.smpe.home)"/>
                        <param name="tokenValue" value="${z.smpe.home}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.control.proc)"/>
                        <param name="tokenValue" value="${z.control.proc}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.servant.proc)"/>
                        <param name="tokenValue" value="${z.servant.proc}"/>
        </antcall>

        <wscmtlog>${setupCmdLineName} ${z.servant.proc}</wscmtlog>
        
     </target>

       <target name="setSetupCmdLineFilePermission"
        description="Change file permission back to 755"
        if="isCurrentOSUNIX">
        
        <chmod perm="u+rwx,g+rx-w,o+rx-w" file="${profilePath}/bin/${setupCmdLineName}"/>
    
    </target>    

    <target name="executeNative2Ascii" 
            description="Converts files from native encodings to ASCII with escaped Unicode"
            unless="isCurrentOSOS400orZOS">

        <n2a infile="${profilePath}/properties/wsadmin.properties" outfile="${profilePath}/temp/wsadmin.properties"/>

        <copy file="${profilePath}/temp/wsadmin.properties"
              tofile="${profilePath}/properties/wsadmin.properties"
              overwrite="true"/>

        <n2a infile="${profilePath}/properties/soap.client.props" outfile="${profilePath}/temp/soap.client.props"/>

        <copy file="${profilePath}/temp/soap.client.props"
              tofile="${profilePath}/properties/soap.client.props"
              overwrite="true"/>
    </target>
            
    <target name="executeNative2AsciiOS400" 
            description="Converts files from native encodings to ASCII with escaped Unicode"
            if="isCurrentOSOS400">

        <n2a infile="${profilePath}/properties/wsadmin.properties" outfile="${profilePath}/temp/wsadmin.properties"/>

        <copy file="${profilePath}/temp/wsadmin.properties"
              tofile="${profilePath}/properties/wsadmin.properties"
              overwrite="true"/>

        <n2a infile="${profilePath}/properties/soap.client.props" outfile="${profilePath}/temp/soap.client.props"/>

        <copy file="${profilePath}/temp/soap.client.props"
              tofile="${profilePath}/properties/soap.client.props"
              overwrite="true"/>
    </target>

    <target name="zReplaceAllNecessaryTokensWithRightValuesForAllBatchAndProps"
            description="Bootstrap the z-specific entries in WCCM files"
            if="isCurrentOSzOS">

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/sas.client.props"/>
                        <param name="token" value="$$(z.keyring)"/>
                        <param name="tokenValue" value="${z.keyring}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/soap.client.props"/>
                        <param name="token" value="$$(z.keyring)"/>
                        <param name="tokenValue" value="${z.keyring}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
                        <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
                        <param name="token" value="$$(soap.port)"/>
                        <param name="tokenValue" value="${soap.port}"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFileAscii">
            <param name="file" value="${profilePath}/properties/wsadmin.properties"/>
            <param name="token" value="#com.ibm.ws.scripting.tempdir="/>
            <param name="tokenValue" value="com.ibm.ws.scripting.tempdir=${profilePath}/temp"/>
        </antcall>

        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.smpe.home)"/>
                        <param name="tokenValue" value="${z.smpe.home}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.control.proc)"/>
                        <param name="tokenValue" value="${z.control.proc}"/>
        </antcall>
            
        <antcall target="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
            <param name="file" value="${profilePath}/bin/${setupCmdLineName}"/>
                        <param name="token" value="$$(z.servant.proc)"/>
                        <param name="tokenValue" value="${z.servant.proc}"/>
        </antcall>

        <wscmtlog>${setupCmdLineName} ${z.servant.proc}</wscmtlog>

    </target>

    <target name="bootstrapWCCMFiles"
        description="Bootstrap WCCM Files"
        depends="detectCurrentOSFamily,
            detectDefaultNodeName,
            detectDefaultCellName,
            setCurrentOSFamily,
            setOSFileSeparator,
            resolveWASHomeForOSShellScripts,
            resolveWASHomeForPropertyFiles,
            resolveWASProfileLocationForPropertyFiles,
            resolveSetupCmdLineName,
            renameCellDirectoryToMatchCellName, 
            renameNodeDirectoryToMatchNodeName,
            replaceAllNecessaryTokensWithRightValuesForAllWCCMFiles,
            replaceJvmArgumentsForSun,
            replaceJvmArgumentsForHP,
            replaceAllNecessaryTokensWithRightValuesForPropertiesFiles,
            zReplaceAllNecessaryTokensWithRightValuesForAllBatchAndProps,
            zReplaceAllNecessaryTokensWithRightValuesForPropertiesFiles,
            setSetupCmdLineFilePermission,
            executeNative2AsciiOS400,
            executeNative2Ascii"/>
</project>
