<!DOCTYPE project [
    <!ENTITY importExternalLogs SYSTEM "file:./scripts/importExternalLogs.xml">
]>
<project name="defaultAppDeployAndConfigCell" default="defaultAppDeployAndConfigCell" basedir=".">

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

    <taskdef name="wsadmin" classname="com.ibm.websphere.ant.tasks.WsAdminInProcess"/>   
       &importExternalLogs;  			
    <property name="appServerServerName" value="server1"/>

    <target name="zSetServerName"
            description="For z/OS only, set serverName to user provided value" if="isCurrentOSzOS">

         <property name="appServerServerName" value="${appServerServerName}"/>

    </target>

    <target name="detectCurrentOSFamily"
            description="Detects 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>

        <!-- z/OS setting must come before the unix setting -->
        <condition property="currentOSFamily" value="z/os">
            <os family="z/os"/>
        </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="Sets the current OS Family">
        
        <!-- 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="isCurrentOSWindows" value="true">
            <os family="windows"/>
        </condition>
        
        <condition property="isCurrentOSUNIX" value="true">
            <os family="unix"/>
        </condition>
    </target>

    <target name="defineOSSpecificConfigFlag"
            description="Defines either configUNIX or configWindows depending on the current OS">
            
        <condition property="configOS400" value="true">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>

        <condition property="configZOS" value="true">
            <equals arg1="${currentOSFamily}" arg2="z/os"/>
        </condition>
        
        <condition property="configUNIX" value="true">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="configWindows" value="true">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
    </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="deployDefaultApp"
            description="Deploys Default Enterprise Application"
            >
            
        <wscmtlog>Deploying DefaultApp EAR, the output will be recorded in: ${WS_CMT_LOG_HOME}/${profileName}/defaultapp_deploy.log</wscmtlog>
          <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->                
        <wsadmin conntype="none"
                 failonerror="false"
                 returnproperty="rcProperty"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/defaultapp_deploy.log"
                 appendTrace="true"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 command="$AdminApp install &quot;${WAS_HOME_UNIX_STYLE}/installableApps/DefaultApplication.ear&quot; {-node ${appServerNodeName} -server ${appServerServerName} -nocreateMBeansForResources -appname DefaultApplication -installed.ear.destination &quot;$(APP_INSTALL_ROOT)/$(CELL)&quot;}"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
        </wsadmin>
        <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/defaultapp_deploy.log" />
            <param name="description" value="Deploying DefaultApp EAR" />
            <param name="precondition" value="foetrue" />
        </antcall>	
    </target>      
      
    <target name="configDefaultApp"
            description="Configures Default Enterprise Application">
            
        <wscmtlog>Configuring DefaultApp datasource, the output will be recorded in: ${profilePath}/logs/defaultapp_config.log</wscmtlog>
           <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->               
        <wsadmin conntype="none"
                 failonerror="false"
                 returnproperty="rcProperty"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/defaultapp_config.log"
                 appendTrace="true"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 script="${templatePath}/actions/scripts/configureDefaultApplication.jacl"
                 lang="jacl"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                <arg value="${appServerNodeName}"/>
                <arg value="${appServerServerName}"/>
        </wsadmin> 
        <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/defaultapp_config.log" />
            <param name="description" value="Configuring DefaultApp datasource" />
            <param name="precondition" value="foetrue" />
        </antcall>	
    </target>

    <target name="defaultAppDeployAndConfigCell"
        description="Configures Cloudscape"
        depends="detectCurrentOSFamily,
            setCurrentOSFamily,
            zSetServerName,
            defineOSSpecificConfigFlag,
            convertWASHomeToUNIXStylePath,
            deployDefaultApp,
            configDefaultApp"/>
</project>
