You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Shankar S <sh...@gmail.com> on 2007/12/02 22:57:35 UTC

Passing properties as parameters to different targets in a build file

Hi all,

I have a project.properties file that define a set of properties for my
build system.
log.dir and build.dir are defined in project.properties. Based upon user's
confirguration these values are changed at build time.

My build.xml looks something like this:

<project name="TEST" default="Build_SS" basedir=".">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
  <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask"/>
  <!-- Set the environment to access the environment variables -->
  <property environment="env" />

  <!-- Set the project property file -->
  <property file="project.properties" />

  <!-- Update the timestamp -->
  <tstamp/>

  <!-- Set up the build and log directories -->
  <if>
  <and>
   <equals arg1="${cvs.checkout}" arg2="true" />
   <equals arg1="${build.dir}" arg2="CVS_DIR" />
  </and>
 <then>
  <var name="build.dir" value="${root.dir}/${DSTAMP}_${TSTAMP}" />
  <var name="log.dir" value="../logs/${root_dir.name}/${DSTAMP}_${TSTAMP}"
/>
  <mkdir dir="${log.dir}" />
  <mkdir dir="${build.dir}" />
 </then>
 <else>
  <var name="build.dir" value="${local_root.dir}" />
  <var name="log.dir" value="${local_log.dir}" />
 </else>
  </if>
   <target name="Build_SS" >
 <if>
   <equals arg1="${cvs.tag}" arg2="true" />
   <then>
   *<antcall target="Tag_All_CVS_Modules">
*    <param name="log.dir" value="${log.dir}"/>
   </antcall>



<target name="Tag_All_CVS_Modules" >
 <echo message="Log directory --> ${log.dir}" />
</target>


-----------------------------------------------------------------------------------------------------------------------------------
Firstly log.dir value is not being passed to target *"Tag_All_CVS_Modules".*
Secondly I tried passing the value using <param/> but no luck with that
either.

Is there a way to pass log.dir (and other properties) to different targets
in the same build file.

Thanks in advance;
-Shankar

RE: Passing properties as parameters to different targets in a build file

Posted by "Agarkar, M (Milind)" <Mi...@rabobank.com>.
if you have log.dir read from the properties file, it is already set, so
you may not be able to set it again

We use something like this

<property file=../../build-info.properties/>

<target name="start-all" description="...">
	<foreach list="${env.start}" param="${env.host}"/>
</target>

You can either change name of the default property OR local property

-----Original Message-----
From: Shankar S [mailto:shanki@gmail.com] 
Sent: 02 December 2007 21:58
To: Ant Users List
Subject: Passing properties as parameters to different targets in a
build file

Hi all,

I have a project.properties file that define a set of properties for my
build system.
log.dir and build.dir are defined in project.properties. Based upon
user's confirguration these values are changed at build time.

My build.xml looks something like this:

<project name="TEST" default="Build_SS" basedir=".">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
  <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask"/>
  <!-- Set the environment to access the environment variables -->
  <property environment="env" />

  <!-- Set the project property file -->
  <property file="project.properties" />

  <!-- Update the timestamp -->
  <tstamp/>

  <!-- Set up the build and log directories -->
  <if>
  <and>
   <equals arg1="${cvs.checkout}" arg2="true" />
   <equals arg1="${build.dir}" arg2="CVS_DIR" />
  </and>
 <then>
  <var name="build.dir" value="${root.dir}/${DSTAMP}_${TSTAMP}" />
  <var name="log.dir"
value="../logs/${root_dir.name}/${DSTAMP}_${TSTAMP}"
/>
  <mkdir dir="${log.dir}" />
  <mkdir dir="${build.dir}" />
 </then>
 <else>
  <var name="build.dir" value="${local_root.dir}" />
  <var name="log.dir" value="${local_log.dir}" />  </else>
  </if>
   <target name="Build_SS" >
 <if>
   <equals arg1="${cvs.tag}" arg2="true" />
   <then>
   *<antcall target="Tag_All_CVS_Modules">
*    <param name="log.dir" value="${log.dir}"/>
   </antcall>



<target name="Tag_All_CVS_Modules" >
 <echo message="Log directory --> ${log.dir}" /> </target>


------------------------------------------------------------------------
-----------------------------------------------------------
Firstly log.dir value is not being passed to target
*"Tag_All_CVS_Modules".* Secondly I tried passing the value using
<param/> but no luck with that either.

Is there a way to pass log.dir (and other properties) to different
targets in the same build file.

Thanks in advance;
-Shankar
_____________________________________________________________

This email (including any attachments to it) is confidential, legally privileged, subject to copyright and is sent for the personal attention of the intended recipient only. If you have received this email in error, please advise us immediately and delete it. You are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. Although we have taken reasonable precautions to ensure no viruses are present in this email, we cannot accept responsibility for any loss or damage arising from the viruses in this email or attachments. We exclude any liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided in this email or its attachments, unless that information is subsequently confirmed in writing. If this email contains an offer, that should be considered as an invitation to treat.
_____________________________________________________________

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