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

   <!--
# IBM Confidential OCO Source Material
# 5639-D57, 5630-A36, 5630-A37, 5724-D18 (C) COPYRIGHT International Business Machines Corp. 1997, 2011
# The source code for this program is not published or otherwise divested
# of its trade secrets, irrespective of what has been deposited with the
# U.S. Copyright Office.
   -->
  
   <!-- 
   ***************************************************************************
   TARGET: updateLogFile
   Log statement to webserver install log
   ***************************************************************************
   -->      
   <target name="updateLogFile"
        description="Update webserver specific logfile">
<echo file="${install.log}" append="true">${stringToAppend}${CRLF}</echo>
   </target>

    <!-- 
    ***************************************************************************
    TARGET: logBoth
    Log statement to both webserver install log and cfg manager log
    ***************************************************************************
    -->      
    <target name="logBoth">
       <echo>${logStatement}</echo>
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="${logStatement}"/>
        </antcall>            
    </target>    

    <!-- 
    ***************************************************************************
    TARGET: logStartupProperties
    Log startup information to the install log
    ***************************************************************************
    -->      
    <target name="logStartupProperties"
            description="Log properties passed to script">
        <property name="install.log" value="${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}installSunOnePlugin.log"/> 
        <mkdir dir="${PLUGIN_HOME}${separatorFile}logs${separatorFile}config"/>
        <touch file="${install.log}"/>
        <tstamp>
           <format property="timestamp" pattern="MM/dd/yyyy hh:mm aa"/>
        </tstamp>
        <antcall target="updateLogFile">
           <param name="stringToAppend" value=" "/>
        </antcall>        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="************************************************************"/>
        </antcall>        
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="** Install SunOne Webserver Plugin ${timestamp}"/>
        </antcall>     
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="************************************************************"/>
        </antcall>        
       
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="PLUGIN_HOME            = ${PLUGIN_HOME}"/>
        </antcall>     
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="SUNONE_MAGNUS_CONF     = ${SUNONE_MAGNUS_CONF} "/>
        </antcall>     
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="SUNONE_OBJ_CONF        = ${SUNONE_OBJ_CONF} "/>
        </antcall>     
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="WAS_PLUGIN_CFG_XML     = ${WAS_PLUGIN_CFG_XML}"/>
        </antcall>     
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="OS_NAME                = ${OS_NAME}"/>
        </antcall> 
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="INSTALLER ARCHITECTURE = ${INSTALL_ARCH}"/>
        </antcall>
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="PLATFORM INFORMATION = ${os.name} ${os.version} - ${os.arch}"/>
        </antcall>
    </target>
    
    <!--
    ***************************************************************************
    TARGET: detectCurrentOSFamily
    Detect current OS Family
    ***************************************************************************
    -->      
    <target name="detectCurrentOSFamily"
            description="Detects the current OS family (UNIX or Windows)">
        
        <condition property="currentOSFamily" value="windows">
            <os family="windows"/>
        </condition>
        
        <condition property="currentOSFamily" value="unix">            
            <os family="unix"/>
        </condition>
        
        <echo>Detected current OS family to be: ${currentOSFamily}</echo>        
    </target>
    
    <!--
    ***************************************************************************
    TARGET: setOSFileSeparator
    Set the appropriate file separator for the OS
    ***************************************************************************
    -->
    <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="unix"/>
        </condition>
        
        <condition property="separatorFile" value="\">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
        
        <echo>file separator is ${separatorFile}</echo>
        
        <condition property="CRLF" value="&#13;&#10;">
            <os family="windows"/>
        </condition>
        
        <condition property="CRLF" value="&#10;">
            <os family="unix"/>
        </condition>
    </target>

    <!--
    **************************************************************************
    TARGET: replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile
    Replace all instances of the token with the token value in the specified file
    **************************************************************************
    -->      
    <target name="replaceAllInstancesOfGivenTokenWithGivenValueForTheGivenFile">
        <replace file="${file}"
            token="${token}"
            value="${tokenValue}"/>
    </target>
    
    <!--
    **************************************************************************
    TARGET: appendToGivenFileGivenString
    Do NOT indent these line. The entries in the httpd.conf file are not tabbed
    **************************************************************************
    -->  
    <target name="appendToGivenFileGivenString">
