<!DOCTYPE project [
    <!ENTITY importExternalLogs SYSTEM "file:./scripts/importExternalLogs.xml">
]>
<project name="generateProfileKey" default="generateProfileKey" 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;   
    <wscmtlog> The current template path is: ${templatePath}</wscmtlog>
    
    <target name="setProfileType" description="Set the profileType">
        <condition property="profileType" value="DEPLOYMENT_MANAGER">
            <equals arg1="${serverType}" arg2="DEPLOYMENT_MANAGER"/>
        </condition>
        <condition property="profileType" value="ADMIN_AGENT">
            <equals arg1="${serverType}" arg2="ADMIN_AGENT"/>
        </condition>
        <condition property="profileType" value="JOB_MANAGER">
            <equals arg1="${serverType}" arg2="JOB_MANAGER"/>
        </condition>
        <wscmtlog> profile type used is: ${profileType}</wscmtlog>
    </target>

    <target name="doGenerateProfileKey" 
        description="Generate a profile key for the given profile, profileName+profileType+UUID">

        <wscmtlog>Generate a profile key for the profile ${profilePath}</wscmtlog>
           <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->     
        <wsadmin conntype="none"
            lang="jacl"
            failonerror="false"
			returnproperty="rcProperty"
            tracefile="${WS_CMT_LOG_HOME}/${profileName}/generateProfileKey.log"
            wasHome="${WAS_HOME}"
            wasInstallRoot="${WAS_HOME}"
            wasRepositoryRoot="${profilePath}/config"
            userInstallRoot="${profilePath}"
            localCell="${cellName}"
            localNode="${nodeName}"
            wsadminProps="${profilePath}/properties/wsadmin.properties"
            command="$AdminTask generateProfileKey {-properties &quot; {{com.ibm.ws.profile.name ${profileName}} {com.ibm.ws.profile.type ${profileType}} {com.ibm.ws.profile.path {${profilePath}}}}&quot;}"
            ipcFilename="${profilePath}/temp/wsadmin">
        </wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/generateProfileKey.log" />
            <param name="description" value="Generating a profile key for the profile ${profilePath}" />
            <param name="precondition" value="foetrue" />
        </antcall>      
        <wscmtlog> The profile key has successfully generated </wscmtlog>

    </target>
  
    <target name="generateProfileKey"
        description="generate the profile key for the profile just being created"
        depends="setProfileType,
                 doGenerateProfileKey"/>  
</project>
