ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shackelford, John-Mason" <Sha...@ncs.com>
Subject RE: Problem with Properties.
Date Mon, 21 Oct 2002 15:45:34 GMT
Paul,

Using antcall typically duplicates the running of tasks since it doesn't use
the same dependency tree to run called task but instead creates a whole new
environment for them to run in. Converting your antcall lines to depends
attributes and using the if/unless syntax is the best way to ensure that you
don't get duplicate calls to a target.

Note that if you are calling multiple targets from the command line then
each is like a new ant invocation except that some overhead is removed.
Without setting some flag external to the buildfile, one can't prevent
multiple calls to a target when multiple targets are specified on the
command line.


So    
   
<target name="all" depends="init" unless="all.done">
  <antcall target="checkIP" />
  <antcall target="email" />
  <antcall target="cleanup" />
  <property name="all.done" value="true" />
</target>

Would become:

<target name="all" depends="init,checkIP,email,cleanup"/>

John-Mason Shackelford

Software Developer
NCS Pearson - Measurement Services
2510 North Dodge St.
Iowa City, IA 52245
319-354-9200x6214
shacjo@ncs.com



-----Original Message-----
From: Paul.Gower@alltel.com [mailto:Paul.Gower@alltel.com] 
Sent: Monday, October 21, 2002 10:20 AM
To: ant-user@jakarta.apache.org
Subject: Problem with Properties.


Examining the following ant build file.  Could someone please tell me why it
is continually running the "create" task even though I'm trying to set the
property after it is run once?  Basically I don't care if I do it this way
or another way...I just want to know how to keep tasks from being run more
than once.  It seems to be working in the init task but not in the other
tasks where I mimic the same property behavior. Thanks for your help.


ANT BUILD FILE:
<project name="sprayIP" default="all" basedir=".">

   <target name="init" unless="init.done">
      <echo message="init.done = ${init.done}" />
      <property name="EMAIL_LIST" value="me@myhost.com" />
      <property name="OLD_IP_FILENAME" value="IP-old.txt" />
      <property name="NEW_IP_FILENAME" value="IP-new.txt" />
      
      <property name="init.done" value="true" />
      <echo message="init.done = ${init.done}" />
   </target>

   <target name="create" depends="init" unless="create.done">
      <echo message="create.done = ${create.done}" />
      <exec executable="getIP.bat">
         <arg value="${NEW_IP_FILENAME}" />
      </exec>
      
      <property name="create.done" value="true" />
      <echo message="create.done = ${create.done}" />
   </target>

   <target name="email" depends="init, create, checkIP"
unless="ip.not.changed">
      <mail from="MAX" tolist="${EMAIL_LIST}" 
            subject="MAX IP ADDRESS" files="${NEW_IP_FILENAME}"
            mailhost="MYMAILHOST"/>
   </target>

   <target name="cleanup" depends="init, email">
      <move file="${NEW_IP_FILENAME}" tofile="${OLD_IP_FILENAME}"
overwrite="yes" />
   </target>

   <target name="all" depends="init" unless="all.done">
      <antcall target="checkIP" />
      <antcall target="email" />
      <antcall target="cleanup" />

      <property name="all.done" value="true" />
   </target>
    
   <target name="checkIP" depends="init, create" unless="checkIP.done">
      <condition property="ip.not.changed">
         <filesmatch file1="${NEW_IP_FILENAME}" file2="${OLD_IP_FILENAME}"
/>
      </condition>

      <echo message="ip.not.changed = ${ip.not.changed}" />
      <property name="checkIP.done" value="true" />
    </target>
</project>

ANT BUILD FILE OUTPUT:
Buildfile: mailIP.xml

init:
     [echo] init.done = ${init.done}
     [echo] init.done = true

all:

init:

create:
     [echo] create.done = ${create.done}

     [exec] C:\bin>ipconfig /all  1>IP-new.txt 
     [echo] create.done = true

checkIP:
     [echo] ip.not.changed = true

init:

create:
     [echo] create.done = ${create.done}

     [exec] C:\bin>ipconfig /all  1>IP-new.txt 
     [echo] create.done = true

checkIP:
     [echo] ip.not.changed = true

email:

init:

create:
     [echo] create.done = ${create.done}

     [exec] C:\bin>ipconfig /all  1>IP-new.txt 
     [echo] create.done = true

checkIP:
     [echo] ip.not.changed = true

email:

cleanup:
     [move] Moving 1 files to C:\bin

BUILD SUCCESSFUL
Total time: 2 seconds

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

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