Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant脚本通过属性文件循环并动态替换值_Ant_Ant Contrib_Xmltask - Fatal编程技术网

Ant脚本通过属性文件循环并动态替换值

Ant脚本通过属性文件循环并动态替换值,ant,ant-contrib,xmltask,Ant,Ant Contrib,Xmltask,我需要遍历一些XML文件,替换其中特定于环境的值,并创建一组新的XML文件。特定于环境的值将取自属性文件。我能够通过一个目录循环读取所有文件,并使用xmltask替换某些特定值,如下所示 <target name="updateConfig" description="update the configuration" depends="init"> <xmltask todir="${ConfigDestDirectory}" report="false"

我需要遍历一些XML文件,替换其中特定于环境的值,并创建一组新的XML文件。特定于环境的值将取自属性文件。我能够通过一个目录循环读取所有文件,并使用xmltask替换某些特定值,如下所示

    <target name="updateConfig" description="update the configuration" depends="init">      
<xmltask todir="${ConfigDestDirectory}" report="false" failwithoutmatch="true">
       <fileset dir="${ConfigSourceDirectory}">
            <include name="*.xml"/>    
       </fileset>               
      <replace path="/:application/:NVPairs/:NameValuePair[:name='Connections/HTTP/HostName']/:value/text()" withXml="localhost"/>          
        </xmltask>
     <echo>Replaced Successfully</echo>
    </target>

成功替换
但是我想通读一个属性文件并从中获取路径/值。 我尝试使用属性选择器、属性、变量作为本例的不同选项,并设法获取路径而不是值。下面是属性文件的片段和我正在使用的目标

#DEV.properties
HostName.xpath=/:application/:NVPairs/:NameValuePair[:name='Connections/HTTP/HostName']/:value/text()
HostName.value=localhost

<project name="TestBuild" default="ReadPropertyFile" basedir=".">
    <target name="init">        
            <property file="DEV.properties"/>
            <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="${xmltaskPath}"/>
            <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${antcontribPath}"/>
            <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
        </target>

    <target name="ReadPropertyFile" description="update the configuration" depends="init">      
                <property file="DEV.properties" prefix="x"/>        
                <propertyselector property="propertyList" delimiter="," select="\0" match="([^\.]*)\.xpath" casesensitive="true" distinct="true"/>      
                <for list="${propertyList}" param="sequence">               
                <sequential>
                    <propertyregex property="destproperty" input="@{sequence}" regexp="([^\.]*)\." select="\1" />                   
                    <property name="tempname" value="${destproperty}.value" />      
                    <var name="localprop" value="${tempname}"/>
                    <echo> @{sequence} </echo>  
                    <echo> ${x.@{sequence}} </echo>
                    <echo>destproperty --> ${destproperty}</echo>
                    <echo>tempname --> ${tempname}</echo>
                    <echo> localprop --> ${localprop}</echo>    
                    <echo>${x.${localprop}} </echo> <!--This is not working -->
                </sequential>               
                </for>          
            </target> 
#开发属性
HostName.xpath=/:application/:NVPairs/:NameValuePair[:name='Connections/HTTP/HostName']/:value/text()
HostName.value=localhost
@{序列}
${x.@{sequence}
destproperty-->${destproperty}
tempname-->${tempname}
localprop-->${localprop}
${x.${localprop}}
如果你们能帮我点忙的话会很有帮助的

谢谢,
文卡特

这样会更好吗

我想你把自己和“x”前缀搞混了


@{序列}
@{sequence}.xpath=${x.@{sequence}.xpath}
@{sequence}.value=${x.@{sequence}.value}

我将下面的脚本调整为使用select=“\1”(选择第一个匹配项)而不是select=“\0”选择整个字符串。嗨,帕特里斯,非常感谢。它工作得很好。你说得对,我把前缀x弄糊涂了,对语法也不太清楚。而且,在我更改ant的版本之前,本地属性不起作用。我现在就开始,太好了!这个
<project name="TestBuild" default="ReadPropertyFile" basedir=".">
    <target name="init">        
        <property file="DEV.properties"/>
        <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="${xmltaskPath}"/>
        <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${antcontribPath}"/>
        <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    </target>

    <target name="ReadPropertyFile" description="update the configuration" depends="init">      
          <property file="DEV.properties" prefix="x"/>        
          <local name="propertyList"/>
          <propertyselector property="propertyList" delimiter="," select="\1" match="x\.([^\.]*)\.xpath" casesensitive="true" distinct="true"/>      
          <for list="${propertyList}" param="sequence">               
            <sequential>
                <echo> @{sequence} </echo>  
                <echo> @{sequence}.xpath = ${x.@{sequence}.xpath} </echo>
                <echo> @{sequence}.value = ${x.@{sequence}.value} </echo>
            </sequential>               
          </for>          
    </target> 
</project>