You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Daniels, Troy (US SSA)" <tr...@baesystems.com> on 2008/01/02 22:08:19 UTC
Returning properties
I have a pattern that is repeated several times, so I'm trying to
extract it into separate tasks in a common build file. I think I'm
running into problems because I'm trying to treat ant more like a
functional language than it is.
In several places, I have targets that look like this
<target name="generate-foo" depends="check-foo-up-to-date"
unless="foo-up-to-date">
<do-generation param="foo">
<stuff value="foo" />
</do-generation>
</target>
<target name="check-foo-up-to-date">
<dependset>
<!-- several srcfileset and targetfileset -->
<targetfilelist dir="." files="foo-test-file" />
</dependset>
<available file="foo-test-file" property="foo-up-to-date"/>
</target>
When ant tries to run generate-foo, it first runs check-foo-up-to-date,
which sets foo-up-to-date if foo is up to date. If foo is up to date,
the unless parameter means the generate-foo target isn't run and all is
good.
If I try to factor out the common parts, there are a few things that
need to be parameterized, which prevents me from calling them with a
simple depends attribute. Instead, I'm using antcall and the new
targets look like
<target name="generate-foo" depends="check-foo-up-to-date"
unless="foo-up-to-date">
<antcall target="generate">
<param name="name" value="foo"/>
</antcall>
</target>
<target name="check-foo-up-to-date">
<antcall target="check-up-to-date">
<param name="file" value="foo-test-file"/>
<param name="property" value="foo-up-to-date"/>
</antcall>
</target>
with generate and check-up-to-date being the new, generic tasks. This
appears to work, except that foo-up-to-date doesn't get updated in the
original project, only the project associated with the antcall. Is
there a good way to get the property back to the original project? I
could do it with files and available, but I'd like something simple to
put into the multiple copies of check-*-up-to-date.
Troy
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Returning properties
Posted by Cyril Sagan <Cy...@sas.com>.
Troy - You're having *exactly* the same problem I had three weeks ago.
Here's the full thread from suggestions I got:
http://www.opensubscriber.com/message/user@ant.apache.org/8193149.html
The best solution I came up with was to use ant-contrib's <antcallback/>, it can take a list of properties to return values back to the calling context.
I think you'll want something like:
<antcallback target="check-up-to-date" return="foo-up-to-date" />
The one disadvantage of <antcallback/> vs. <antcall/> is that <antcallback/> does not support multiple nested <target name=""/> like <antcall/> does (in 1.7 at least). This isn't a huge problem, but caused me to introduce more wrapper targets. Not sure if this will be an issue for you.
Hope this helps.
--Cyril
-----Original Message-----
From: Daniels, Troy (US SSA) [mailto:troy.daniels@baesystems.com]
Sent: Wednesday, January 02, 2008 4:08 PM
To: user@ant.apache.org
Subject: Returning properties
I have a pattern that is repeated several times, so I'm trying to
extract it into separate tasks in a common build file. I think I'm
running into problems because I'm trying to treat ant more like a
functional language than it is.
In several places, I have targets that look like this
<target name="generate-foo" depends="check-foo-up-to-date"
unless="foo-up-to-date">
<do-generation param="foo">
<stuff value="foo" />
</do-generation>
</target>
<target name="check-foo-up-to-date">
<dependset>
<!-- several srcfileset and targetfileset -->
<targetfilelist dir="." files="foo-test-file" />
</dependset>
<available file="foo-test-file" property="foo-up-to-date"/>
</target>
When ant tries to run generate-foo, it first runs check-foo-up-to-date,
which sets foo-up-to-date if foo is up to date. If foo is up to date,
the unless parameter means the generate-foo target isn't run and all is
good.
If I try to factor out the common parts, there are a few things that
need to be parameterized, which prevents me from calling them with a
simple depends attribute. Instead, I'm using antcall and the new
targets look like
<target name="generate-foo" depends="check-foo-up-to-date"
unless="foo-up-to-date">
<antcall target="generate">
<param name="name" value="foo"/>
</antcall>
</target>
<target name="check-foo-up-to-date">
<antcall target="check-up-to-date">
<param name="file" value="foo-test-file"/>
<param name="property" value="foo-up-to-date"/>
</antcall>
</target>
with generate and check-up-to-date being the new, generic tasks. This
appears to work, except that foo-up-to-date doesn't get updated in the
original project, only the project associated with the antcall. Is
there a good way to get the property back to the original project? I
could do it with files and available, but I'd like something simple to
put into the multiple copies of check-*-up-to-date.
Troy
---------------------------------------------------------------------
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