ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Echlin, Robert" <Robert.Ech...@windriver.com>
Subject RE: Do things based on project success or failure
Date Thu, 02 Jun 2011 16:43:05 GMT
Hi Eric,
(code below)
Try the "depends with if/unless" pattern.

Note the "if" and "unless" parameters on the do.true and do.false targets.
"condition" sets a variable depending on something - in this case where a file exists or not.

The "top" level target does nothing except make sure other things happen in order. 
You might call that pattern "empty target orders actions".

Rob
---------

File check.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="Build rules for documentation sets" default="top">

  <target name="top" description="Does the given file exist?" depends="exists, do.true,
do.false"/>
  
  <target name="exists" 
          description="Check if a file exists">
    <condition property="file.exists">
      <available file="${file.name}"/>
    </condition>
  </target>

  <target name="do.true" if="file.exists">
    <echo>yay! it's true!</echo>
  </target>

  <target name="do.false" unless="file.exists">
    <echo>Darn! Try again!</echo>
  </target>

</project>

---------
Output of tests:
C:\depends-if>ant -f check.xml -Dfile.nam
=check.xml
Buildfile: C:\Documents and Settings\rechlin\My Documents\test\TEST-ant\depends-if\check.xml

exists:

do.true:
     [echo] yay! it's true!

do.false:

top:

BUILD SUCCESSFUL
Total time: 0 seconds

C:\depends-if>ant -f check.xml -Dfile.nam
=check.xmlOFF
Buildfile: C:\Documents and Settings\rechlin\My Documents\test\TEST-ant\depends-if\check.xml

exists:

do.true:

do.false:
     [echo] Darn! Try again!

top:

BUILD SUCCESSFUL
Total time: 0 seconds
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message