<project name="aboutThisProfileManagement" default="aboutThisProfileManagement" 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.ManagementProfileTemplateResourceBundle"/>
        
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.type" param="" property="profileSummaryType"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="Management.name" param="" property="profileSummaryTypeValue"/>
        <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.cellname" param="" property="profileSummaryCellName"/>
        <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.adminsecurity" param="" property="profileSummaryAdminSecurity"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.adminconsole" param="" property="profileSummaryAdminConsole"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.adminconsole.secure" param="" property="profileSummaryAdminConsoleSecure"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.bootstrap.management" param="" property="profileSummaryBootstrap"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.port.soap.management" param="" property="profileSummarySOAP"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.service.management" param="" property="profileSummaryService"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.true" param="" property="profileSummaryTrue"/>
        <resourcebundle resourceBundleName="${BUNDLE_NAME}" resourceBundleKey="ProfileSummary.false" param="" property="profileSummaryFalse"/>

    </target>

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

        <property file="${profilePath}/properties/portdef.props"/>
       
        <property name="adminConsolePort" value="${WC_adminhost}"/>
        <property name="adminConsoleSecurePort" value="${WC_adminhost_secure}"/>
	<property name="bootstrapPort" value="${BOOTSTRAP_ADDRESS}"/>
	<property name="SOAPPort" value="${SOAP_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="isAdminSecuritySet" value="${profileSummaryTrue}">
            <equals arg1="${enableAdminSecurity}" arg2="true"/>
        </condition>
        <condition property="isAdminSecuritySet" value="${profileSummaryFalse}">
        	<not>
            <equals arg1="${enableAdminSecurity}" arg2="true"/>
          </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>
        
        
        <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">${profileSummaryCellName} ${cellName}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryHostName} ${hostName}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryAdminSecurity} ${isAdminSecuritySet}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryAdminConsole} ${adminConsolePort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryAdminConsoleSecure} ${adminConsoleSecurePort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryBootstrap} ${bootstrapPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummarySOAP} ${SOAPPort}${CRLF}</echo>
        <echo file="${profilePath}/logs/AboutThisProfile.txt" append="true">${profileSummaryService} ${isRunAsServiceSet}${CRLF}</echo>

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