Xml ant replaceregexp,与变量/属性匹配

Xml ant replaceregexp,与变量/属性匹配,xml,regex,ant,Xml,Regex,Ant,这应该是一个常见的问题,但我不知道怎么做,希望在这里得到一些指导 问题: 我需要使用ant替换一组XML配置文件(weblogic config.XML文件)中的一些但不是所有应用程序版本(ant contrib也可以使用) 我有一个应该设置新版本的应用程序列表,以及它们应该具有的版本,我有需要替换的配置文件 我迄今为止所走的道路: 我创建了一个包含三个参数的宏;应用程序名称、应用程序版本和配置文件 这将从循环中调用 以下是我现在拥有的: <macrodef name="update-te

这应该是一个常见的问题,但我不知道怎么做,希望在这里得到一些指导

问题:

我需要使用ant替换一组XML配置文件(weblogic config.XML文件)中的一些但不是所有应用程序版本(ant contrib也可以使用)

我有一个应该设置新版本的应用程序列表,以及它们应该具有的版本,我有需要替换的配置文件

我迄今为止所走的道路:

我创建了一个包含三个参数的宏;应用程序名称、应用程序版本和配置文件

这将从循环中调用

以下是我现在拥有的:

<macrodef name="update-template-config-file">
  <attribute name="application-name" />
  <attribute name="application-version" />
  <attribute name="config-file-name" />

  <sequential>

    <local name="match-string"/>
    <local name="replace-string"/>
    <property name="match-string" value="@{application-name}#[0-9](\.[0-9])*"/>
    <property name="replace-string" value="@{application-name}#@{application-version}"/>

    <echo>match ${match-string} replace: ${replace-string} in @{config-file-name}</echo>

    <replaceregexp file="@{config-file-name}"
      match="${match-string}"
      replace="${replace-string}"
      byline="true"/>
  </sequential>

</macrodef>

match${match string}replace:${replace string}位于@{config file name}
因此,问题是replaceregexp的match部分被解释为正则表达式(正确),我想知道是否有方法使用“match string”属性的值而不是它的名称

解决方法:

从ant脚本中,通过每个循环回显替换指令来创建一个新的ant脚本,然后调用创建的ant文件来执行替换

为了完整性,请将调用宏的位置作为目标

<target name="update-template-config-files">
  <for param="config-file">
     <path>
       <fileset dir="${RP_CONTENT_ROOT_DIR}/domain_templates" includes="**/config.xml"/>
     </path>
    <sequential>
      <for param="application-file">
        <path>
          <fileset dir="${STAGE_ROOT}/applications" includes="*.*"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{application-file}"/>
          <update-template-config-file application-name="${filename}" application-version="5.1.0.3.0" config-file-name="@{config-file}" />
        </sequential>
      </for>
    </sequential>
  </for>
</target>

我的脚本出错,忘记从应用程序名称中删除后缀

谢谢vio1331让我再看一次回音线

在下面找到可用的更新代码段(但仅适用于ear文件)



echo工作正常吗?您好,是的,这是一个替换真实应用程序名和路径后的示例:[echo]匹配一些应用程序.ear[0-9](\[0-9])*替换:一些/some/path/config/config.xml中的一些应用程序.ear[5.1.0.3.0我正在编写一个ant任务。实际上我发现了一个错误,忘了删除后缀(例如.ear)。我会试试的。
<target name="update-template-config-files">
  <for param="config-file">
     <path>
       <fileset dir="${RP_CONTENT_ROOT_DIR}/domain_templates" includes="**/config.xml"/>
     </path>
    <sequential>
      <for param="application-file">
        <path>
          <fileset dir="${STAGE_ROOT}/wlng/applications" includes="*.ear"/>
        </path>
        <sequential>
        <local name="filename"/>
        <basename property="filename" file="@{application-file}" suffix=".ear"/>
        <update-template-config-file application-name="${filename}" application-version="5.1.0.3.0" config-file-name="@{config-file}" />
        </sequential>
      </for>
    </sequential>
  </for>
</target>