ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Fetzer <elstonk...@yahoo.com>
Subject Re: Do things based on project success or failure
Date Thu, 02 Jun 2011 18:25:06 GMT
Not sure what you're answering here Robert.  Are you saying inside the exists 
target, call the other build file with subant and if it succeeds it will go to 
do.true or do.false?

Thanks,
Eric




________________________________
From: "Echlin, Robert" <Robert.Echlin@windriver.com>
To: Ant Users List <user@ant.apache.org>
Sent: Thu, June 2, 2011 10:43:05 AM
Subject: RE: Do things based on project success or failure

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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message