<project name="bootstrapPluginsDomino7" default="bootstrapPluginsDomino7" 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: 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: 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}install${WEBSERVER_SELECTED}Plugin.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 ${WEBSERVER_SELECTED} 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="DOMINO7_NAMES_CONF = ${DOMINO7_NAMES_CONF} "/>
        </antcall>     
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="DOMINO7_NOTES_CONF = ${DOMINO7_NOTES_CONF} "/>
        </antcall>

        <antcall target="updateLogFile">
           <param name="stringToAppend" value="USER            = ${DOMINO7_NOTES_USER}"/>
        </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="OS_NAME            = ${INSTALL_ARCH}"/>
        </antcall>     

      
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="WEBSERVER_SELECTED  = ${WEBSERVER_SELECTED}"/>
        </antcall>
        
        
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="WEBSERVER_TYPE      = ${WEBSERVER_TYPE}"/>
        </antcall>

       
        <antcall target="updateLogFile">
           <param name="stringToAppend" value="OS_NAME            = ${INSTALL_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: 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="WAS_PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libdomino5_http.a">
            <equals arg1="${OS_NAME}" arg2="AIX"/>
        </condition>
        
        <condition property="WAS_PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libdomino5_http.so">
            <equals arg1="${OS_NAME}" arg2="Linux"/>
        </condition>
        
        <condition property="WAS_PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libdomino6_http.so">
            <equals arg1="${OS_NAME}" arg2="SunOS"/>
        </condition>
        
        <condition property="WAS_PLUGIN_DRIVER" value="${PLUGIN_HOME}/bin${bitsDir}libdomino5_http.sl">
            <equals arg1="${OS_NAME}" arg2="HP-UX"/>
        </condition>

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

        <antcall target="logBoth">
           <param name="logStatement" value="WAS plugin driver set to: ${WAS_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="${DOMINO7_NOTES_CONF}"/>
             <available file="${DOMINO7_NAMES_CONF}"/>
          </and>
        </condition>
        <condition property="logMsg" value="Located config files ${DOMINO7_NOTES_CONF} and ${DOMINO7_NAMES_CONF}">
           <istrue value="${configFile}"/>
        </condition>
        
        <condition property="logMsg" value="Could not locate config files ${DOMINO7_NOTES_CONF} and ${DOMINO7_NAMES_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: resolvePLUGINJAVAExecutableForTheCurrentPlatform
    Sets PLUGIN_JAVA_EXECUTABLE to the PLUGIN Java interpretor for the 
    current platform
    **************************************************************************
    -->      
    <target name="resolvePLUGINJAVAExecutableForTheCurrentPlatform" if="configFile"
            description="Sets PLUGIN_JAVA_EXECUTABLE to the PLUGIN Java interpretor for the current platform">
            
        <condition property="PLUGIN_JAVA_EXECUTABLE" value="${PLUGIN_HOME}${separatorFile}java${separatorFile}jre${separatorFile}bin${separatorFile}java">
            <equals arg1="${currentOSFamily}" arg2="unix"/>
        </condition>
        
        <condition property="PLUGIN_JAVA_EXECUTABLE" value="${PLUGIN_HOME}${separatorFile}java${separatorFile}jre${separatorFile}bin${separatorFile}javaw.exe">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
        
        <antcall target="logBoth">
           <param name="logStatement" value="JAVA interpretor set to: ${PLUGIN_JAVA_EXECUTABLE}"/>
        </antcall>     

    </target>
    
    <!--
    **************************************************************************
    TARGET: resolveClasspathForTheCurrentPlatform
    Set classpath 
    **************************************************************************
    -->      
    <target name="resolveClasspathForTheCurrentPlatform" if="configFile"
            description="Sets DOMINO7_CLASSPATH to the correct classpath for the current platform">
                        
        <condition property="DOMINO7_CLASSPATH" 
                value="${PLUGIN_HOME}${separatorFile}lib${separatorFile}InstallWASdsapiPlugin.jar:${DOMINO7_NOTES_CONF}">
            <and>
               <equals arg1="${currentOSFamily}" arg2="unix"/>
                  <not>
                     <equals arg1="${OS_NAME}" arg2="SunOS"/>
                  </not>
            </and>
        </condition>
        
        <condition property="DOMINO7_CLASSPATH" 
                value="${PLUGIN_HOME}${separatorFile}lib${separatorFile}InstallWASdsapiPlugin.jar:${PLUGIN_HOME}${separatorFile}lib${separatorFile}dominoutil.jar:${DOMINO7_NOTES_CONF}">
            <equals arg1="${OS_NAME}" arg2="SunOS"/>
        </condition>
        
        <condition property="DOMINO7_CLASSPATH" 
                value="${PLUGIN_HOME}${separatorFile}lib${separatorFile}InstallWASdsapiPlugin.jar;${DOMINO7_NOTES_CONF}">
            <equals arg1="${currentOSFamily}" arg2="windows"/>
        </condition>
                        
        <antcall target="logBoth">
           <param name="logStatement" value="Domino 7 classpath set to: ${DOMINO7_CLASSPATH}"/>
        </antcall>     
        
    </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: InstallWASdsapiPluginWindows
    Installs domino plugin on Windows
    **************************************************************************
    -->      
    <target name="InstallWASdsapiPluginWindows"  if="configFile"
            description="Install domino plugin on windows platform">            
            
        <antcall target="logBoth">
           <param name="logStatement" value="Run ${PLUGIN_JAVA_EXECUTABLE} -classpath ${DOMINO7_CLASSPATH} InstallWASdsapiPlugin -d ${DOMINO7_NAMES_CONF} -l ${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log -v ${WAS_PLUGIN_DRIVER} -version v6"/>
        </antcall>     
        <antcall target="logBoth">
           <param name="logStatement" value="The results will be logged to ${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log"/>
        </antcall>     
        
        <dirname property="DOMINO7_NAMES_PATH" file="${DOMINO7_NAMES_CONF}"/>        
        
        <antcall target="logBoth">
           <param name="logStatement" value="DOMINO6_NAMES_PATH is ${DOMINO7_NAMES_PATH}"/>
        </antcall>     

        <dirname property="DOMINO7_NOTES_PATH" file="${DOMINO7_NAMES_PATH}"/>        
        

        <antcall target="logBoth">
           <param name="logStatement" value="DOMINO6_NOTES_PATH is ${DOMINO7_NOTES_PATH}"/>
        </antcall>     
        
