You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jeff Davidson <JD...@redhawkgaming.com> on 2004/10/21 22:23:30 UTC

vs

Ant-users,

I've started using <macrodef/> and <presetdef/> and before I get too far
down one path or another, I wanted to see what sort of wisdom you might
impart upon me.

Take, for example, the following two *def's:

	<presetdef name="my.preset.ant">
		<ant dir="NOT SET" antfile="build.xml" target="test" />
	</presetdef>

	<macrodef name="my.macro.ant">
		<attribute name="dir" />
		<attribute name="antfile" default="build.xml" />
		<attribute name="target" default="test" />
		<sequential>
			<ant dir="@{dir}" antfile="@{antfile}"
target="@{target}" />
		</sequential>
	</macrodef>

And the two following calls:

	<my.preset.ant dir="foo" />
	<my.macro.ant dir="foo" />

Both calls do exactly the same thing, and both allow overriding of all three
attributes, but their underlying definition is quite different.

Aside from the difference that <my.macro.ant/> requires the dir= attribute
to be set, whereas <my.preset.ant/> would simply fail (assuming
"${basedir}/NOT SET" doesn't exist!), are there other vagaries, differences,
or gotchas that are good to know?

Obviously, given no major differences, the <presetdef/> version is probably
preferable due, simply, to its readability.  Moreover, it seems to me that a
one-line <macrodef/> should simply be replaced by a <presetdef/>, with the
caveat that there is nothing to actually catch required properties that are
unset.  Are there any other twists that I'm overlooking?

Your thoughts are welcome,
~Jeff


Re: vs

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 21 Oct 2004, Jeff Davidson <JD...@redhawkgaming.com>
wrote:

> Aside from the difference that <my.macro.ant/> requires the dir=
> attribute to be set, whereas <my.preset.ant/> would simply fail
> (assuming "${basedir}/NOT SET" doesn't exist!), are there other
> vagaries, differences, or gotchas that are good to know?

Your macrodef-ed <ant> doesn't support any of the additional
attributes or nested elements of the <ant> task - the presetdef-ed one
does.  This may be good or bad, dependending on context.

In your example you'll probably prefer to the presetdef-ed version
since it still allows users to set the inheritAll attribute - but if
you wanted to enforce a specific value, macrodef could hide it away
for you.

This really comes down as the major difference between the two
approaches, presetdef only provides default values that can be changed
later, macrodef can enforce those values.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org