Java Mailing List Archive

http://www.ant-tasks.com/

Home » Ant Users List »

convert ant path without assigning to immutable property

Jake Beard

2010-08-20

Replies: Find Java Web Hosting

Author LoginPost Reply
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="@(protected)}">
     <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=@(protected)}"/>
     <arg value="--beautify"/>
     <arg value="--ie"/>
     <arg value="@(protected)}"/>
    </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="@(protected)}"/>
            <chainedmapper>
             <flattenmapper/>
             <globmapper from="*.xml" to="build/@{backend}/@(protected)"/>
            </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="@(protected)}"
            backend="@(protected)}"
            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
to 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. Thanks,

Jake

PS: I've also posted this question on Stack Overflow:
http://stackoverflow.com/questions/3534659/convert-ant-path-without-assigning-to-immutable-property

©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.