ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Reeves, Paul C" <pcre...@sandia.gov>
Subject RE: Rant on immutable properties
Date Mon, 02 Aug 2004 13:39:31 GMT
You can get around the immutable aspects of properties via the Ant-Contrib
tasks.

Specifically, you may use <propertycopy> with the parameter override="true"
to re-assign a property.

This runs counter to the philosophy of ant, but I find it essential in my
work.  I tend to use it while iterating over a set of sub-tasks using
Ant-Contrib's <for> task.  I need to set arguments to pass to sub-tasks and
want to recycle the arguements as "variables" so that I only have to
maintain a single set of code that works for a whole set of projects.


Paul

P.S.  See
http://ant-contrib.sourceforge.net/


Here is an example of what I need to do.  I have a large set of projects
that need to be built via their own ant build files.  Each resides in a
unique directory and has a unique target that should be called.  These
settings are held in a property file.  The iteration looks like this:

    <!--Iterate over the custom ant build commands -->                      
    <for list       = "${proj.build_commands}" 
         delimiter  = ","
         param      = "string">

      <sequential>
      
        <math result    = "build_cnt" 
              operand1  = "${build_cnt}" 
              operation = "+" 
              operand2  = "${incr}" 
              datatype  = "int"/>
              
        <propertycopy name     = "proj.ant_build.antfile"  
                      from     =
"${ant.project.name}.build_command.${build_cnt}.antfile"
                      override = "true"
                      silent   = "true"/>
        <propertycopy name     = "proj.ant_build.dir"  
                      from     =
"${ant.project.name}.build_command.${build_cnt}.dir"
                      override = "true"
                      silent   = "true"/>
        <propertycopy name     = "proj.ant_build.target"  
                      from     =
"${ant.project.name}.build_command.${build_cnt}.target"
                      override = "true"
                      silent   = "true"/>
                      
        <echo message="&#10;"/>
        <echo message="&#10;"/>
        <echo message="${ant.project.name} >>>Running:  ant -buildfile
'${proj.ant_build.antfile}' ${proj.ant_build.target}&#10;"/>
        
        <trycatch property="proj.build_command.error">
          <try>
            <!-- Call the custom ant build command -->
            <ant  antfile     = "${proj.ant_build.antfile}"
                  dir         = "${proj.ant_build.dir}"
                  target      = "${proj.ant_build.target}"
                  inheritAll  = "false"
                  inheritRefs = "false"/>
          </try>
          <catch>
            <ant antfile="build_log.xml" inheritAll="false"
target="update_log">
              <property name="proj.build_success" value="false"/>
              <property name="proj.build_dir"
value="${proj.build_dir}"/>
            </ant>
            <echo message="${ant.project.name} >>>ERROR:  Exception Thrown
in Ant Build (${ant.project.name})"/>
            <echo message="${ant.project.name} >>>        Exception:
${proj.build_command.error}"/>
            <throw message="${proj.build_command.error}&#10;&#10;&#10;***
ABORTING BUILD ***&#10;&#10;&#10;"/>
          </catch>
        </trycatch>
        
      </sequential>
      
    </for>









-----Original Message-----
From: Rhino [mailto:rhino1@sympatico.ca]
Sent: Monday, August 02, 2004 6:53 AM
To: Ant Users List
Subject: Re: Rant on immutable properties



----- Original Message ----- 
From: "Martin Gainty" <mgainty@hotmail.com>
To: <user@ant.apache.org>
Sent: Friday, July 30, 2004 1:23 PM
Subject: Rant on immutable properties


> Hello All
>
> I have need to set the value of a property based on user input
> but cannot do so because properties are immutable?
>
> Is there a workaround?
>
Have you considered the 'input' core task? You could ask the user to supply
a value while the script executes and use the returned value in your script.

Rhino


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



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


Mime
View raw message