Bug 53723 - [Patch] Local task: local by prefix, all local, New: global task
Summary: [Patch] Local task: local by prefix, all local, New: global task
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: unspecified
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-15 07:32 UTC by Ralf
Modified: 2012-09-15 05:31 UTC (History)
0 users



Attachments
Patch with improved local task, the new global task and antunit test (21.86 KB, patch)
2012-08-15 07:32 UTC, Ralf
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf 2012-08-15 07:32:50 UTC
Created attachment 29236 [details]
Patch with improved local task, the new global task and antunit test

Recently I had the need to better control local properties within
a macrodef.

1) All properties with a given prefix should be local.
   Needed for:
     <xmlproperty file="@{src}"  prefix="prefix" />

2) All properties in the current scope should be local.

3) Create a way to exclude a certain property from the
   extensive local restriction defined by the previous points.


Examples:

    <sequential>
        <!-- all properties with the prefix "local." are local -->
        <local prefix="local" />
    </sequential>

    <sequential>
        <!-- all properties in this sequential are local -->
        <local/>
    </sequential>

    <sequential>
        <!-- all properties in this sequential are local ... -->
        <local/>
        <!-- ... except the property gFoo -->
        <global name="gFoo" />
    </sequential>


Updated task "local": 

1) New attribut "prefix": All properties with the given prefix are handled as
   local properties. 
   - If the prefix is empty a BuildException is thrown.
   - If the prefix does not end with a "." one is appended.

2) Without any attribute, all properties are local.

Usage:

     <!-- foo is a local property - like today -->
     <local name="foo" />

     <!-- All properties with the prefix "local." are local -->
     <local prefix="local" />

     <!-- all properties are local -->
     <local/>


New task "global":

Well, if I can restrict scope like that, it might be that I need a way to
declare all but a special property as local. So I introduced the task global.
The global task is only useful with a accompanied local task.  Otherwise it
has no effect.

Attributes:

   name: The name of the global property
   prefix: All properties with the given prefix are handled as
       global properties. 
       - If the prefix is empty a BuildException is thrown.
       - If the prefix does not end with a "." one is appended.

Usage:
     <!-- all properties are local, except "global.foo" -->
     <local/>
     <global name="global.foo" />
    
     <!-- all properties are local, except those prefixed with "global." -->
     <local/>
     <global prefix="global" />


Note: "global" does not really mean global. In the following example
"foo" is global for the inner sequential but is marked local in the
outer sequential. So it is not visible outside the outer sequential.
From this point of view the name "global" is not 100% correct.

    <target ...
    
        <sequential>
            <local name="foo" />
            <sequential>
                <!-- all but foo are local -->
                <local all="true"/>
                <global name="foo" />
                <property name="foo" value="isset" />
            </sequential>
            <!-- property foo is set -->
        </sequential>
        <!-- property foo is NOT set -->

    </target>


Some strange usage:

The global task always overrules a local task. Independant of the order.
Should this be changed? How?

    <target name="strange">
        <sequential>
            <!-- Property 'strange' is local -->
            <local name="strange" />
            <property name="strange" value="bar" />
            <echo message="inner local strange: ${strange}" />

            <!-- Now property 'strange' is global -->
            <global name="strange" />
            <echo message="1. inner global strange: ${strange}" />
            <property name="strange" value="bar2" />
            <echo message="2. inner global strange: ${strange}" />

            <!-- declaring it local again has no effect -->
            <local name="strange" />
            <echo message="3. inner global strange: ${strange}" />
        </sequential>
        <echo message="global strange: ${strange}" />
    </target>

Output:

    strange:
    inner local strange: bar
    1. inner global strange: ${strange}
    2. inner global strange: bar2
    3. inner global strange: bar2
    global strange: bar2



The attached patch contains:
- Updated local task, LocalProperties and LocalPropertyStack
- New task global
- Updated antunit tests (src/tests/antunit/taskdefs/local-test.xml)


I would further refine this if needed and also update documentation if this is
considered for inclusion in ant.