<project name="deploySIBManaged" default="deploySIBManaged" 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="wsadmin" classname="com.ibm.websphere.ant.tasks.WsAdminInProcess"/>

  <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="runSIBDefineChainsJACL"
    description="Runs the JACL script to update the default server template with the SIB transport chains">

    <wscmtlog>
      Defining SIB transport chains and ports in the default server template, the output will be recorded in: ${WS_CMT_LOG_HOME}/${profileName}/SIBDefineChains.log
    </wscmtlog>

    <echo>${profileName}</echo>
    <echo>user.install.root value=${profilePath}</echo>
    <echo>was.install.root value=${WAS_HOME}</echo>
    <echo>was.repository.root value=${profilePath}/config</echo>
    <echo>local.cell value=${cellName}</echo>
    <echo>local.node value=${nodeName}</echo>

    <wsadmin
      conntype="none"
      failonerror="true"
      tracefile="${WS_CMT_LOG_HOME}/${profileName}/SIBDefineChains.log"
      wasHome="${WAS_HOME}"
      wasInstallRoot="${WAS_HOME}"
      wasRepositoryRoot="${profilePath}/config"
      userInstallRoot="${profilePath}"
      localCell="${cellName}"
      localNode="${nodeName}"
      wsadminProps="${profilePath}/properties/wsadmin.properties"
      script="${templatePath}/actions/scripts/sibdefinechains.jacl"
      lang="jacl"
      ipcFilename="${profilePath}/temp/wsadmin">

      <arg value="${nodeName}"/>

    </wsadmin>

  </target>

  <target name="runSIBGenericDeployRAsJACL" 
          description="Runs the JACL script to deploy the SIB component RAs">

    <wscmtlog>Adding SIB JMS RA and WebSphere MQ RA to the Cell, Node, Servers and server templates, the output will be recorded in: ${WS_CMT_LOG_HOME}/${profileName}/SIBGenericDeployRAs.log</wscmtlog>

    <wsadmin
      conntype="none"
      failonerror="true"
      tracefile="${WS_CMT_LOG_HOME}/${profileName}/SIBGenericDeployRAs.log"
      wasHome="${WAS_HOME}"
      wasInstallRoot="${WAS_HOME}"
      wasRepositoryRoot="${profilePath}/config"
      userInstallRoot="${profilePath}"
      localCell="${cellName}"
      localNode="${nodeName}"
      wsadminProps="${profilePath}/properties/wsadmin.properties"
      script="${templatePath}/actions/scripts/sibgenericdeployRAs.jacl"
      lang="jacl"
      ipcFilename="${profilePath}/temp/wsadmin">
      <arg value="${nodeName}"/>
      <arg value="true"/>
      <arg value="true"/>
    </wsadmin>

  </target>
	  
  <target name="resolveProfilePathForPropertyFiles">
       
      <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"/>
           
  </target>

  <target
    name="deploySIBManaged"
    description="Configures templates for SIB managed (custom) profiles"
    depends="runSIBDefineChainsJACL, runSIBGenericDeployRAsJACL, resolveProfilePathForPropertyFiles">

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

    <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>

