ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Cepek" <>
Subject fail-safe O/S-dependent operations idiom?
Date Thu, 18 Jul 2002 21:10:08 GMT
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?

Here's what I have come up with so far:

    <target name="projecthelp" description="Usage">
        <condition property="projecthelp_target"
            <os family="unix"/>
        <condition property="projecthelp_target"
            <os family="windows"/>
        <condition property="projecthelp_target"
                    <os family="unix"/>
                    <os family="windows"/>
        <antcall target="${projecthelp_target}"/>

    <target name="projecthelp_unix">
        <exec dir="${ant_loc}" taskname="" executable="ant" os="Linux">
            <arg line="-projecthelp"/>

    <target name="projecthelp_windows">
        <exec dir="${ant_loc}" taskname="" executable="cmd.exe"
                os="Windows 2000">
            <arg line="/c ant -projecthelp"/>

    <target name="projecthelp_fail">
        <fail message="The projecthelp target is not yet configured for
this O/S"/>

I don't like the replication of the O/S names (unix and windows) in the
above.  I'm strongly opposed to needless redundancy, and really wish I
could avoid it here.

FYI, we use the above in our "Queen Ant" script to encapsulate using the
-projecthelp output of Ant as the default "target" when Ant is invoked
(i.e. no target -> usage).  Calling scripts look like this:

<?xml version="1.0"?>
<project name="common" default="projecthelp">
    <target name="projecthelp">
        <ant antfile="${QUEEN_ANT}" target="projecthelp">
            <property name="ant_loc" value="${my_dir}"/>

I'm particularly interested in better ways to do the first snippet above
WITHOUT the O/S name repetition.  But I'm open to comments, suggestions,
ideas, etc. about either excerpt.  Thanks!

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

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

View raw message