<project name="convertCodepageForProfileBatchFiles" default="convertCodepageForProfileBatchFiles" basedir=".">
    
    <taskdef name="wscmtlog"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>
    <taskdef name="foreach"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.ForEachAntTask"/>
    <taskdef name="detectlocale"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.DetectLocaleAntTask"/>    
    <taskdef name="autoconvertencoding"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AutomaticCodePageConversionAntTask"/>    

    <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="defineLocale"
            description="Defines locale">

        <detectlocale property="currentLocale"/>
                            
        <condition property="detectedLocaleFlag" value="true">
              <equals arg1="${currentLocale}" arg2="en_US"/>              
        </condition>       
    </target>
    
    <target name="convertFileEncoding"
            description="Convert file encoding"
            if="configWindows">

        <fileset dir="${profilePath}\bin" id="batch.fileset">
                       <include name="*.bat"/>
        </fileset>

        <pathconvert pathsep=","
                     property="batch.files"
                     refid="batch.fileset"/>

        <foreach list="${batch.files}" propertyName="batch.file" target="convertEncoding"/>
    </target>
    
    
    <target name="convertEncoding"
            unless="detectedLocaleFlag">
        <autoconvertencoding path="${batch.file}"/>    
    </target>
    
    <target name="convertCodepageForProfileBatchFiles"
        description="Convert the codepage for batch files in profile bin directory"
        if="configWindows"
        depends="detectCurrentOSFamily,
            defineOSSpecificConfigFlag,
            defineLocale,
            convertFileEncoding"/>    

</project>
