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

    <taskdef name="wscmtlog"
        classname="com.ibm.ws.install.configmanager.actionengine.ant.utils.AntTaskToLogToConfigManagersLogFiles"/>

    <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="setCurrentOSFamily"
            description="Detects the current OS family (UNIX or Windows)">
        
        <!-- OS/400 setting must come before the unix setting -->
        <condition property="isCurrentOSOS400" value="true">
            <equals arg1="${os.name}" arg2="OS/400"/>
        </condition>
        
        <condition property="isCurrentOSWindows" value="true">
            <os family="windows"/>
        </condition>
        
        <condition property="isCurrentOSUNIX" value="true">
            <os family="unix"/>
        </condition>
    </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="resolveOsgiCfgInitExecutableForTheCurrentPlatform"
            description="Sets OSGI_CFG_INIT to the right script for the current platform">
            
        <condition property="OSGI_CFG_INIT" value="${WAS_HOME}/bin/osgiCfgInit">
            <equals arg1="${currentOSFamily}" arg2="os/400"/>
        </condition>
        
        <condition property="OSGI_CFG_INIT" value="${WAS_HOME}/bin/osgiCfgInit.sh">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="OSGI_CFG_INIT" value="${WAS_HOME}/bin/osgiCfgInit.bat">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
        
        <wscmtlog>osgiCfgInit interpretor set to: ${OSGI_CFG_INIT}</wscmtlog>
    </target>    

    <target name="runOsgiCfgInit"
            description="initializes OSGi for the profile">
            
        <exec executable="${OSGI_CFG_INIT}"
                output="${WS_CMT_LOG_HOME}/${profileName}/osgi_cfg_init.log" failonerror="false">
            <arg value="default"/>
		<env key="WAS_USER_SCRIPT" value="${profilePath}/bin/${setupCmdLineName}"/>
            <env key="PROFILE_CONFIG_ACTION" value="true"/>
        </exec>
        
        <wscmtlog>Done.</wscmtlog>
    </target>

    <target name="osgiCfgInit"
        description="Initialize OSGi Configuration"
        depends="detectCurrentOSFamily,
            setCurrentOSFamily,
            resolveOsgiCfgInitExecutableForTheCurrentPlatform,
                resolveSetupCmdLineName,
                runOsgiCfgInit"/>

</project>

