ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: fail-safe O/S-dependent operations idiom?
Date Thu, 18 Jul 2002 22:18:41 GMT
--- Mike Cepek <mcepek@smsi.com> 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>
    <condition property="antcmd.args" value="-projecthelp">
      <os family="unix"/>
    </condition>
    <condition property="antcmd" value="cmd.exe">
      <os family="windows"/>
    </condition>
    <condition property="antcmd.args" value="/c ant -projecthelp">
      <os family="windows"/>
    </condition>
    <fail unless="antcmd"
          message="Projecthelp target not yet configured for this OS."/>
  </target>

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

BTW:
>             <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.)

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com

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


Mime
View raw message