ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: fail-safe O/S-dependent operations idiom?
Date Thu, 18 Jul 2002 22:48:04 GMT
Sure, that's a good way to run an os-specific command I guess, but to get an
help or using target to use the built-in -project of Ant (which seems to be
the ultimate goal here), simply do (as posted a few weeks ago, with output
for Ant 1.4.1 and 1.5beta):

  <target name="usage">
    <java classname="org.apache.tools.ant.Main">
      <arg value="-projecthelp" />
      <arg value="-buildfile" />
      <arg value="${ant.file}" />
    </java>
  </target>

And Diane, I'm not sure I follow the link between <condition> and
<propertyset>? --DD

-----Original Message-----
From: Diane Holt [mailto:holtdl@yahoo.com] 
Sent: Thursday, July 18, 2002 5:19 PM
To: Ant Users List
Subject: Re: fail-safe O/S-dependent operations idiom?

--- 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>

--
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