<!-- Add WebSpherePluginCfg variable to notes.ini file. -->    
        <replaceregexp file="${DOMINO7_NOTES_PATH}${separatorFile}notes.ini" match="(WebSpherePluginCfg=.*)"
                       byline="true"
                       replace=" ">                                          
        </replaceregexp>                    
        <antcall target="appendToGivenFileGivenString">
			<param name="file" value="${DOMINO7_NOTES_PATH}${separatorFile}notes.ini"/>
			<param name="stringToAppend" value="WebSpherePluginCfg=${WAS_PLUGIN_CFG_XML}"/>
	</antcall>
        <antcall target="appendToGivenFileGivenString">
			<param name="file" value="${DOMINO7_NOTES_PATH}${separatorFile}notes.ini"/>
			<param name="stringToAppend" value=" "/>
	</antcall>

        <exec executable="${PLUGIN_JAVA_EXECUTABLE}" dir="${DOMINO7_NOTES_PATH}" failonerror="true" >
            <arg value="-classpath"/>
            <arg value="&quot;${DOMINO7_CLASSPATH}&quot;"/>
            <arg value="InstallWASdsapiPlugin"/>
            <arg value="-d"/>
            <arg value="&quot;${DOMINO7_NAMES_CONF}&quot;"/>
            <arg value="-l"/>
            <arg value="&quot;${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log&quot;"/>
            <arg value="-v"/>
            <arg value="&quot;${WAS_PLUGIN_DRIVER}&quot;"/>
            <arg value="-version"/>
            <arg value="v6"/>
            <env key="PATH" path="${DOMINO7_NOTES_PATH}"/>
        </exec>
    </target>

    <!--
    **************************************************************************
    TARGET: InstallWASdsapiPluginUnix
    Installs domino plugin on Unix
    Change permissions on PLUGIN_HOME/log directory so notes user has write permissions
    When installing as root we must su to notes user. 
    Command to configure the domino server is dumped to a temporary (domino7Install.sh) file 
    and executed via exec cmd.  Once the executed domino7Install.sh is deleted.
    **************************************************************************
    -->      
    <target name="InstallWASdsapiPluginUnix"  if="configFile"
            description="Install domino7 plugin">
            
        <antcall target="logBoth">
           <param name="logStatement" value="Run ${PLUGIN_JAVA_EXECUTABLE} -classpath ${DOMINO7_CLASSPATH} InstallWASdsapiPlugin -d ${DOMINO7_NAMES_CONF} -l ${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log -v ${WAS_PLUGIN_DRIVER} -version v6"/>
        </antcall>     
        <antcall target="logBoth">
           <param name="logStatement" value="The results will be logged to ${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log"/>
        </antcall>     

        <exec executable="chmod" failonerror="true">  
           <arg value="ugo+rw"/>
           <arg value="${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log"/>
        </exec>

        <dirname property="DOMINO7_NOTES_PATH" file="${DOMINO7_NOTES_CONF}"/>
        <dirname property="DOMINO7_NAMES_PATH" file="${DOMINO7_NAMES_CONF}"/>

        <dirname property="DOMINO7_NOTES_LIB_PATH"  file="${DOMINO7_NOTES_PATH}"/>
        <dirname property="DOMINO7_NOTES_JVM_PATH"  file="${DOMINO7_NOTES_LIB_PATH}"/>        
        <dirname property="DOMINO7_NOTES_ROOT_PATH" file="${DOMINO7_NOTES_JVM_PATH}"/>

        <antcall target="logBoth">
           <param name="logStatement" value="DOMINO7_NOTES_ROOT_PATH is ${DOMINO7_NOTES_ROOT_PATH}"/>
        </antcall>     

        <property name="dominoInstall.file" value="${PLUGIN_HOME}${separatorFile}bin${separatorFile}${WEBSERVER_SELECTED}Install.sh"/> 

        <echo file="${dominoInstall.file}">
           su ${DOMINO7_NOTES_USER} -c &quot;LIBPATH=${DOMINO7_NOTES_ROOT_PATH}:${DOMINO7_NOTES_PATH}:${DOMINO7_NAMES_PATH}:$LIBPATH; \
             PATH=${DOMINO7_NOTES_ROOT_PATH}:${DOMINO7_NOTES_PATH}:${DOMINO7_NAMES_PATH}:$PATH; \
             LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${DOMINO7_NOTES_ROOT_PATH}:${DOMINO7_NOTES_PATH}; \
             export PATH LIBPATH LD_LIBRARY_PATH;
             ${PLUGIN_JAVA_EXECUTABLE} \
             -classpath ${DOMINO7_CLASSPATH} \
             InstallWASdsapiPlugin \
             -d ${DOMINO7_NAMES_CONF} \
             -l ${PLUGIN_HOME}${separatorFile}logs${separatorFile}config${separatorFile}install${WEBSERVER_SELECTED}Plugin.log \
             -v ${WAS_PLUGIN_DRIVER} \
             -version v6&quot;
        </echo>

        <exec executable="chmod" failonerror="true">  
           <arg value="ugo+rx"/>
           <arg value="${dominoInstall.file}"/>
        </exec>

        <exec executable="/bin/sh" dir="${PLUGIN_HOME}${separatorFile}bin" failonerror="true">
           <arg value="-c"/>
           <arg value=". ${dominoInstall.file}"/>
        </exec>
       
        <delete file="${dominoInstall.file}"/> 
        
    </target>

    <!--
    **************************************************************************
    TARGET: createLogDir
    create directory for webserver plugin log
    **************************************************************************
    -->
    <target name="createLogDir" if="default.logDir.notfound">
        <antcall target="logBoth">
           <param name="logStatement" value="Creating 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}config${separatorFile}configure_${WEBSERVER_SELECTED}_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: terminateOnFailure
    ***************************************************************************
    -->      
    <target name="terminateOnFailure" if="fatalError">
       <fail message="Fatal error.  Terminating plugin configuration"/>
    </target>
    
    <!--
    ***************************************************************************
    TARGET: SetupPluginCfg
    Create script to set up WAS_PLUGIN_CONFIG_FILE environment variable
    UNIX only
    ***************************************************************************
    -->      
    <target name="SetupPluginCfg">
        <antcall target="logBoth">
            <param name="logStatement" value="Creating ${DOMINO7_NAMES_PATH}${separatorFile}setupPluginCfg.sh"/>
        </antcall>

