ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john guthrie <jguth...@psynapsetech.com>
Subject record and replace questions
Date Tue, 22 Jun 2004 17:34:21 GMT
i am seeing some oddities with ant using record and replace. i
got this clever idea of using record to set some environment
variables based on ant build properties - i'd just "record" them
to a file then have my script dot(.) that file (obviously i am
in unixland here). ant version, by the way:
   local ant> ant -version
   Apache Ant version 1.6.0 compiled on December 18 2003

so here is my first build.xml:
   <?xml version="1.0" encoding="UTF-8"?>
   <project basedir="." default="all" name="tess">
     <property name="version" value="0.1"/>
     <target name="tess" description="testing something or other">
       <record name="tess.sh" action="start"
               emacsmode="true" append="true"/>
       <echo message="TARFILE=tess-${version}.tar.gz"/>
       <record name="tess.sh" action="stop"/>
     </target>
   </project>

when i run this i see:
   local ant> ant tess
   Buildfile: build.xml

   tess:
        [echo] TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   Total time: 0 seconds
   local ant> cat tess.sh
   TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   local ant>

so the "BUILD SUCCESSFUL" message has also been recorded, dunno why.

my next clever idea is to use replace to comment out that "BUILD
SUCCESSFUL" message. i modify my build.xml to:
   <?xml version="1.0" encoding="UTF-8"?>
   <project basedir="." default="all" name="tess">
     <property name="version" value="0.1"/>
     <target name="tess" description="testing something or other">
       <record name="tess.sh" action="start"
               emacsmode="true" append="true"/>
       <echo message="TARFILE=tess-${version}.tar.gz"/>
       <record name="tess.sh" action="stop"/>
       <replace file="tess.sh" token="BUILD SUCCESSFUL"
              value="#BUILD SUCCESSFUL"/>
     </target>
   </project>

remove the old tess.sh, and run this. i see the same output. but,
to my surprise, if i run it again, when i'd expect to have two
"BUILD SUCCESSFUL" messages, i only see the first, commented out.
here it is:
   local ant> ant tess
   Buildfile: build.xml

   tess:
        [echo] TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   Total time: 0 seconds
   local ant> cat tess.sh
   TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   local ant> ant tess
   Buildfile: build.xml

   tess:
        [echo] TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   Total time: 0 seconds
   local ant> cat tess.sh
   TARFILE=tess-0.1.tar.gz

   #BUILD SUCCESSFUL
   TARFILE=tess-0.1.tar.gz
   local ant>

this file will serve my needs, but it looks like the worst sort of
hack pile-up (e.g. having to call the target twice). so i play around
with it, and come up with the following version, with which i am pretty
happy:
   <?xml version="1.0" encoding="UTF-8"?>
   <project basedir="." default="all" name="tess">
     <property name="version" value="0.1"/>
     <target name="tess" description="testing something or other">
       <antcall target="tessecho" inheritRefs="true"/>
     </target>
     <target name="tessecho">
       <record name="tess.sh" action="start"
               emacsmode="true" append="true"/>
       <echo message="TARFILE=tess-${version}.tar.gz"/>
       <record name="tess.sh" action="stop"/>
     </target>
   </project>

running this looks like:
   local ant> ant tess
   Buildfile: build.xml

   tess:

   tessecho:
        [echo] TARFILE=tess-0.1.tar.gz

   BUILD SUCCESSFUL
   Total time: 0 seconds
   local ant> cat tess.sh
   TARFILE=tess-0.1.tar.gz
   local ant>


putting record in a subtarget gets rid of the recording of "BUILD
SUCCESSFUL", but i don't understand why. to me, too, the oddest
behavior above is in the second case, where i run the target twice
and have different outputs from each individual run.

john

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


Mime
View raw message