<project name="proxyWebuiConfig" default="proxyWebuiConfig" basedir=".">
    
    <taskdef name="wscmtlog"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>
                
    <property name="NODE_NAME" value="${WS_CMT_NODE_NAME}"/>
    <property name="CELL_NAME" value="${WS_CMT_CELL_NAME}"/>
    <property name="serverName" value="dmgr"/>

    <target name="detectCurrentOSFamily"
            description="Detecs 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>
        
        <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>
        
        <condition property="distributed" value="true">
            <not> 
                 <equals arg1="${currentOSFamily}" arg2="z/OS"/>
            </not>
        </condition>
        
        <condition property="isZOS" value="true">
            <equals arg1="${currentOSFamily}" arg2="z/OS"/>
        </condition>
        
        <wscmtlog>Detected current OS family to be: ${currentOSFamily}</wscmtlog>
    </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>

    <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="resolveSetupCmdLineName">
        <available property="setupCmdLineName"
            value="setupCmdLine"
            file="${WAS_HOME}/bin/setupCmdLine"/>

        <available property="setupCmdLineName"
            value="setupCmdLine.bat"
            file="${WAS_HOME}/bin/setupCmdLine.bat"/>

        <available property="setupCmdLineName"
            value="setupCmdLine.sh"
            file="${WAS_HOME}/bin/setupCmdLine.sh"/>

        <wscmtlog>Detected setupCmdLine script name to be: ${setupCmdLineName}</wscmtlog>
    </target>    

    <target name="undeployProxyAdminConsole"
            description="Unregisters proxy console plugin" if="distributed">
            
        <wscmtlog>Unregistering proxy console plugin, the output will be recorded in: ${WAS_HOME}/logs/proxy_uninstall_webui_config.log</wscmtlog>
            
        <replaceregexp file="${WAS_HOME}/features/com.ibm.ws.nd_6.0.0.0/feature.xml"
			match="(.*)com.ibm.ws.console.proxy(.*)"
			replace=""
			byline="true"/>
    </target>
    
    <target name="undeployProxyAdminConsoleZOS"
            description="Unregisters proxy console plugin" if="isZOS">

        <taskdef name="changeFileEncoding" classname="com.ibm.ws390.utility.ChangeFileEncoding"/>            
            
        <wscmtlog>Unregistering proxy console plugin, the output will be recorded in: ${WAS_HOME}/logs/proxy_uninstall_webui_config.log</wscmtlog>
        
        <changeFileEncoding verbose="false" pathname="${WAS_HOME}/features/com.ibm.ws.nd_6.0.0.0/feature.xml" currentEncoding="ISO8859_1" newEncoding="Cp1047" />
                    
        <replaceregexp file="${WAS_HOME}/features/com.ibm.ws.nd_6.0.0.0/feature.xml"
			match="(.*)com.ibm.ws.console.proxy(.*)"
			replace=""
			byline="true"/>
			
		<changeFileEncoding verbose="false" pathname="${WAS_HOME}/features/com.ibm.ws.nd_6.0.0.0/feature.xml" currentEncoding="Cp1047" newEncoding="ISO8859_1" />
			
    </target>

    <target name="proxyWebuiConfig"
        description="Configures proxy webui"
        depends="detectCurrentOSFamily,
            setOSFileSeparator,
            convertWASHomeToUNIXStylePath,
            resolveSetupCmdLineName,
            undeployProxyAdminConsole,
            undeployProxyAdminConsoleZOS"/>
</project>
