<!DOCTYPE project [
    <!ENTITY importExternalLogs SYSTEM "file:./scripts/importExternalLogs.xml">
]>
<project name="webuiConfig" default="webuiConfig" 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="NODE_NAME" value="${WS_CMT_NODE_NAME}"/>
    <property name="CELL_NAME" value="${WS_CMT_CELL_NAME}"/>
   
    
    <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>
    

    <!--  LI 4405 - addition of config archives to profile creation - eWAS logic     -->
    <!--         eWAS requires that the Admin Console be installed from this action  -->
    <!--         set the isEmbed property if the following file does not exist       -->


    <target name="detectProductLevel">
      <!-- The existance of the WAS.product file tells us we are on a full WAS Base install.
           Otherwise we are on the Embed product.  EWAS.product should exist instead. -->
      <condition property="isEmbed">
         <not>
            <available file="${WAS_HOME}/properties/version/WAS.product"/>
         </not>
      </condition> 
   </target>

    <!--   LI 4405  insert end - only execute targets IFF isEmbed is set          -->

    <target name="deployAdminConsole"
            description="Deploys Admin Console" 
	    if="isEmbed">
            
        <echo>  isEmbed indicates WAS Embedded </echo>

        <wscmtlog>Deploying admin console, the output will be recorded in: ${WAS_HOME}/logs/webui_config.log</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}/webui_config.log"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                 <command value="$AdminApp install &quot;${WAS_HOME_UNIX_STYLE}/systemApps/isclite.ear&quot; {-node ${NODE_NAME} -server ${serverName} -appname isclite -copy.sessionmgr.servername ${serverName} -zeroEarCopy -skipPreparation -installed.ear.destination $(WAS_INSTALL_ROOT)/systemApps }"/>
                 <command value="$$AdminConfig save"/>
                 <command value="$AdminApp edit isclite { -MapWebModToVH {{.* .* admin_host}}}"/>
                 <command value="$$AdminConfig save"/>
        </wsadmin> 
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/webui_config.log" />
            <param name="description" value="Deploying admin console" />
            <param name="precondition" value="foetrue" />
        </antcall>   		
    </target>

    <target name="copyWebXML"
            description="Copy web xml from install to profile location" 
	    unless="isEmbed">
        	<wscmtlog>Copying web.xml to profile location. From ${WAS_HOME_UNIX_STYLE}/systemApps/isclite.ear/isclite.war/WEB-INF/web.xml 
         		to ${profilePath}/config/cells/${cellName}/applications/isclite.ear/deployments/isclite/isclite.war/WEB-INF/web.xml</wscmtlog>
         	<copy 
         		file="${WAS_HOME_UNIX_STYLE}/systemApps/isclite.ear/isclite.war/WEB-INF/web.xml" 
         		tofile="${profilePath}/config/cells/${cellName}/applications/isclite.ear/deployments/isclite/isclite.war/WEB-INF/web.xml" 
         		overwrite="true" failonerror="false"/>   
    </target>

    <target name="setCellVar" description="Sets a cell-scoped variable named WAS_CELL_NAME"
		if="isEmbed">
         <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->   
        <wsadmin conntype="none"
                 failonerror="false"
				 returnproperty="rcProperty"
				 lang="jacl"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/webui_config.log"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                 <command value="set varMap [$$AdminConfig getid /Cell:${CELL_NAME}/VariableMap:/]"/>
                 <command value="set nameattr1 [list symbolicName WAS_CELL_NAME]"/>
                 <command value="set valattr1 [list value ${CELL_NAME}]"/>
                 <command value="set attr1 [list $nameattr1 $valattr1]"/>
                 <command value="set attrs [list $attr1]"/>
                 <command value="$$AdminConfig modify $$varMap [subst {{entries {$$attrs}}}]"/>
                 <command value="$$AdminConfig save"/>
        </wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/webui_config.log" />
            <param name="description" value="Copying web.xml to profile location." />
            <param name="precondition" value="foetrue" />
        </antcall> 
    </target>

    
    <target name="updateDeploymentXml"
            description="Updates the deployment.xml to add a sharedLibBypass property"
	    if="isEmbed">
            
        <wscmtlog>Updating deployment.xml, the output will be recorded in: ${WAS_HOME}/logs/deploy_config.log</wscmtlog>
         <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->           
        <wsadmin conntype="none"
                 failonerror="false"
				 returnproperty="rcProperty"
				 lang="jacl"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log"
                 appendTrace="true"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                 <command value="set deployment [$AdminConfig getid /Deployment:isclite/]"/>
                 <command value="set appDeploy [$AdminConfig showAttribute $deployment deployedObject]"/>
                 <command value="set nameAttr [list name com.ibm.ws.classloader.sharedLibBypass]"/>
                 <command value="set valueAttr [list value true]"/>
                 <command value="set reqAttr [list required false]"/>
                 <command value="set propAttr [list $nameAttr $valueAttr $reqAttr]"/>
                 <command value="$AdminConfig create Property $appDeploy $propAttr"/>
                 <command value="$$AdminConfig save"/>
                 <command value="set attr1 [list enableSecurityIntegration false]"/>
                 <command value="set attrs [list $attr1]"/>
                 <command value="set configs [lindex [$AdminConfig showAttribute $appDeploy configs] 0]"/>
                 <command value="set appConfig [lindex $configs 0]"/>
                 <command value="set SM [$AdminConfig showAttribute $appConfig sessionManagement]"/>
                 <command value="$$AdminConfig modify $SM $attrs"/>
                 <command value="set theCookie [$AdminConfig showAttribute $SM defaultCookieSettings]"/>
                 <command value="$$AdminConfig modify $theCookie {{path /ibm}}"/>
                 <command value="$$AdminConfig save"/>
        </wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log" />
            <param name="description" value="Updating deployment.xml" />
            <param name="precondition" value="foetrue" />
        </antcall> 
    </target>

    
    <target name="setupIehs" description="sets the classloader for iehs.war to PARENT_LAST"
		if="isEmbed">

        <wscmtlog>Setting IEHS classloader to PARENT_LAST, the output will be recorded in: ${WAS_HOME}/logs/webui_config.log</wscmtlog>
         <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->   
        <wsadmin conntype="none"
                 failonerror="false"
				 returnproperty="rcProperty"
				 lang="jacl"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log"
                 appendTrace="true"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                 <command value="set isclite [$$AdminConfig getid /Deployment:isclite/]"/>
                 <command value="set iscliteDepObject [$$AdminConfig showAttribute $$isclite deployedObject]"/>
                 <command value="set modules [lindex [$$AdminConfig showAttribute $$iscliteDepObject modules] 0]"/>
                 <command value="foreach module $$modules { if {[regexp iehs [$$AdminConfig showAttribute $$module uri]] == 1} {$$AdminConfig modify $$module {{classloaderMode PARENT_LAST}}}}"/>
                 <command value="$$AdminConfig save"/>
        	</wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log" />
            <param name="description" value="Setting IEHS classloader to PARENT_LAST" />
            <param name="precondition" value="foetrue" />
        </antcall> 
    </target>

    <target name="setupIsclite" description="sets the classloader for isclite.war to PARENT_LAST"
		if="isEmbed">

        <wscmtlog>Setting ISCLITE classloader to PARENT_LAST, the output will be recorded in: ${WAS_HOME}/logs/webui_config.log</wscmtlog>
         <!-- fail on error was true, but changed to false to accomodate F69142-65189 -->   
        <wsadmin conntype="none"
                 failonerror="false"
				 returnproperty="rcProperty"
				 lang="jacl"
                 tracefile="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log"
                 appendTrace="true"
                 wasHome="${WAS_HOME}"
                 wasInstallRoot="${WAS_HOME}"
                 wasRepositoryRoot="${profilePath}/config"
                 userInstallRoot="${profilePath}"
                 localCell="${cellName}"
                 localNode="${nodeName}"
                 wsadminProps="${profilePath}/properties/wsadmin.properties"
                 ipcFilename="${profilePath}/temp/wsadmin"
                 >
                 <command value="set isclite [$$AdminConfig getid /Deployment:isclite/]"/>
                 <command value="set iscliteDepObject [$$AdminConfig showAttribute $$isclite deployedObject]"/>
                 <command value="set modules [lindex [$$AdminConfig showAttribute $$iscliteDepObject modules] 0]"/>
                 <command value="foreach module $$modules { if {[regexp isclite [$$AdminConfig showAttribute $$module uri]] == 1} {$$AdminConfig modify $$module {{classloaderMode PARENT_LAST}}}}"/>
                 <command value="$$AdminConfig save"/>
        	</wsadmin>
         <antcall target="importLogsToMain" >
            <param name="logfile" value="${WS_CMT_LOG_HOME}/${profileName}/deploy_config.log" />
            <param name="description" value="Setting ISCLITE classloader to PARENT_LAST" />
            <param name="precondition" value="foetrue" />
        </antcall> 
    </target>

    <target name="webuiConfig"
        description="Configures WebUI"
        depends="convertWASHomeToUNIXStylePath,
            detectProductLevel,
            deployAdminConsole,
            copyWebXML,
            setCellVar,
            setupIehs,
            setupIsclite,
            updateDeploymentXml"/>
</project>
