You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by snoofkin <ar...@arielbloch.com> on 2008/11/19 03:18:28 UTC
How to build an Ant path from a comma-seperated list?
Hi,
I would like to describe Java module dependencies as a comma-separated list,
and have Ant recursively clean/compile them.
This is possible using the following setup:
<path id="modules">
<pathelement location="${A.dir}"/>
<pathelement location="${B.dir}"/>
<pathelement location="${C.dir}"/>
</path>
<target name="clean-all">
<foreach target="clean" param="name">
<path refid="modules"/>
</foreach>
</target>
But I would like to move to a simple list, something like:
<property name="dependencies" value="A,B,C" />
is there a programmatic way to build a path from a list?
Thanks,
Ariel
--
View this message in context: http://www.nabble.com/How-to-build-an-Ant-path-from-a-comma-seperated-list--tp20572597p20572597.html
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
AW: AW: How to build an Ant path from a comma-seperated list?
Posted by Ja...@rzf.fin-nrw.de.
Not a one liner but a two-liner.
This is the technique I use often for displaying paths with <pathconvert> ...
<pathconvert property="p" pathsep="${line.separator}- ">
<fileset dir="." includes="*"/>
</pathconvert>
<property name="listing" value="- ${p}${line.separator}"/>
<echo>${listing}</echo>
The main task just calculates the middle part (${p}) and I have to put something before and after it.
In your case this is the same:
<property name="list" value="aaa,bbb,ccc"/>
<ac:propertyregex
property="pattern.internal"
input="${list}"
regexp=","
replace="/,**/"
/>
<property name="pattern" value="**/${pattern.internal}/"/>
<echo>Input List : '${list}'</echo>
<echo>Input Pattern: '${pattern}'</echo>
Jan
>-----Ursprüngliche Nachricht-----
>Von: snoofkin [mailto:ariel.nabble@arielbloch.com]
>Gesendet: Mittwoch, 19. November 2008 20:39
>An: user@ant.apache.org
>Betreff: Re: AW: How to build an Ant path from a comma-seperated list?
>
>
>Thanks for this idea!
>
>The problem is that the input list is of unknown size, and I
>could not find
>a regexp that will convert all items in this list correctly (I
>bet this can
>be done).
>
>So I came up with the following solution using <for>, <var> and
><propertyregex>:
>
> <var name="dependencies.path" value="" />
> <property name="input.list" value="aaa,bbb,ccc" />
>
> <target name="calculate-dependencies-path"
>description="Converts the
>input.list comma-seperated list to dependencies.path">
> <for param="item" list="${input.list}">
> <sequential>
> <propertyregex property="item.path"
> override="true"
> input="@{item}"
> regexp="(.+)"
> replace="**/\1\/"
> casesensitive="false"/>
> <var name="dependencies.path"
>value="${dependencies.path},${item.path}" />
> </sequential>
> </for>
> <echo>RESULT: ${dependencies.path}</echo>
> </target>
>
>This prints
> RESULT: ,**/aaa/,**/bbb/,**/ccc/
>
>If there is an easier solution using one line regexp I would
>gladly use it,
>as this is somewhat cumbersome.
>
>Thanks!
>Ariel
>--
>View this message in context:
>http://www.nabble.com/How-to-build-an-Ant-path-from-a-comma-sep
>erated-list--tp20572597p20587661.html
>Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: AW: How to build an Ant path from a comma-seperated list?
Posted by snoofkin <ar...@arielbloch.com>.
Thanks for this idea!
The problem is that the input list is of unknown size, and I could not find
a regexp that will convert all items in this list correctly (I bet this can
be done).
So I came up with the following solution using <for>, <var> and
<propertyregex>:
<var name="dependencies.path" value="" />
<property name="input.list" value="aaa,bbb,ccc" />
<target name="calculate-dependencies-path" description="Converts the
input.list comma-seperated list to dependencies.path">
<for param="item" list="${input.list}">
<sequential>
<propertyregex property="item.path"
override="true"
input="@{item}"
regexp="(.+)"
replace="**/\1\/"
casesensitive="false"/>
<var name="dependencies.path"
value="${dependencies.path},${item.path}" />
</sequential>
</for>
<echo>RESULT: ${dependencies.path}</echo>
</target>
This prints
RESULT: ,**/aaa/,**/bbb/,**/ccc/
If there is an easier solution using one line regexp I would gladly use it,
as this is somewhat cumbersome.
Thanks!
Ariel
--
View this message in context: http://www.nabble.com/How-to-build-an-Ant-path-from-a-comma-seperated-list--tp20572597p20587661.html
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
AW: How to build an Ant path from a comma-seperated list?
Posted by Ja...@rzf.fin-nrw.de.
If the modules have a common base directory you could use <ac:propertyregexp> for
building an include pattern from your list.
moduleA,moduleB --> **/moduleA/,**/moduleB/
Then specifying the path is
<path><fileset dir="COMMON_BASEDIR" includes="${CALCULATED_INCLUDE_PATTERN}"/></path>
But if you just want to iterate with <ac:for> or <ac:foreach> you could use simply their
"list" attribute.
Jan
>-----Ursprüngliche Nachricht-----
>Von: snoofkin [mailto:ariel.nabble@arielbloch.com]
>Gesendet: Mittwoch, 19. November 2008 03:18
>An: user@ant.apache.org
>Betreff: How to build an Ant path from a comma-seperated list?
>
>
>Hi,
>
>I would like to describe Java module dependencies as a
>comma-separated list,
>and have Ant recursively clean/compile them.
>
>This is possible using the following setup:
>
> <path id="modules">
> <pathelement location="${A.dir}"/>
> <pathelement location="${B.dir}"/>
> <pathelement location="${C.dir}"/>
> </path>
>
> <target name="clean-all">
> <foreach target="clean" param="name">
> <path refid="modules"/>
> </foreach>
> </target>
>
>But I would like to move to a simple list, something like:
> <property name="dependencies" value="A,B,C" />
>
>is there a programmatic way to build a path from a list?
>
>Thanks,
>Ariel
>--
>View this message in context:
>http://www.nabble.com/How-to-build-an-Ant-path-from-a-comma-sep
>erated-list--tp20572597p20572597.html
>Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org