<?xml version="1.0"?>
<!-- <!DOCTYPE configuration SYSTEM "dtd/Configuration.dtd">  -->
<configuration name="SAPJVMTasks" version="1.0">
  <package name="com.sap.sdt.tools" version="1.0"/>

  <!-- Backup policy files to temp dir in case we do a force update of SAPJVM in the same directory -->
  <task name="BACKUP_POLICY_FILES" type="fs">
    <description>Backup JVM policy files</description>
    <copy file="$(/J2EE/StandardSystem/CentralInstance/JDKHomeDirectory)/jre/lib/security/local_policy.jar" toDir="$(JSPM/DIR/TMP)"/>
    <copy file="$(/J2EE/StandardSystem/CentralInstance/JDKHomeDirectory)/jre/lib/security/US_export_policy.jar" toDir="$(JSPM/DIR/TMP)"/>
  </task>
  
  <task name="EXTRACT_BINARIES" type="extract">
    <if test="$(IS_ARCHIVE)">
      <extract archive="$(ARCHIVE)" target="$(TARGET_DIR)"/>
    </if>
  </task>
  
  <task name="COPY_BINARIES" type="fs">
    <if test="!$(IS_ARCHIVE)">
      <copy toDir="$(TARGET_DIR)" overwrite="true">
        <fileset dir="$(SOURCE_DIR)">
          <include name="*"/>
        </fileset>
      </copy>
    </if>
  </task>
  
  <task name="RESTORE_POLICY_FILES" type="fs">
    <description>Restore JVM policy files</description>
	  <if test="$FILE_EXISTS($(TARGET_DIR)/sapjvm_5) == true">
	    <move file="$(JSPM/DIR/TMP)/local_policy.jar" toDir="$(TARGET_DIR)/sapjvm_5/jre/lib/security"/>
	    <move file="$(JSPM/DIR/TMP)/US_export_policy.jar" toDir="$(TARGET_DIR)/sapjvm_5/jre/lib/security"/>
	  </if>
	  <if test="$FILE_EXISTS($(TARGET_DIR)/sapjvm_6) == true">
	    <move file="$(JSPM/DIR/TMP)/local_policy.jar" toDir="$(TARGET_DIR)/sapjvm_6/jre/lib/security"/>
	    <move file="$(JSPM/DIR/TMP)/US_export_policy.jar" toDir="$(TARGET_DIR)/sapjvm_6/jre/lib/security"/>
	  </if>
	  
  </task>
  
  <task name="ADAPT_PROFILES" type="modifyFile">
     <!-- Update SAP JVM version in each instance profile -->
     <for-each variable="/J2EE/StandardSystem/Instances" into="Instance">
       <modifyFile file="$(Instance@InstanceProfilePath)" commentPattern="# *****  %  *****">
          <modifyProperty target="SAPJVM_VERSION"> <!-- modify this parameter only if it exists already -->
            <stringValue>$(Instance@SapJvmVersion)</stringValue>
          </modifyProperty>
		  
				  <if test="$FILE_EXISTS($(TARGET_DIR)/sapjvm_5) == true">
					  <!-- find and replace in each property value pattern sapjvm_[0-9] with current JVM home directory parrent folder name -->
					  <replaceInValue regex="sapjvm_[0-9]"> <!-- modify this parameter only if it exists already -->
						<stringValue>sapjvm_5</stringValue>
					  </replaceInValue>
					  <addProperty target="DIR_SAPJVM"> <!-- if it was present before, it was updated by replaceInValue above -->
						<stringValue>$$(DIR_EXECUTABLE)$$(DIR_SEP)sapjvm_5</stringValue>
					  </addProperty>
		      </if>
		
				  <if test="$FILE_EXISTS($(TARGET_DIR)/sapjvm_6) == true">
					  <!-- find and replace in each property value pattern sapjvm_[0-9] with current JVM home directory parrent folder name -->
					  <replaceInValue regex="sapjvm_[0-9]"> <!-- modify this parameter only if it exists already -->
						<stringValue>sapjvm_6</stringValue>
					  </replaceInValue>
					  <addProperty target="DIR_SAPJVM"> <!-- if it was present before, it was updated by replaceInValue above -->
						<stringValue>$$(DIR_EXECUTABLE)$$(DIR_SEP)sapjvm_6</stringValue>
					  </addProperty>
		      </if>
       </modifyFile>
     </for-each>
     <modifyFile id="UpdateProfile"/>
  </task>

	<task name="UPDATE_JDBC_DRIVER_LST_FILE" type="fs">
		<copy id="updateDriverLstFile"/>
  </task>

  <task name="READ_PROFILES" type="detect">
     <!-- Update SAP JVM version in each instance profile -->
     <for-each variable="/J2EE/StandardSystem/Instances" into="Instance">
      <readProfile type="ProfileReader">
        <param name="file" value="$(Instance@InstanceProfilePath)" />
        <get path="DIR_SAPJVM" varname="/J2EE/StandardSystem/Instances[$(Instance@INDEX)]/SapJvmDirectory"/>
        <get path="DIR_SAPJVM" varname="/J2EE/StandardSystem/Instances[$(Instance@INDEX)]/JDKHomeDirectory"/>
      </readProfile>       
     </for-each>
  </task>
</configuration>
