<project name="aboutThisProfileSecureProxy" default="aboutThisProfileSecureProxy" basedir=".">

    <taskdef name="wscmtlog" 
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>
    <taskdef name="resourcebundle" classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.ResourceBundleAntTask"/> 
    <taskdef name="isFirstProfile" classname="com.ibm.ws.profile.anttasks.IsFirstProfile"/>

    <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="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="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="configUNIX" value="true">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="configWindows" value="true">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
    </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="setOSCRLFSequence"
            description="Sets CRLF to whatever is the appropriate CRLF sequence for this platform">

        <condition property="CRLF" value="&#10;">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>
        <condition property="CRLF" value="&#10;">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        <condition property="CRLF" value="&#13;&#10;">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
    </target>

    <target name="resolveResourceBundleStrings"
            description="Resolves NL text for the key properties used to create this profile">
        <property name="BUNDLE_NAME" value="com.ibm.ws.profiletemplates.resourcebundle.SecureProxyProfileTemplateResourceBundle"/>
        
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="SecureProxy.name" param="" property="profileSummaryTypeValue"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.type" param="" property="profileSummaryType"/>        
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.location" param="" property="profileSummaryLocation"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.diskspace" param="" property="profileSummaryDiskSpace"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.diskspace.suffix" param="" property="profileSummaryDiskSpaceSuffix"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.name" param="" property="profileSummaryName"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.isdefault" param="" property="profileSummaryIsDefault"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.nodename" param="" property="profileSummaryNodeName"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.hostname" param="" property="profileSummaryHostName"/>        
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.http" param="" property="profileSummaryHTTP"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.https" param="" property="profileSummaryHTTPS"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.ipc" param="" property="profileSummaryIPC"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.service.secureproxy" param="" property="profileSummaryService"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.true" param="" property="profileSummaryTrue"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.false" param="" property="profileSummaryFalse"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.sip" param="" property="profileSummarySIP"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.sips" param="" property="profileSummarySIPS"/>
                
    </target>

    <target name="resolvePorts"
            description="Resolves the key ports used to create this profile">

        <property file="${profilePath}/properties/portdef.props"/>
						  
			  <property name="HTTPPort" value="${PROXY_HTTP_ADDRESS}"/>
			  <property name="HTTPSPort" value="${PROXY_HTTPS_ADDRESS}"/>
			  
			  <property name="SIPPort" value="${PROXY_SIP_ADDRESS}"/>
			  <property name="SIPSPort" value="${PROXY_SIPS_ADDRESS}"/>
			  
			  <property name="IPCPort" value="${IPC_CONNECTOR_ADDRESS}"/>
    </target>

    <target name="generateProfileInformationFile"
            description="Generates an information file for the key properties used to create this profile">
            
        <isFirstProfile property="firstProfile"/>    
        <condition property="isDefaultSet" value="${profileSummaryTrue}">
            <or>
            	<equals arg1="${firstProfile}" arg2="true"/>
            	<isset property="isDefault"/>
            </or>
        </condition>
        <condition property="isDefaultSet" value="${profileSummaryFalse}">
          <not>
            <or>
            	<equals arg1="${firstProfile}" arg2="true"/>
            	<isset property="isDefault"/>
            </or>
          </not>
        </condition>
        <condition property="isRunAsServiceSet" value="${profileSummaryTrue}">
          <or>
            <equals arg1="${winserviceCheck}" arg2="true"/>
            <equals arg1="${enableService}" arg2="true"/>
          </or>
        </condition>
        <condition property="isRunAsServiceSet" value="${profileSummaryFalse}">
        	<not>
            <or>
              <equals arg1="${winserviceCheck}" arg2="true"/>
              <equals arg1="${enableService}" arg2="true"/>
            </or>
          </not>
        </condition>
        <condition property="isWebServerSet" value="${profileSummaryTrue}">
            <equals arg1="${webServerCheck}" arg2="true"/>
        </condition>
        <condition property="isWebServerSet" value="${profileSummaryFalse}">
        	<not>
            <equals arg1="${webServerCheck}" arg2="true"/>
          </not>
        </condition>
        
        
  			<xmlproperty file="${templatePath}/templateMetadata.xml"/>
			  <property name="profileSummaryDiskSpaceSize" value="${profileTemplate.size}"/>

       	<echo file="${profilePath}/logs/AboutThisProfile.txt" append="false">${profileSummaryType} ${profileSummaryTypeValue}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryLocation} ${profilePath}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryDiskSpace} ${profileSummaryDiskSpaceSize} ${profileSummaryDiskSpaceSuffix}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryName} ${profileName}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryIsDefault} ${isDefaultSet}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryNodeName} ${nodeName}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryHostName} ${hostName}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryHTTP} ${HTTPPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryHTTPS} ${HTTPSPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummarySIP} ${SIPPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummarySIPS} ${SIPSPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryIPC} ${IPCPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryService} ${isRunAsServiceSet}${CRLF}</echo>

    </target>
        
    <target name="aboutThisProfileSecureProxy"
        description="Generates an information file for the key properties used to create this profile"
        depends="detectCurrentOSFamily,
            defineOSSpecificConfigFlag,
            setOSFileSeparator,
            setOSCRLFSequence,
            resolveResourceBundleStrings,
            resolvePorts,
            generateProfileInformationFile"/>                      
</project>