<echo file="${file}" append="true">${stringToAppend}${CRLF}</echo>
    </target>
    
    <!--
    **************************************************************************
    TARGET: getPlatformPluginDriver
    Set the appropriate driver name for the OS
    **************************************************************************
    -->      
    <target name="getPlatformPluginDriver"
            description="Sets WAS_PLUGIN_DRIVER to the correct WAS plugin driver for the current platform">
            
        <condition property="PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libns61_http.so">
            <equals arg1="${OS_NAME}" arg2="AIX"/>
        </condition>
        
        <condition property="PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libns61_http.so">
            <equals arg1="${OS_NAME}" arg2="Linux"/>
        </condition>
        
        <condition property="PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libns61_http.so">
            <equals arg1="${OS_NAME}" arg2="SunOS"/>
        </condition>
        
        <condition property="PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libns61_http.sl">
            <equals arg1="${OS_NAME}" arg2="HP-UX"/>
        </condition>

        <condition property="PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}ns61_http.dll">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>

        <antcall target="logBoth">
           <param name="logStatement" value="WAS plugin driver set to: ${PLUGIN_DRIVER}"/>
        </antcall>
    </target>
    
    <!--
    **************************************************************************
    TARGET: checkConfigFiles
    Check existence of the webserver specific configuration file(s).
    Only executed if cfgFiles.ok is true
    **************************************************************************
    -->      
    <target name="checkConfigFiles" if="cfgFiles.ok">
       <condition property="configFile">
          <and>
             <available file="${SUNONE_MAGNUS_CONF}"/>
             <available file="${SUNONE_OBJ_CONF}"/>
          </and>
        </condition>
        <condition property="logMsg" value="Located config files ${SUNONE_MAGNUS_CONF} and ${SUNONE_OBJ_CONF}">
           <istrue value="${configFile}"/>
        </condition>
        
        <condition property="logMsg" value="Could not locate config files ${SUNONE_MAGNUS_CONF} and ${SUNONE_OBJ_CONF}">
           <isfalse value="${configFile}"/>
        </condition>
        
        <antcall target="logBoth">
           <param name="logStatement" value="${logMsg}"/>
        </antcall>
        
        <condition property="fatalError">
           <isfalse value="${configFile}"/>
        </condition>
        
        <antcall target="terminateOnFailure"/>

    </target>

    <!--
    ***************************************************************************
    TARGET: terminateOnFailure
    ***************************************************************************
    -->      
    <target name="terminateOnFailure" if="fatalError">
       <fail message="Fatal error.  Terminating plugin configuration"/>
    </target>
    
    <!--
    **************************************************************************
    TARGET: convertToUnixPath
    Filenames added to magnus.conf file MUST only contain forward slash.  
    Backward slashes are ignored    
    Convert path to unix style pathname which only contains forward slash                             
    **************************************************************************
    -->      
    <target name="convertToUnixPath">
        <path id="driver.path">
           <pathelement location="${PLUGIN_DRIVER}"/>
        </path>
        <pathconvert targetos="unix" property="WAS_PLUGIN_DRIVER" refid="driver.path"/>
        
        <path id="driver.path">
           <pathelement location="${WAS_PLUGIN_CFG_XML}"/>
        </path>
        <pathconvert targetos="unix" property="PLUGIN_CFG_XML" refid="driver.path"/>

    </target>
    
    <!--
    **************************************************************************
    TARGET: appendSunOneConfigurationFileLoadModuleEntry
    Add LoadModule entry to magnus.conf file.  Comment out existing WAS plugin
    LoadModule definitions
    **************************************************************************
    -->      
    <target name="appendSunOneConfigurationFileLoadModuleEntry" if="configFile"
            description="Add LoadModule entry to magnus.conf file">
        
        <replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;load-modules&quot;.funcs=&quot;as_init,as_handler,as_term&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                                          
        </replaceregexp>                    
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Commenting out previous LoadModule entries"/>
        </antcall>
        
        <replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;as_init&quot;.bootstrap.properties.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>                    
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Commenting out previous bootstrap entries"/>
        </antcall>
      

        <replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;load-modules&quot;.shlib=&quot;(.*\\)(.*)j2eeplugin.dll&quot;.*)" 
                       byline="true"
                       flags="is"
                       replace="#\1">                                          
        </replaceregexp>
	
        <replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;load-modules&quot;.shlib=&quot;(.*/)(.*)j2eeplugin.dll&quot;.*)" 
                       byline="true"
                       flags="is"
                       replace="#\1">                                          
        </replaceregexp>
	    
	
        <replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;load-modules&quot;.shlib=&quot;(.*/)(.*)libj2eeplugin.so&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                                          
        </replaceregexp>
	<replaceregexp file="${SUNONE_MAGNUS_CONF}" match="(Init.fn=&quot;load-modules&quot;.shlib=&quot;(.*/)(.*)libj2eeplugin.sl&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                                          
        </replaceregexp>                     
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Commenting out load-module entry for Sun's libj2eeplugin"/>
        </antcall>
                    
        <antcall target="appendToGivenFileGivenString">
			<param name="file" value="${SUNONE_MAGNUS_CONF}"/>
			<param name="stringToAppend" value=" "/>
	</antcall>
        
        <antcall target="appendToGivenFileGivenString">
			<param name="file" value="${SUNONE_MAGNUS_CONF}"/>
			<param name="stringToAppend" value="Init fn=&quot;load-modules&quot; funcs=&quot;as_init,as_handler,as_term&quot; shlib=&quot;${WAS_PLUGIN_DRIVER}&quot;"/>
	</antcall>
	<antcall target="logBoth">
           <param name="logStatement" value="Appending: Init fn=&quot;load-modules&quot; funcs=&quot;as_init,as_handler,as_term&quot; shlib=&quot;${WAS_PLUGIN_DRIVER}&quot; to ${SUNONE_MAGNUS_CONF}"/>
        </antcall>
                        
        <antcall target="appendToGivenFileGivenString">
			<param name="file" value="${SUNONE_MAGNUS_CONF}"/>
			<param name="stringToAppend" value="Init fn=&quot;as_init&quot; bootstrap.properties=&quot;${PLUGIN_CFG_XML}&quot;"/>
	</antcall>
	<antcall target="logBoth">
           <param name="logStatement" value="Appending: Init fn=&quot;as_init&quot; bootstrap.properties=&quot;${PLUGIN_CFG_XML}&quot; to ${SUNONE_MAGNUS_CONF}"/>
        </antcall>
    
    </target>
    
    <!--
    **************************************************************************
    TARGET: appendSunOneConfigurationFileHandlerEntry
    Add service and Addlog entries to obj.conf file.  Comment out existing WAS
    plugin service and Addlog definitions
    **************************************************************************
    -->      
    <target name="appendSunOneConfigurationFileHandlerEntry" if="configFile"
            description="Add service and AddLog entry to obj.conf file">
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(Service.fn=&quot;as_handler&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>                    
        
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Commenting out previous fn=&quot;as_handler&quot; entries"/>
        </antcall>
        
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(AddLog.fn=&quot;as_term&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp> 
	
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Commenting out previous AddLog fn=&quot;as_term&quot; entries"/>
        </antcall>
	
        
       <!--
        **************************************************************************
        Some obj.conf files may have the default Object name in quotes.  There is
        no way to tell.... 
        **************************************************************************
        -->      
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(Object.name=default>.*)"
                       byline="true"
                       flags="is"
                       replace="\1${CRLF}Service fn=&quot;as_handler&quot; ${CRLF}AddLog fn=&quot;as_term&quot;">                   
        </replaceregexp>                    
        
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(Object.name=&quot;default&quot;>.*)"
                       byline="true"
                       flags="is"
                       replace="\1${CRLF}Service fn=&quot;as_handler&quot;${CRLF}AddLog fn=&quot;as_term&quot;">                   
        </replaceregexp>                    
        
        <antcall target="logBoth">
           <param name="logStatement" value="Appending: Service fn=&quot;as_handler&quot; AddLog fn=&quot;as_term&quot; to ${SUNONE_OBJ_CONF}"/>
        </antcall>

        <!--
        **************************************************************************
        Comment out j2eeplugin directives in the obj.conf file.  This feature, which is enabled by default in SunOne 6.x., intercepts servlets
        and jsps prior to our plugin and handles the requests meant for the WebSphere.  
        **************************************************************************
        -->                                        
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(NameTrans.fn=&quot;ntrans-j2ee&quot;.name=&quot;j2ee&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>                    
        
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(Error.fn=&quot;error-j2ee&quot;.*)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>                    
	
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(PathCheck.fn=&quot;find-index-j2ee&quot;)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>    
	
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(ObjectType.fn=&quot;type-j2ee&quot;)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>  
	
        
        <replaceregexp file="${SUNONE_OBJ_CONF}" match="(Service.fn=&quot;service-j2ee&quot;.method=&quot;*&quot;)"
                       byline="true"
                       flags="is"
                       replace="#\1">                   
        </replaceregexp>
	
	
        <antcall target="logBoth">
           <param name="logStatement" value="Disabling the feature of Sun Java System Web server that supports servlets and JSPs by default."/>
        </antcall>
        <antcall target="logBoth">
           <param name="logStatement" value="Disabling this feature allows requests to be handled by Web server Plug-in for IBM WebSphere Application Server "/>
        </antcall>
        <antcall target="logBoth">
           <param name="logStatement" value="Commenting out 'NameTrans fn=&quot;ntrans-j2ee&quot;' name=&quot;j2ee&quot; in ${SUNONE_OBJ_CONF} "/>
        </antcall>
        <antcall target="logBoth">
           <param name="logStatement" value="Commenting out 'Error fn=&quot;error-j2ee&quot;' in ${SUNONE_OBJ_CONF}"/>
        </antcall>
	<antcall target="logBoth">
           <param name="logStatement" value="Commenting out 'PathCheck fn=&quot;find-index-j2ee&quot;' in ${SUNONE_OBJ_CONF}"/>
        </antcall>
	<antcall target="logBoth">
           <param name="logStatement" value="Commenting out 'ObjectType fn=&quot;type-j2ee&quot;' in ${SUNONE_OBJ_CONF}"/>
        </antcall>
	 <antcall target="logBoth">
           <param name="logStatement" value="Commenting out 'Service fn=&quot;service-j2ee&quot; method=&quot;*&quot;' in ${SUNONE_OBJ_CONF}"/>
        </antcall>
	
    </target>
       
    <!--
    **************************************************************************
    TARGET: createLogDir
    create directory for webserver plugin log
    **************************************************************************
    -->
    <target name="createLogDir" if="default.logDir.notfound">
        <antcall target="logBoth">
           <param name="logStatement" value="Creating log directory ${default.log.dir}"/>
        </antcall>
        <mkdir dir="${default.log.dir}"/>
    </target>
    
    <!--
    **************************************************************************
    TARGET: chkLogDir
    check whether PLUGINHOME/logs/<webservername> directory exists
    **************************************************************************
    -->
    <target name="chkLogDir">
    
       <property name="default.log.dir" value="${PLUGIN_HOME}${separatorFile}logs${separatorFile}${WEBSERVER_NAME}"/>  
  
        <condition property="default.logDir.notfound">
           <not>
              <available file="${default.log.dir}" type="dir"/>
           </not>
        </condition>
  
        <condition property="logDirMsg" value="Log directory ${default.log.dir} exists">
           <isfalse value="${default.logDir.notfound}"/>
        </condition>
        
        <condition property="logDirMsg" value="Log directory ${default.log.dir} does not exist">
           <istrue value="${default.logDir.notfound}"/>
        </condition>
        
        <antcall target="logBoth">
           <param name="logStatement" value="${logDirMsg}"/>
        </antcall>
        <antcall target="createLogDir" />
    </target>
    
    
    <!--
    **************************************************************************
    TARGET: createCfgDir
    create directory for plugin-cfg.xml
    **************************************************************************
    -->
    <target name="createCfgDir" if="default.cfgDir.notfound">
        <antcall target="logBoth">
           <param name="logStatement" value="Creating directory ${default.config.dir}"/>
        </antcall>
        <mkdir dir="${default.config.dir}"/>
    </target>

    <!--
    **************************************************************************
    TARGET: updatePlgCfg
    copy plugin-cfg.xml from template directory to 
    PLUGIN_HOME\config\webserver name directory.  
    If the directory does not exist it must be created
    Replace the PLUGIN_HOME and WAS_HOSTNAME tags with the appropriate values
    **************************************************************************
    -->
    <target name="updatePlgCfg" if="update.cfg">
        <antcall target="logBoth">
           <param name="logStatement" value="Installing default plugin-cfg.xml file in directory ${default.config.dir}"/>
        </antcall>
       
        
        <antcall target="createCfgDir"/>
       
        <copy file="${PLUGIN_HOME}${separatorFile}config${separatorFile}templates${separatorFile}plugin-cfg.xml" 
              tofile="${default.config.file}"
              overwrite="false"/>
             
        <replace file="${default.config.file}" 
                 token="$(PLUGIN_HOME)"
                 value="${PLUGIN_HOME}" />
        
        <replace file="${default.config.file}" 
                 token="$(WAS_HOSTNAME)"
                 value="${WAS_HOSTNAME}" />       
                           
        <replace file="${default.config.file}" 
                 token="$(WEBSERVER_NAME)"
                 value="${WEBSERVER_NAME}" />       
    </target>    


    <!--
    **************************************************************************
    TARGET: updatePlgKeyStore
    copy plugin key store files  from etc directory to 
    plug-in config file directory.  
    **************************************************************************
    -->
    <target name="updatePlgKeyStore" if="plugin.cfgFile.found">
        <antcall target="logBoth">
           <param name="logStatement" value="Installing default keystore files in directory ${default.config.dir}"/>
        </antcall>

        <copy file="${PLUGIN_HOME}${separatorFile}etc${separatorFile}plugin-key.kdb" 
              tofile="${default.config.dir}${separatorFile}plugin-key.kdb"
              overwrite="false"/>

        <copy file="${PLUGIN_HOME}${separatorFile}etc${separatorFile}plugin-key.sth" 
              tofile="${default.config.dir}${separatorFile}plugin-key.sth"
              overwrite="false"/>

     <!--   <copy file="${PLUGIN_HOME}${separatorFile}etc${separatorFile}plugin-key.crl" 
              tofile="${default.config.dir}${separatorFile}plugin-key.crl"
              overwrite="false"/>  -->

        <copy file="${PLUGIN_HOME}${separatorFile}etc${separatorFile}plugin-key.rdb" 
              tofile="${default.config.dir}${separatorFile}plugin-key.rdb"
              overwrite="false"/>
    </target>    
    

    <!--
    **************************************************************************
    TARGET: chkPlgCfg
    Check if plugin-cfg.xml file exists
    If plugin-cfg.xml exists it will not be overwritten
    If non default location is specified, file MUST exist.
    **************************************************************************
    -->
    <target name="checkPlgCfg"
            description="check plugin-cfg.xml.">
        
       <property name="default.config.dir" value="${PLUGIN_HOME}${separatorFile}config${separatorFile}${WEBSERVER_NAME}"/>  
       <property name="default.config.file" value="${default.config.dir}${separatorFile}plugin-cfg.xml"/>
                   
       <condition property="default.cfgDir.notfound">
          <not>
             <available file="${default.config.dir}" type="dir"/>
          </not>
       </condition>
       
       <condition property="default.cfgFile.notfound">
          <not>
             <available file="${default.config.file}"/>
          </not>
       </condition>

       <condition property="standalone.cfgFile.found">
          <available file="${WAS_PLUGIN_CFG_XML}"/>
       </condition>

       <!--
       **********************************************************************
       cfgFiles.ok if 1) file exists
                      2) Given file is same as default plug-in config file
       **********************************************************************
       -->
       <condition property="cfgFiles.ok">
          <or>
             <istrue value="${standalone.cfgFile.found}"/>
             <equals arg1="${default.config.file}" arg2="${WAS_PLUGIN_CFG_XML}" />
          </or>
       </condition>
              
       <condition property="cfgLogMsg" value="Default plugin-cfg.xml exists in ${default.config.dir}.  The file will not be overwritten">
          <and>
             <isfalse value="${default.cfgFile.notfound}"/>
             <istrue value="${cfgFiles.ok}"/>
          </and>
       </condition>

       <condition property="cfgLogMsg" value="Default plugin-cfg.xml does not exist in ${default.config.dir}.">
          <and>
             <istrue value="${default.cfgFile.notfound}"/>
             <istrue value="${cfgFiles.ok}"/>
          </and>
       </condition>
       
       <condition property="cfgLogMsg" 
                  value="INSTALL ERROR!!! ${WAS_PLUGIN_CFG_XML} does not exist.${CRLF}
           The file MUST exist for a local_standalone configuration. If you selected to have the${CRLF}
           definition for webserver ${WEBSERVER_NAME} created by the plugin installer please check${CRLF}
           ${PLUGIN_HOME}${separatorFile}logs${separatorFile}configure_ihs_webserver.log${CRLF}
           to determine the cause of the failure.">
          <isfalse value="${cfgFiles.ok}"/>
       </condition>
       
       <antcall target="logBoth">
          <param name="logStatement" value="${cfgLogMsg}"/>
       </antcall>
       
       <condition property="fatalError">
          <isfalse value="${cfgFiles.ok}"/>
       </condition>
        
       <antcall target="terminateOnFailure"/>
       
       <!--
       ******************************************************************************
       update.cfg if default config file does not exist
       ******************************************************************************
       -->
       <condition property="update.cfg">
          <and>
             <istrue value="${default.cfgFile.notfound}"/>
             <istrue value="${cfgFiles.ok}"/>
          </and>
       </condition>
       
       <antcall target="updatePlgCfg"/>
       
       <!--
       ******************************************************************************
       plugin.cfgFile.found if plugin config file exist
       ******************************************************************************
       -->
       <condition property="plugin.cfgFile.found">
          <available file="${WAS_PLUGIN_CFG_XML}"/>
       </condition>
       
       <antcall target="updatePlgKeyStore"/>

    </target>
    
    <!--
    **************************************************************************
    TARGET: ConfigureSunOnePlugin
    **************************************************************************
    -->
    <target name="ConfigureSunOnePlugin"
            description="Configure SunOne Plugin only if required options are set"
            depends="detectCurrentOSFamily,  
                     setOSFileSeparator, 
                     SetBitsDir,
                     logStartupProperties,                    
                     getPlatformPluginDriver,
                     convertToUnixPath,
                     chkInstall_Arch,
                     checkPlgCfg,
                     checkConfigFiles,
                     chkLogDir,
                     appendSunOneConfigurationFileLoadModuleEntry,  
                     appendSunOneConfigurationFileHandlerEntry">
                     
        <antcall target="logBoth">
           <param name="logStatement" value="Install complete"/>
        </antcall>

    </target>
    
    <!-- TARGET:  chkInstall_Arch
    **************************************************************************
    Verifies that if 64 bit is chosen, then /64bits/ directory must exist.
    **************************************************************************
    -->
    <target name="chkInstall_Arch">
       <condition property="64bit.Dir.found">
             <available type="dir" file="${PLUGIN_HOME}${separatorFile}bin${separatorFile}64bits"/>
       </condition>
       
       <condition property="mismatch.detected">
          <and>
             <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
             <isfalse value="${64bit.Dir.found}"/>
          </and>
       </condition>

       <condition property="cfgLogMsg" value="****  64 bit Architecture was chosen, but installed plugin doesn't contain the proper structure.  **** ${CRLF}****  Either choose 32 bit within Plugin Configuration Tool or Uninstall Plugin and Install 64 bit plugin.  **** ">
             <istrue value="${mismatch.detected}"/>
       </condition>
       
       <condition property="cfgLogMsg" value="64 bit directory was located.">
             <isfalse value="${mismatch.detected}"/>
       </condition>

       <antcall target="logBoth">
          <param name="logStatement" value="${cfgLogMsg}"/>
       </antcall>
       
       <condition property="fatalError">
          <istrue value="${mismatch.detected}"/>
       </condition>

      <antcall target="terminateOnFailure"/>
    
    </target>
          
    <!--
    **************************************************************************
    TARGET: Usage
    Displays usage information
    **************************************************************************
    -->
    <target name="Usage" if="CMDLINE_CFG"
            description="Display usage information">       
      	<echo message="Usage: -ant -f ConfigureSunOne.ant [[option=optionValue]..]"/>
      	<echo message=""/>
      	<echo message="Valid Options"/>
        <echo message="============="/>
      	<echo message="-DPLUGIN_HOME=pluginDirectory"/>
        <echo message="    required - the location of the plugin home directory"/>
        <echo message="      (ie, \usr\IBM\WebSphere\Plugins)"/>
      	<echo message="-DOS_NAME=operatingSystem"/>
        <echo message="    required - the current operating system.  Valid values are:"/>
      	<echo message="      AIX"/>
      	<echo message="      Linux"/>
      	<echo message="      SunOS"/>
      	<echo message="      HP-UX"/>
      	<echo message="      windows"/>
      	<echo message="-DSUNONE_OBJ_CONF=SunOneObjConfFile"/>
        <echo message="    required - the full path name of the SunOne web server"/>
        <echo message="               obj.conf file"/>
      	<echo message="-DSUNONE_MAGNUS_CONF=SunOneMagnusConfFile"/>
        <echo message="    required - the full path name of the SunOne web server"/>
        <echo message="               magnus.conf file"/>
      	<echo message="-DWAS_PLUGIN_CFG_XML=PluginCfgXml"/>
        <echo message="    required - the full path name of the plugin-cfg.xml file"/>     
                                                            
    </target>                                               


    <!--
    ******************************************************************************
    TARGET:  is32
    This is to determine the bitmode of the hosting maching (32 or 64)
    ******************************************************************************
    -->
    <target name="is32">
     <exec resultproperty="is.thirtytwo" executable="/bin/sh" dir="/" os="AIX">
      <arg value = "-c"/>
      <arg value = "ls -l /unix | grep '_64'"/>
     </exec>
     <exec resultproperty="is.thirtytwo" executable="/bin/bash" os="Linux">
      <arg value = "-c"/>
      <arg value = "uname -m | egrep '(64|390x)'"/>
     </exec>
     <exec resultproperty="is.thirtytwo" executable="/bin/bash" os="SunOS">
      <arg value = "-c"/>
      <arg value = "isainfo -vk | grep '64'"/>
     </exec>
     <exec resultproperty="is.thirtytwo" executable="/bin/sh" os="HPUX">
      <arg value = "-c"/>
      <arg value = "getconf KERNEL_BITS | grep '64'"/>
     </exec>
     <exec resultproperty="is.thirtytwo" executable="/bin/sh" os="HP-UX">
      <arg value = "-c"/>
      <arg value = "getconf KERNEL_BITS | grep '64'"/>
     </exec>

        <!-- Force 32-bit on Windows, for now:
               IA64 not supported 
               AMD64 not recognized in v7 scripts
               IHS is still 32-bit only on Windows. 
        -->
        <condition property="is.thirtytwo" value="1">
          <os family="windows"/>
        </condition>

    <echo message="32-bit OS: ${is.thirtytwo}"/>
    </target>

    <!-- TARGET:  SetBitsDir
    **************************************************************************
    This will set the bitsdir to /, /32bits/, or /64bits/
    **************************************************************************
    -->
    <target name="SetBitsDir">
        <available type="dir" file="${PLUGIN_HOME}${separatorFile}bin${separatorFile}64bits" property="plugin.install.64bit"/>
        
        <!-- z/os packaging is more simple -->
        <condition property="bitsDir" value="/">
            <equals arg1="${OS_NAME}" arg2="ZOS"/>
        </condition>
        
        <condition property="bitsDir" value="${separatorFile}32bits${separatorFile}">
           <and>
             <equals arg1="${INSTALL_ARCH}" arg2="32" trim="true"/>
             <istrue value="${plugin.install.64bit}"/>    
           </and>
        </condition>
         
        <condition property="bitsDir" value="${separatorFile}64bits${separatorFile}">
           <and>
             <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
             <istrue value="${plugin.install.64bit}"/>    
           </and>
        </condition>

        <condition property="bitsDir" value="${separatorFile}">
           <and>
             <equals arg1="${INSTALL_ARCH}" arg2="32" trim="true"/>
             <isfalse value="${plugin.install.64bit}"/> 
           </and>
        </condition>

     <!--   <condition property="bitsDir" value="${separatorFile}">
           <and>
             <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
             <not>
                <istrue value="${plugin.install.64bit}"/> 
             </not>
           </and>
        </condition>  -->
        <echo message="bitsDir is ${bitsDir} PLUGIN64: ${plugin.install.64bit} OS-is-32bit: ${is.thirtytwo}"/>    
    </target>


    <!--
    **************************************************************************
    TARGET: bootstrapPluginsSunOne
    This is the main target. Check that all required config options are present.
    If all required config options are present set SunOneTarget to ConfigureSunOnePlugin
    Otherwise set SunOneTarget to "Usage" so the usage information can be displayed
    **************************************************************************
    -->
    <target name="bootstrapPluginsSunOne"
        description="Bootstrap SunOne Plugin">
        
        <condition property="ValidOptions">                   
           <and>                                            
              <isset property="SUNONE_OBJ_CONF"/>               
              <isset property="SUNONE_MAGNUS_CONF"/>
              <isset property="WAS_PLUGIN_CFG_XML"/> 
              <isset property="OS_NAME"/>
              <isset property="PLUGIN_HOME"/>
              <isset property="PLUGIN_INSTALL_TYPE"/>    
	            <isset property="INSTALL_ARCH"/>        
              <isset property="WEBSERVER_TYPE"/>                         
              <not>
                 <equals arg1="${SUNONE_OBJ_CONF}" arg2=" " trim="true"/>               
              </not>
              <not>   
                 <equals arg1="${SUNONE_MAGNUS_CONF}" arg2=" " trim="true"/>
              </not>
              <not>
                 <equals arg1="${WAS_PLUGIN_CFG_XML}" arg2=" " trim="true"/>
              </not>
	            <not>
                 <equals arg1="${INSTALL_ARCH}" arg2=" " trim="true"/>
              </not>                  
              <equals arg1="${WEBSERVER_TYPE}" arg2="SUNJAVASYSTEM" trim="true"/>
           </and>                                           
        </condition>
       	
        <condition property="SunOneTarget" value="ConfigureSunOnePlugin">
           <istrue value="${ValidOptions}"/>
        </condition>
        
        <condition property="SunOneTarget" value="Usage">
              <isfalse value="${ValidOptions}"/>
        </condition>
        
        <antcall target="${SunOneTarget}"/>  
        
    </target>
    
</project>
