tags:

views:

105

answers:

2

Hi,

I ve got a problem in getting properties with ant from a properties file. With a simple target like this in my build.xml, i'd like to get at least two properties path1 and path2. I'd like to have a generic target to get this two properties.... in order to avoid modifying the build.xml (just adding a new prop)

Any suggestions? Thanks in advance !

build.xml :

<target name="TEST" description="test ant">
    <property file="dependencies.properties"/>  
    <svn>  
        <export srcUrl="${path.prop}" destPath="${workspace}/rep/" />  
    </svn>  
</target>  

dependencies.properties :

path1.prop = /path/to/src1
path2.prop = /path/to/src2
A: 

You could write your path settings to a comma separated list in a single property and use a foreach loop

stacker
A: 

Thanks, it works. in addition you can use the propertycopy from ant-contrib to get other properties from the file.

dependencies.list=path1,path2
path1.prop1=val1
path1.prop2=val2
path2.prop1=val3
path2.prop2=val4

like this :

<target name="main">
    <property file="dependencies.properties"/>
    <foreach list="${dependencies.list}" delimiter="," param="name" target="doExtract" inheritall="true"/>
</target>

<target name="doExtract">
    <propertycopy name="prop1" from="${name}.prop1" silent="true"/>
    <propertycopy name="prop2" from="${name}.prop2" silent="true"/>
    <svn>
        <export srcUrl="${prop1}" destPath="${workspace}/rep/"" />
    </svn>
</target>
julia2020