tags:

views:

36

answers:

1

Hi,

I have a situation where I have a path with a number of path segments, and, for each path segment, I need to transform that path segment (presumably using a mapper), and then pass the original path segment AND the transformed path segment to a macro.

The problem is that it's not clear to me how to transform the path, without assigning the transformed path to an immutable property.

The slightly simplified build file is below.

<?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>

Because target-test-path and target-test-path-dir will only be assigned once, this will repeatedly echo the following: [echo] build/switch/is-for-ie/KitchenSink.js, /home/jacob/workspace/gsoc2010/git-scxml-js/scxml-js/build/switch/is-for-ie

I'd appreciate any guidance anyone can offer.

+2  A: 

You can use parameter values to construct property names, like this:

<!-- 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}"
/>
Alexander Pogrebnyak