转换ant路径而不分配给不可变属性

时间:2010-08-20 20:30:14

标签: java ant

我的情况是我有一个包含多个路径段的路径,并且,对于每个路径段,我需要转换该路径段(可能使用映射器),然后传递原始路径段并转换路径段到宏。

问题在于,我不清楚如何转换路径,而不将转换后的路径分配给不可变属性。

稍微简化的构建文件如下所示。

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="scxml-js" basedir="." default="generate-javascript">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${basedir}/lib/build-java/ant-contrib-0.6.jar" />
    </classpath>
  </taskdef>

  <property name="backends" value="switch,table,state"/>
  <property name="browsers" value="firefox,ie,chrome"/>
  <property name="for-ie" value="is-for-ie,is-not-for-ie"/>

  <path id="scxml-tests-xml">
    <pathelement location="test/kitchen_sink/KitchenSink.xml"/>
    <pathelement location="test/kitchen_sink/KitchenSink_dataModule.xml"/>
    <!-- ... -->
  </path>

  <!-- the macro call java with specific arguments -->
  <macrodef name="compile-with-scxml-js">
    <attribute name="backend"/>
    <attribute name="test-path"/>
    <attribute name="out-path"/>

    <sequential>
      <java classname="org.mozilla.javascript.tools.shell.Main" output="@{out-path}">
        <classpath>
          <pathelement location="lib/java/js.jar"/>
           <!-- ... -->
        </classpath>
        <arg value="${basedir}/runner.js"/>
        <arg value="${basedir}"/>
        <arg value="src/javascript/scxml/cgf/main"/>

        <arg value="--backend=@{backend}"/>
        <arg value="--beautify"/>
        <arg value="--ie"/>
        <arg value="@{test-path}"/>
      </java>
    </sequential>
  </macrodef>

  <!-- run unit and performance tests -->
  <target name="generate-javascript">

    <for list="${for-ie}" param="for-ie">
      <sequential>
        <for list="${backends}" param="backend">
          <sequential>
            <for param="test-path">
              <path refid="scxml-tests-xml"/>
              <sequential>

                <!-- do some manipulation -->
                <pathconvert property="target-test-path">
                  <path path="@{test-path}"/>
                  <chainedmapper>
                    <flattenmapper/>
                    <globmapper from="*.xml" to="build/@{backend}/@{for-ie}/*.js"/>
                  </chainedmapper>
                </pathconvert>

                <dirname property="target-test-path-dir" file="${target-test-path}"/>

                <echo>${target-test-path}, ${target-test-path-dir}</echo> 

                <!-- execute some tasks, call a macro -->

                <mkdir dir="${target-test-path-dir}"/>

                <compile-with-scxml-js-ie
                  test-path="@{test-path}"
                  backend="@{backend}"
                  out-path="${target-test-path}"/>
              </sequential>
            </for>
          </sequential>
        </for>
      </sequential>
    </for>
  </target>

</project>

因为target-test-path和target-test-path-dir只会被分配一次,所以会反复回复以下内容: [echo] build / switch / is-for-ie / KitchenSink.js,/ home / jacob / workspace / gsoc2010 / git-scxml-js / scxml -js / build / switch / is-for-ie

我很感激任何人都可以提供任何指导。

1 个答案:

答案 0 :(得分:2)

您可以使用参数值来构造属性名称,如下所示:

<!-- do some manipulation -->
<pathconvert property="@{backend}.@{for-ie}.target-test-path">
  <path path="@{test-path}"/>
  <chainedmapper>
    <flattenmapper/>
    <globmapper from="*.xml" to="build/@{backend}/@{for-ie}/*.js"/>
  </chainedmapper>
</pathconvert>

<dirname
  property="@{backend}.@{for-ie}.target-test-path-dir"
  file="${@{backend}.@{for-ie}.target-test-path}"
/>

<echo>${@{backend}.@{for-ie}.target-test-path}, ${@{backend}.@{for-ie}.target-test-path-dir}</echo> 

<!-- execute some tasks, call a macro -->

<mkdir dir="${@{backend}.@{for-ie}.target-test-path-dir}"/>

<compile-with-scxml-js-ie
  test-path="@{test-path}"
  backend="@{backend}"
  out-path="${@{backend}.@{for-ie}.target-test-path}"
/>