From: rtconner on
I do not know if this is possible, but I thought I'd ask anyways...

I want to conditionally pass arguement to a call. I'll just give you my
real life example since it explains it best.

ant -Dinstance.dir="$INSTANCE_DIR" \
-Dversion="$VERSION" \
-Dnotify.email="$NOTIFY_EMAIL" \
-Dadmin.user="$ADMIN_USER" \
-Dadmin.pass="$ADMIN_PASS" \
-Dbackup.dir="$BACKUP_DIR" \
-Dserver="$SERVER" \
-f $BUILD_FILE deploy> $LOG_FILE 2>&1 &

....but I only want to pass arguments in if the variable exists. in an
ideal world (i know this doesn't work)

ant -Dinstance.dir="$INSTANCE_DIR" \
if [ -n "$VERSION" ]; then
-Dversion="$VERSION" \
fi
if [ -n "$NOTIFY_EMAIL" ]; then
-Dnotify.email="$NOTIFY_EMAIL" \
fi
-Dadmin.user="$ADMIN_USER" \
-Dadmin.pass="$ADMIN_PASS" \
if [ -n "$BACKUP_DIR" ]; then
-Dbackup.dir="$BACKUP_DIR" \
fi
if [ -n "$SERVER" ]; then
-Dserver="$SERVER" \
fi
-f $BUILD_FILE deploy\
if [ -n "$LOG_FILE" ]
> $LOG_FILE 2>&1 &
fi

Or some other way of constructing the ant call based on conditions. Is
this possible? How would I go about doing something like this?

Thank you,
Rob

From: Stephane Chazelas on
On 13 Jan 2006 09:00:37 -0800, rtconner(a)gmail.com wrote:
> I do not know if this is possible, but I thought I'd ask anyways...
>
> I want to conditionally pass arguement to a call. I'll just give you my
> real life example since it explains it best.
>
> ant -Dinstance.dir="$INSTANCE_DIR" \
> -Dversion="$VERSION" \
> -Dnotify.email="$NOTIFY_EMAIL" \
> -Dadmin.user="$ADMIN_USER" \
> -Dadmin.pass="$ADMIN_PASS" \
> -Dbackup.dir="$BACKUP_DIR" \
> -Dserver="$SERVER" \
> -f $BUILD_FILE deploy> $LOG_FILE 2>&1 &
>
> ...but I only want to pass arguments in if the variable exists. in an
> ideal world (i know this doesn't work)
[...]

ant ... ${VERSION+"-Dversion=$VERSION"} ...

--
Stephane
From: Ed Morton on


rtconner(a)gmail.com wrote:
> I do not know if this is possible, but I thought I'd ask anyways...
>
> I want to conditionally pass arguement to a call. I'll just give you my
> real life example since it explains it best.
>
> ant -Dinstance.dir="$INSTANCE_DIR" \
> -Dversion="$VERSION" \
> -Dnotify.email="$NOTIFY_EMAIL" \
> -Dadmin.user="$ADMIN_USER" \
> -Dadmin.pass="$ADMIN_PASS" \
> -Dbackup.dir="$BACKUP_DIR" \
> -Dserver="$SERVER" \
> -f $BUILD_FILE deploy> $LOG_FILE 2>&1 &
>
> ...but I only want to pass arguments in if the variable exists. in an
> ideal world (i know this doesn't work)
>
> ant -Dinstance.dir="$INSTANCE_DIR" \
> if [ -n "$VERSION" ]; then
> -Dversion="$VERSION" \
> fi
> if [ -n "$NOTIFY_EMAIL" ]; then
> -Dnotify.email="$NOTIFY_EMAIL" \
> fi
> -Dadmin.user="$ADMIN_USER" \
> -Dadmin.pass="$ADMIN_PASS" \
> if [ -n "$BACKUP_DIR" ]; then
> -Dbackup.dir="$BACKUP_DIR" \
> fi
> if [ -n "$SERVER" ]; then
> -Dserver="$SERVER" \
> fi
> -f $BUILD_FILE deploy\
> if [ -n "$LOG_FILE" ]
> > $LOG_FILE 2>&1 &
> fi
>
> Or some other way of constructing the ant call based on conditions. Is
> this possible? How would I go about doing something like this?
>
> Thank you,
> Rob
>

Do somthing like this:

version=""
notify=""
backup=""
server=""
if [ -n "$VERSION" ]; then
version="-Dversion=$VERSION"
fi
if [ -n "$NOTIFY_EMAIL" ]; then
notify="-Dnotify.email=$NOTIFY_EMAIL"
fi
if [ -n "$BACKUP_DIR" ]; then
backup="-Dbackup.dir=$BACKUP_DIR"
fi
if [ -n "$SERVER" ]; then
server="-Dserver=$SERVER"
fi

ant -Dinstance.dir="$INSTANCE_DIR" \
$version \
$notify \
$backup \
-Dadmin.pass="$ADMIN_PASS" \
-Dbackup.dir="$BACKUP_DIR" \
$server \
-f $BUILD_FILE deploy> $LOG_FILE 2>&1 &

You might have to play with the quoting...

Ed.
From: Stephane Chazelas on
On Fri, 13 Jan 2006 11:11:41 -0600, Ed Morton wrote:
[...]
> Do somthing like this:
>
> version=""
> notify=""
> backup=""
> server=""
> if [ -n "$VERSION" ]; then
> version="-Dversion=$VERSION"
> fi
> if [ -n "$NOTIFY_EMAIL" ]; then
> notify="-Dnotify.email=$NOTIFY_EMAIL"
> fi
> if [ -n "$BACKUP_DIR" ]; then
> backup="-Dbackup.dir=$BACKUP_DIR"
> fi
> if [ -n "$SERVER" ]; then
> server="-Dserver=$SERVER"
> fi
>
> ant -Dinstance.dir="$INSTANCE_DIR" \
> $version \
> $notify \
> $backup \
> -Dadmin.pass="$ADMIN_PASS" \
> -Dbackup.dir="$BACKUP_DIR" \
> $server \
> -f $BUILD_FILE deploy> $LOG_FILE 2>&1 &
[...]

Then, you need first to disable filename generation (set -f) and
word splitting (IFS=""), so that from the 3 actions taken by the
shell upon expanding an unquoted variable, only the third one
(removing empty expansions) remains.

Note that if -f requires an argument, then $BUILD_FILE should be
quoted.

--
Stephane
From: rtconner on
Stephane Chazelas wrote:
>
> ant ... ${VERSION+"-Dversion=$VERSION"} ...
>

This is great, but how would I set VERSION to null i order for this to
evaluate to false.
I had thought
VERSION="" would work but it doesn't seem to be working as I thought, I
just have an if statement above and I'd like the varable to exist, but
setting it to null is fine.

otherwise I might go with Ed's way of doing this.