ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Cepek" <mce...@smsi.com>
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"
value="projecthelp_unix">
            <os family="unix"/>
        </condition>
        <condition property="projecthelp_target"
value="projecthelp_windows">
            <os family="windows"/>
        </condition>
        <condition property="projecthelp_target"
value="projecthelp_fail">
            <not>
                <or>
                    <os family="unix"/>
                    <os family="windows"/>
                </or>
            </not>
        </condition>
        <antcall target="${projecthelp_target}"/>
    </target>

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

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

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

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}"/>
        </ant>
    </target>
    :

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:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message