2010-08-20 91 views
0

我有一個情況,我有一個路徑段的路徑,並且,對於每個路徑段,我需要轉換該路徑段(推測使用映射器),然後將原始路徑段和經轉換的路徑段傳遞給宏。轉換螞蟻路徑,而不分配給不可變屬性

問題是,我不清楚如何轉換路徑,而不將轉換路徑分配給不可變屬性。

稍微簡化的構建文件如下。

<?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="[email protected]{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> 

由於目標測試路徑和目標測試路徑-DIR將只分配一次,這將反覆回聲以下: [回波]建立/開關/是換即/的KitchenSink。 js,/ home/jacob/workspace/gsoc2010/git-scxml -js/scxml -js/build/switch/is-for-ie

我很感謝任何人可以提供的指導。

回答

2

可以使用參數值來構建屬性名稱,像這樣:

<!-- do some manipulation --> 
<pathconvert property="@{backend}[email protected]{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}[email protected]{for-ie}.target-test-path-dir" 
    file="${@{backend}[email protected]{for-ie}.target-test-path}" 
/> 

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

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

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

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