Search code examples
antant-contrib

Change values of list in ANT


I need to change the values of an ANT-script list in real time. This is the situation;

I have these properties:

x.y.6.1=something1
x.y.6.2=something2
x.y.6.3=something3

list=6.1,6.2

I want the list to become list=something1;something2

This is the gist of the code;

<target name="target1">
    <foreach list="${list}" target="target2" param="var" delimiter="," />
</target>

<target name="target2">
    <propertycopy name="var" from="x.y.${var}" silent="true"/>
</target>

Now, the propertycopy part works, however, it will not keep the new value. I tried many variations, none which worked. I am using ant-contrib.

Help would be much appreciated! Adam


Solution

  • I have solved the problem, in an icky way, but it works great!

    <project name="Test" default="main">
        <property file="agent.properties" />
        <property file="temp_updates.txt" />
        <taskdef name="propertycopy" classname="net.sf.antcontrib.property.PropertyCopy" />
        <taskdef name="foreach" classname="net.sf.antcontrib.logic.ForEach" />
    
        <target name="main">
            <property name="Agent Updates" value="6.1,6.2" />
            <antcall target="create_temp_files" />
            <antcall target="agent_updates_target" />
            <propertycopy name="custom.agent.release.group" from="updates" silent="true" override="true" />
        </target>
    
        <target name="agent_updates_target">
            <foreach list="${Agent Updates}" target="agent_version_to_path" param="var" delimiter="," />
        </target>
    
        <target name="agent_version_to_path">
            <propertycopy name="var" from="agent.installer.${var}" silent="true" override="true"/>
            <echo message="${var};" file="temp_updates.txt" append="true" />
        </target>
    
        <target name="create_temp_files">
            <echo message="updates=" file="temp_updates.txt" />
        </target>
    
    </project>
    

    on another file, "agent.properties" I had that;

    agent.installer.6.3=something3
    agent.installer.6.2=something2
    agent.installer.6.1=something1
    agent.installer.6.0=...
    agent.installer.5.6=...
    agent.installer.5.0.12=...
    agent.installer.5.0.11=...
    agent.installer.5.0.9.5=...
    agent.installer.3.8=...
    agent.installer.3.7=...
    

    As a result, a new file "temp_updates.txt" was created, having

    updates=something1;something2;
    

    Which I then loaded into the actual program.

    May not be pretty, but it works quite well.

    Thank you Skoll and Mark O'Connor for all your help, I used those ideas to come up with this one. I would rate you, but I can't :( Sorry!