ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <>
Subject Re: fail-safe O/S-dependent operations idiom?
Date Thu, 18 Jul 2002 22:18:41 GMT
--- Mike Cepek <> wrote:
> O great Ant gurus :-) I seek a clean way to perform operating-system
> dependent operations with a fail-safe check in case the O/S isn't
> supported.  Is there already an idiom out there for this?

  <target name="setArgs" description="Set up projecthelp args">
    <condition property="antcmd" value="ant">
      <os family="unix"/>
    <condition property="antcmd.args" value="-projecthelp">
      <os family="unix"/>
    <condition property="antcmd" value="cmd.exe">
      <os family="windows"/>
    <condition property="antcmd.args" value="/c ant -projecthelp">
      <os family="windows"/>
    <fail unless="antcmd"
          message="Projecthelp target not yet configured for this OS."/>

  <target name="projecthelp" depends="setArgs" description="Print usage">
    <exec dir="${ant_loc}" executable="${antcmd}">
      <arg line="${antcmd.args}"/>

>             <property name="ant_loc" value="${my_dir}"/>

When setting locations, you should use the 'location' attribute.

> I'm particularly interested in better ways to do the first snippet above
> WITHOUT the O/S name repetition.

Unfortunately, <condition> only sets one property (maybe something for
Dominique to consider for his <propertyset> addition?), so there is still
a bit of redundancy, but hopefully it's a bit cleaner than what you had.

> Extra Credit:  Anyone know why <exec> and <condition> use two different
> sets of names for O/Ses?  I know THAT they do; I'm curious about WHY...

I don't think they do -- not for 'name', anyway. (You're welcome to prove
me wrong, though.)



Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message