ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <>
Subject Re: Properties set within conditions
Date Tue, 12 Oct 2004 15:20:02 GMT
Is 'antcall' (and 'antcallback') the only way to create my properties
conditionally? I used 'antcall' and 'condition' to set my properties because
they are the only ways I know to set a property conditionally within the Ant
core tasks; if there is a better way, I'd love to hear about it.


----- Original Message ----- 
From: "Vadim Kazakov" <>
To: "Ant Users List" <>
Sent: Tuesday, October 12, 2004 10:37 AM
Subject: RE: Properties set within conditions

This is because you're are setting these variables in an antcall. Which
does not actually propogate up those properties. You could check out the
antcallback task in ant-contrib. That will do what you want also see the
recent thread about returning values from antcallback.


From: Rhino []
Sent: October 12, 2004 7:10 AM
To: ant-user
Subject: Properties set within conditions


I'm having a problem with seeing a property that I set within some
conditional logic. Some new properties are only visible within the
target where I add them but I need them to be visible in later targets
as well.

I've spent several hours looking at the archives for this mailing list
and trying everything I could think of but I can't seem to make my
script work the way I want, even though it seems like something that
should be pretty easy.

First, let me explain in words what I want to do, then I'll show you the
current version of the script, which doesn't quite work. Maybe you can
suggest what I need to change to make this work.

My script is going to upload some files to one of two servers, then run
some commands on that server that involve the files I uploaded. The user
is allowed to choose which of the two servers the user wants during the
execution of the Ant script. Then, depending on which one the user
chooses, certain properties like the hostname and a target directory for
the uploads (for starters) are going to be set. Then, regardless of
which server was selected, the userid and password for the server will
be selected. Then, the upload will take place, followed by the commands
that are running on the target server.

The individual targets all seem to work okay when I run them alone,
provided that they get the properties they need have been set at a
script-wide level beforehand. I only get into trouble when I try to set
properties in one target and then use them in a later target.

Although I am using scp and sshexec in my Ant script for the upload and
for running the commands that execute on the server, I would prefer to
use only standard Ant tasks wherever possible in the rest of my script.

Here is my script:


<?xml version="1.0"?>

<project name="Resume" default="sshexec" basedir=".">

<property name="hostname.sympatico" value=""/>

<property name="sympatico.resume.dir" value="/home/rhino"/>

<property name="hostname.tonge" value=""/>

<property name="tonge.resume.dir" value="/home/rhino/public_html"/>

<property name="" value="true"/>


Determine which server is the target.


<target name="getserver" description="Determine which server is the

<input message="Which server should receive the files? 1. Sympatico 2.




<echo message="Server choice is ${server.choice}"/>


<target name="setparms" description="Set the server-dependent

<condition property="Sympatico">

<equals arg1="${server.choice}" arg2="1"/>


<antcall target="sympatico"/>

<antcall target="tonge"/>


<target name="sympatico" if="Sympatico" description="Set the
server-dependent properties for Sympatico.">

<echo>server = Sympatico</echo>

<property name="server" value="${hostname.sympatico}"/>

<property name="server.resume.dir" value="${sympatico.resume.dir}"/>

<echo message="The Server hostname is ${server}. The resume directory is


<target name="tonge" unless="Sympatico" description="Set the
server-dependent properties for Tonge.">

<echo>server = Tonge</echo>

<property name="server" value="${hostname.tonge}"/>

<property name="server.resume.dir" value="${tonge.resume.dir}"/>

<echo message="The Server hostname is ${server}. The resume directory is


<target name="getlogin" description="Get userid and password for

<input message="Please supply the userid for the server:"
addproperty="userid" defaultvalue="dougb"/>

<input message="Please supply the password for the server:"
addproperty="password" defaultvalue="dougbpw"/>


<target name="display" description="Display server-dependent

<echo message="The userid is ${userid} and the password is

<echo message="The Server hostname is ${server}. The resume directory is





1. target directory MUST exist.

2. source directories that are empty never get created on the target


<target name="scp"
description="scp copies local files to remote machines via SSH">

<scp file="C:/Answer.txt"
todir="${userid}:${password}@${server}:/home/rhino" trust="true"/>

<!--scp file="C:/dbasic.log"
todir="${userid}:${password}@${server}:/home/rhino" trust="false"

<scp file="${userid}:${password}@${server}:/etc/ssh/"
todir="d:/eclipse/workspace/resume/xml" trust="true"/>

<scp todir="${userid}:${password}@${server}:/home/rhino/tmp"

<fileset dir="d:/myTempDir">

<include name="**/*"/>







<target name="sshexec" depends="scp" description="sshexec is an SSH
command line">

<echo message="The Server hostname is ${server}. The resume directory is

<echo message="The userid is ${userid}. The password is ${password}."/>

<sshexec host="${server}" username="${userid}" password="${password}"
command="touch myfile" trust="true"/>

<sshexec host="${server}" username="${userid}" password="${password}"
command="rm myfile" trust="true"/>

<sshexec host="${server}" username="${userid}" password="${password}"
command="sh hello.bash" trust="true"/>




The basic problem is that my scp step doesn't seem to see the values of
${server} and ${server.resume.dir} anywhere but in the steps that set
them, 'tonge' or 'sympatico', depending on which one was invoked. If
these two properties were global to the whole script rather than local
to the 'tonge' or 'sympatico' tasks, my script should work.
Unfortunately, I haven't been able to find any way to make the property
global to the whole script.

I also seem to have some problems with the dependencies between the
tasks. To my way of thinking:

- 'setparms' should depend on 'getserver';

- 'sympatico' and 'tonge' should both depend on 'setparms' (although
this may be redundant due to the antcalls in 'setparms')

- 'getlogin' should be dependent on either 'sympatico' or 'tonge',
whichever was executed, or possibly both

- 'display' should be dependent on 'getlogin'

- 'scp' should be dependent on 'display'

- 'sshexec' should be dependent on 'scp'

However, if I try to implement those dependencies, the script tends to
have a lot more problems. Perhaps someone could tell me how the
dependencies should be set for what I am trying to do.

I'm using Ant 1.6.1 on Windows XP but would be willing to upgrade to a
newer version of Ant if that would help.

rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the
other way is to make it so complicated that there are no obvious
deficiencies." - C.A.R. Hoare

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message