ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Brown" <dbr...@shadysoft.net>
Subject RE: Passing command line parameter to ant and reading them from within JUnit
Date Wed, 12 Feb 2003 23:32:12 GMT
If you invoke ant like this:

    ant -Dfoo=123

in your build.xml file you just dereference it as if it was already defined.

    <property name="bar" value="${foo}"/>

Here's a more complicated example that specifically tests to see whether
something was defined before continuing:

  <target name="check.foo">
    <condition property="foo.ok">
      <isset property="foo"/>
    </condition>
    <fail message="The 'foo' property is not set" unless="foo.ok"/>
  </target>

Then you just make your other targets depend on this first. If "foo" isn't
defined, everything stops and the user gets a message. Of course, you can
also do something like this:

  <target name="check.isset" if="foo">
    <echo message="foo is set"/>
  </target>
  <target name="check.isnotset" unless="foo">
    <echo message="foo is not set"/>
  </target>
  <target name="check" depends="check.isset,check.isnotset"/>

There's another thing with properties; once they are defined, they cannot be
re-defined. Therefore, you cannot check to see if a property is defined and
if not, define it. But you can get around this in two ways:

1) Just go ahead and set a property within the build.xml file without
checking whether it was already defined. If the property was defined on the
ccommandline, the commandline value is the one that will be used. If it's
not defined on the commandline, the build.xml property definition will win.

2) Check to see whether the property was defined and use that property to
set a different property altogether.

Doug

-----Original Message-----
From: Steve [mailto:steven.hawkes@ascom.ch] 
Sent: Wednesday, February 12, 2003 3:04 PM
To: ant-user@jakarta.apache.org
Subject: Passing command line parameter to ant and reading them from within
JUnit

Hi,

I know how to pass command line parameters into ANT using the -D option.
But how can I pick up these parameters from within a JUnit test script
Started from within ANT.

Regards

Steve


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


Mime
View raw message