Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macrodef and "local properties"

Tags:

ant

macrodef

I am trying to move a file (specified by a pattern) to a given location in an Ant macrodef:

<macrodef name="extract">
    <attribute name="package"/> 
    <sequential>

        <!-- the path will contain the unique file in extracted regardless of the name -->
        <path id="source_refid">
            <dirset dir="${dep}/lib/@{package}/extracted/">
                <include name="@{package}-*"/>
            </dirset>
        </path>

        <!-- this is not working: properties are immutable -->
        <property name="source_name" refid="source_refid"/>

        <move
            file="${source_name}"
            tofile="${dep}/@{package}/"
            overwrite="true"
        />

    </sequential>
</macrodef>

This will work just once as ${source_name} is immutable.

An option would be to use the variable task but I didn't find a way to assign a refid to a var.

Is there a way to have something similar to local variable in a macrodef? Or (XY problem) is there a better way to solve my problem?

like image 624
Matteo Avatar asked Nov 28 '11 06:11

Matteo


1 Answers

Since Ant 1.8 you can use the local task for this. For example:

<local name="source_name"/>
<property name="source_name" refid="source_refid"/>

Your example is just the sort of thing local is for!

like image 75
martin clayton Avatar answered Sep 23 '22 07:09

martin clayton