<echo file="${DOMINO7_NAMES_PATH}${separatorFile}setupPluginCfg.sh">
#Set environment variable for Domino 7 Web Server plugin on UNIX
WAS_PLUGIN_CONFIG_FILE=${WAS_PLUGIN_CFG_XML}
export WAS_PLUGIN_CONFIG_FILE
</echo>

        <exec executable="chmod" failonerror="true">
           <arg value="ugo+rx"/>
           <arg value="${DOMINO7_NAMES_PATH}${separatorFile}setupPluginCfg.sh"/>
        </exec>

        <antcall target="logBoth">
            <param name="logStatement" value="Creating ${PLUGIN_HOME}${separatorFile}bin${separatorFile}setupPluginCfg.sh"/>
        </antcall>

<echo file="${PLUGIN_HOME}${separatorFile}bin${separatorFile}setupPluginCfg.sh">
#Set environment variable for Domino 7 Web Server plugin on UNIX
WAS_PLUGIN_CONFIG_FILE=${WAS_PLUGIN_CFG_XML}
export WAS_PLUGIN_CONFIG_FILE
</echo>

        <exec executable="chmod" failonerror="true">
           <arg value="ugo+rx"/>
           <arg value="${PLUGIN_HOME}${separatorFile}bin${separatorFile}setupPluginCfg.sh"/>
        </exec>

    </target>
    
    <!--
    **************************************************************************
    TARGET: ConfigureDomino7PluginWindows
    **************************************************************************
    -->
    <target name="ConfigureDomino7PluginWindows"
            description="Configure Domino7 Plugin only if required options are set"      
            depends="detectCurrentOSFamily,  
                     setOSFileSeparator, 
                     SetBitsDir,
                     logStartupProperties,                    
                     getPlatformPluginDriver,
                     chkInstall_Arch,
                     checkPlgCfg,
                     checkConfigFiles,
                     chkLogDir,
                     resolvePLUGINJAVAExecutableForTheCurrentPlatform,
            	       resolveClasspathForTheCurrentPlatform,
                     InstallWASdsapiPluginWindows">
                     
        <antcall target="logBoth">
           <param name="logStatement" value="Install complete"/>
        </antcall>
     
    </target>
    
    <!--
    **************************************************************************
    TARGET: ConfigureDomino7PluginUnix
    **************************************************************************
    -->
    <target name="ConfigureDomino7PluginUnix"
            description="Configure Domino7 Plugin only if required options are set"      
            depends="detectCurrentOSFamily,  
                     setOSFileSeparator, 
                     SetBitsDir,
                     logStartupProperties,                    
                     getPlatformPluginDriver,
                     chkInstall_Arch,
                     checkPlgCfg,
                     checkConfigFiles,
                     chkLogDir,
                     resolvePLUGINJAVAExecutableForTheCurrentPlatform,
            	       resolveClasspathForTheCurrentPlatform,
                     InstallWASdsapiPluginUnix,
                     SetupPluginCfg">     
                     
        <exec executable="chmod" failonerror="true">  
           <arg value="ugo+rw"/>
           <arg value="${PLUGIN_HOME}${separatorFile}logs${separatorFile}${WEBSERVER_NAME}"/>
        </exec>

        <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.">
          <and>
             <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
             <isfalse value="${mismatch.detected}"/>
          </and>
       </condition>
       
       <condition property="cfgLogMsg" value="Verified directories.">
             <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:  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"/>
        
        <condition property="INSTALL_ARCH" value="32">
        	<equals arg1="${INSTALL_ARCH}" arg2=" " trim="true"/>
        </condition>
        
       <condition property="bitsDir" value="${separatorFile}32bits${separatorFile}">
             <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
       </condition> 

        <condition property="bitsDir" value="${separatorFile}">
         <not>
	         <equals arg1="${INSTALL_ARCH}" arg2="64" trim="true"/>
	       </not>
	      </condition>  
	
    </target>
        
    <!--
    **************************************************************************
    TARGET: Usage
    Displays usage information
    **************************************************************************
    -->
    <target name="Usage" if="CMDLINE_CFG"
            description="Display usage information">       
      	<echo message="Usage: -ant -f ConfigureDomino7.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="-DDOMINO7_NAMES_CONF=Domino7NamesNsf"/>
        <echo message="    required - the full path name of the Domino7 names.nsf file"/>
      	<echo message="-DDOMINO7_NOTES_CONF=Domino7NotesJar"/>
        <echo message="    required - the full path name of the Domino7 Notes.jar file"/>     
                                                            
    </target>                                               

    <!--
    **************************************************************************
    TARGET: bootstrapPluginsDomino7
    This is the main target. Check that all required config options are present.
    If all required config options are present set Domino7Target to 
    ConfigureDomino7Plugin. Otherwise set Domino7Target to "Usage" so the usage
    information can be displayed
    **************************************************************************
    -->
    <target name="bootstrapPluginsDomino7"
        description="Bootstrap Domino7 Plugin">
        
        <condition property="ValidOptions">                   
           <and>                                            
              <isset property="DOMINO7_NAMES_CONF"/>               
              <isset property="DOMINO7_NOTES_CONF"/>
              <isset property="DOMINO7_NOTES_USER"/>
              <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="${DOMINO7_NAMES_CONF}" arg2=" " trim="true"/>               
              </not>
              <not>   
                 <equals arg1="${DOMINO7_NOTES_CONF}" arg2=" " trim="true"/>
              </not>
              <not>  
                 <equals arg1="${DOMINO7_NOTES_USER}" 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="DOMINO" trim="true"/>
              <equals arg1="${WEBSERVER_SELECTED}" arg2="domino7" trim="true"/>              
           </and>                                           
        </condition>
              
        <condition property="Domino7Target" value="Usage">
           <isfalse value="${ValidOptions}"/>
        </condition>
        <condition property="Domino7Target" value="ConfigureDomino7PluginWindows">
           <and>
              <istrue value="${ValidOptions}"/>
              <os family="windows"/>
           </and>
        </condition>

        <condition property="Domino7Target" value="ConfigureDomino7PluginUnix">
           <and>
              <istrue value="${ValidOptions}"/>
              <os family="unix"/>
           </and>
        </condition>

        <antcall target="${Domino7Target}"/>  
        
    </target>

</project>
