开发者

Ant propertyset inheritance with nested tasks

开发者 https://www.devze.com 2023-01-12 23:10 出处:网络
I have a s开发者_Python百科et of nested Ant build files, and I need to control which properties are inherited by each \"sub\" task. I\'m trying to define these as propertysets (to keep the code manage

I have a s开发者_Python百科et of nested Ant build files, and I need to control which properties are inherited by each "sub" task. I'm trying to define these as propertysets (to keep the code manageable) but these are not inherited by subtasks, unlike properties.

The example below demonstrates the problem, foo.* get copied into the middle project but not to the bottom project. If I define each property to be inherited explicitly, like bar.*, they get inherited by the bottom project too.

Is there any way to get a group of properties to inherit all the way down, in the same way individual properties do? Without rewriting the sub-processes, is there something else I could try?

[top.xml]

<?xml version="1.0"?>
<project name="test-top">
    <property name="foo.1" value="1"/>
    <property name="foo.2" value="2"/>
    <property name="bar.1" value="1"/>
    <property name="bar.2" value="2"/>

    <ant antfile="middle.xml" inheritall="false">
        <propertyset>
            <propertyref prefix="foo."/>
        </propertyset>
        <property name="bar.1" value="${bar.1}"/>
        <property name="bar.2" value="${bar.2}"/>
    </ant>
</project>

[middle.xml]

<?xml version="1.0"?>
<project name="test-middle">

    <echo>foo ${foo.1} ${foo.2}</echo>
    <echo>bar ${bar.1} ${bar.2}</echo>

    <ant antfile="bottom.xml" inheritall="false"/>
</project>

[bottom.xml]

<?xml version="1.0"?>
<project name="test-bottom">

    <echo>foo ${foo.1} ${foo.2}</echo>
    <echo>bar ${bar.1} ${bar.2}</echo>

</project>

[OUTPUT OF ant -f top.xml]

 [echo] foo 1 2
 [echo] bar 1 2
 [echo] foo ${foo.1} ${foo.2}
 [echo] bar 1 2


I think Alexander's solution is close. How about this though, doesn't need any change in middle.xml or bottom.xml.

The idea is to use the echoproperties task to 'unroll' the propertyset to individual properties, then to use that in the ant task call.

Before calling middle.xml, write the property set out using something like this:

<echoproperties destfile="myproperties.txt">
    <propertyset>
        <propertyref prefix="foo."/>
        <propertyref prefix="bar."/>
    </propertyset>
</echoproperties>

Then make the call to middle.xml:

<ant antfile="middle.xml" inheritall="false">
    <property file="myproperties.txt" />
</ant>

Properties supplied to the ant task inherit all the way down as you say, so you only need to change top.xml:

These properties become equivalent to properties you define on the command line. These are special properties and they will always get passed down, even through additional <ant> tasks with inheritall set to false (see above).


In top.xml you can create a file with inheritable properties using <propertyfile> task.

Then you can load this file with <property file="..."/>in each of your submodules.

0

精彩评论

暂无评论...
验证码 换一张
取 消