Generate comma separated ist

114 Views Asked by At

I'm trying to create a build script which will call an external app that will be used to create several projects. When the external app is run, it may require some external libs to be passed to it. The issue is that for each project I won't know which libs (if any) are needed.

So in order to achieve this I thought the best approach would be as follows :

1) For each project create a lib.property file, that contains the list of external libs. i.e LIB1=xxx LIB2=ccc LIB3=yyy

2) Have my build script 'read' the property file to determine the external libs and then build it into the exec command line for the external app along with the external lib references. i.e myApp -lib1,lib2,lib3

Is this a sensible / doable approach ? I'm trying to write it up here, but if there's a better way in ANT I'd appreciate any advice ?

this is what I've written so far

<target name="info">
<echo>Reading lib file</echo>
<property file="lib.properties" prefix="x"/>
<propertyselector property="propertyList" delimiter="," match="LIB[0-9]" select="\0" />
<echo> List LIBS in loop</echo>
<for list="${propertyList}" param="sequence">
<sequential>
<echo>${x.@{sequence}}</echo>
</sequential>
</for>
</target>
1

There are 1 best solutions below

2
On BEST ANSWER

Using var task

<project name="MyProject" default="info" basedir=".">
    <target name="info">
        <taskdef resource="net/sf/antcontrib/antcontrib.properties">
            <classpath>
                <pathelement location="${basedir}/ant-contrib-0.6.jar"/>
            </classpath>
        </taskdef>

        <echo>Reading lib file</echo>
        <property file="lib.properties" prefix="x"/>
        <propertyselector property="propertyList" delimiter="," match="LIB[0-9]" select="\0" />
        <echo> List LIBS in loop</echo>

        <var name="x" value=""/>
        <for list="${propertyList}" param="sequence">
            <sequential>
                <echo>${x.@{sequence}}</echo>
                <var name="x" value="${x.@{sequence}},${x}"/>
            </sequential>
        </for>
        <var name="x" value="-${x}"/>

        <echo>Final: ${x}</echo>
    </target>
</project>

But is doesn't work perfect:

 info:
 [echo] Reading lib file
 [echo]  List LIBS in loop
 [echo] yyy
 [echo] ccc
 [echo] xxx
 [echo] Final: -xxx,ccc,yyy,