简体   繁体   中英

how can I use the for loop inside the copy task in ant script

I have a file which is having some variables, I want to copy each line from this to other file except for the lines which has the type=Password .

here is the sample file.

<Environment xsi:type="amxdata:Environment" name="@AMX_ENVIRONMENT_NAME@">  
    <SVar xsi:type="amxdata_base:SubstitutionVariable" name="FF_JDBC_USERNAME" type="String" value="@SVAR_ENV_JDBC_USERNAME@" />
    <SVar xsi:type="amxdata_base:SubstitutionVariable" name="FF_JDBC_PASSWORD" type="Password" value="@SVAR_ENV_JDBC_PASSWORD@" />
        <SVar xsi:type="amxdata_base:SubstitutionVariable" name="MON_JMS_USERNAME" type="String" value="@MON_EMS_USER@" />
    <SVar xsi:type="amxdata_base:SubstitutionVariable" name="MON_JMS_PASSWORD" type="Password" value="@MON_EMS_PASSWORD@" />        
    </Environment>

Output file:

<Environment xsi:type="amxdata:Environment" name="@AMX_ENVIRONMENT_NAME@">  
    <SVar xsi:type="amxdata_base:SubstitutionVariable" name="FF_JDBC_USERNAME" type="String" value="@SVAR_ENV_JDBC_USERNAME@" />
        <SVar xsi:type="amxdata_base:SubstitutionVariable" name="MON_JMS_USERNAME" type="String" value="@MON_EMS_USER@" />
</Environment>

This is how I would accomplish your task. It reads in.xml into property xml-content excluding the lines with type="Password" and prints the new contents into out.xml .

<target name="strip-passwords">
  <loadfile property="xml-content" srcFile="in.xml" >
    <filterchain>
      <linecontainsregexp negate="true"> 
        <regexp pattern="\Qtype=&quot;Password&quot;\E"/> 
      </linecontainsregexp>
    </filterchain>
  </loadfile>
  <echo message="${xml-content}" file="out.xml"/>
</target>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM