You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Trent Ohannessian <to...@gmail.com> on 2006/05/02 22:02:00 UTC

Qustion about property prefix...

Hello.  I'm trying to use the <property> task with a prefix.  Here is the
code I'm using:

------------------------------------------
    <property file="./webtest.properties" prefix="${env}" />
    <echo message="host: ${host}" />
------------------------------------------

And here is the properties file I'm trying to load:

------------------------------------------
localhost.host=localhost
qa.host=qatest.domain.com

localhost.port=8080
qa.port=80
------------------------------------------

When I use the prefix property option, none of the properties are read and
they are not usable in the Ant script.  What I'm trying to do is pass in a
property on the command line and then use the correct set of properties
based on server.  I can see the localhost getting passed into the Ant script
correctly, but it doesn't work even if I hardcode localhost into prefix="".
  Is this the right way to go about doing this?

Thanks!
Trent

--
Learn from the mistakes of others. You can't live long enough to make them
all yourself.

Re: Qustion about property prefix...

Posted by Dominique Devienne <dd...@gmail.com>.
On 5/3/06, Trent Ohannessian <to...@gmail.com> wrote:
> Thank you all for your replies.  This Ant script is actually running Canoo
> WebTest.  It's testing the small GUI portion of our application. The entire
> application uses several properties files, but there is just one file per
> subsystem and the server designations are made by adding a
> localhost.whatever or qa.whatever, etc.  I was hoping to stay away from
> multiple properties files to keep the standard set by the entire app, but I
> see there is no way around that.  I'll just live with it and continue on. :)

By using filter readers in <loadproperties>, you might be able to
filter-out properties that don't start with a given prefix (thus
hiding them, as if not in the file). What I'm not sure of if whether
you can also strip the prefix using filter readers, kinda like what's
possible with <propertyset> and <mapper>. Using the latter 2 in
<java>, I used to select one set of properties or another based on a
prefix, which sounds like what you're trying to do. But properties
whose names have been stripped of the prefix were passed to the forked
sub-process, while you want the properties to become part of the
current's build (Project in fact). --DD

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


Re: Qustion about property prefix...

Posted by Trent Ohannessian <to...@gmail.com>.
Thank you all for your replies.  This Ant script is actually running Canoo
WebTest.  It's testing the small GUI portion of our application. The entire
application uses several properties files, but there is just one file per
subsystem and the server designations are made by adding a
localhost.whatever or qa.whatever, etc.  I was hoping to stay away from
multiple properties files to keep the standard set by the entire app, but I
see there is no way around that.  I'll just live with it and continue on. :)

Thanks for your help!

On 5/2/06, Steve Loughran <st...@apache.org> wrote:
>
> Trent Ohannessian wrote:
> > Hello.  I'm trying to use the <property> task with a prefix.  Here is
> the
> > code I'm using:
> >
> > ------------------------------------------
> >    <property file="./webtest.properties" prefix="${env}" />
> >    <echo message="host: ${host}" />
> > ------------------------------------------
> >
> > And here is the properties file I'm trying to load:
> >
> > ------------------------------------------
> > localhost.host=localhost
> > qa.host=qatest.domain.com
> >
> > localhost.port=8080
> > qa.port=80
> > ------------------------------------------
> >
> > When I use the prefix property option, none of the properties are read
> and
> > they are not usable in the Ant script.  What I'm trying to do is pass in
> a
> > property on the command line and then use the correct set of properties
> > based on server.  I can see the localhost getting passed into the Ant
> > script
> > correctly, but it doesn't work even if I hardcode localhost into
> prefix="".
> >  Is this the right way to go about doing this?
>
> I recommend having a different property file per server
>
> <property file="secure/${server}.properties" />
>
> Keep the server settings somewhere locked down, esp. once you add
> passwords
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


--
Learn from the mistakes of others. You can't live long enough to make them
all yourself.

Re: Qustion about property prefix...

Posted by Steve Loughran <st...@apache.org>.
Trent Ohannessian wrote:
> Hello.  I'm trying to use the <property> task with a prefix.  Here is the
> code I'm using:
> 
> ------------------------------------------
>    <property file="./webtest.properties" prefix="${env}" />
>    <echo message="host: ${host}" />
> ------------------------------------------
> 
> And here is the properties file I'm trying to load:
> 
> ------------------------------------------
> localhost.host=localhost
> qa.host=qatest.domain.com
> 
> localhost.port=8080
> qa.port=80
> ------------------------------------------
> 
> When I use the prefix property option, none of the properties are read and
> they are not usable in the Ant script.  What I'm trying to do is pass in a
> property on the command line and then use the correct set of properties
> based on server.  I can see the localhost getting passed into the Ant 
> script
> correctly, but it doesn't work even if I hardcode localhost into prefix="".
>  Is this the right way to go about doing this?

I recommend having a different property file per server

<property file="secure/${server}.properties" />

Keep the server settings somewhere locked down, esp. once you add passwords


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


Re: Qustion about property prefix...

Posted by Rhino <rh...@sympatico.ca>.
I'm not sure about the answer to your original question but I might be able 
to suggest a different way to accomplish what you are trying to do. Someone 
on this mailing list, probably Jan Materne, gave me the basic idea and it 
worked very well in my build script.

The purpose of my script is to upload a bunch of files to one of two 
different servers. First, I do all of the compiling, jarring, etc. that is 
necessary to create the files which need to be uploaded. Then, I have 
targets that: determine which server is to be destination of the upload; 
grab the appropriate properties file (there is a different properties file 
for each server); execute the appropriate upload target; and do the actual 
upload.

Here is a quick explanation of each of these targets, followed by the 
relevant part of the script:
1. 'getserver' - prompts the user for which server is to be the destination 
of the files. Whichever value is chosen, a property called 'servername' is 
set to the name of the server.  In my case, I wanted to allow the decision 
to be made at run-time but you could simply force the user to supply a 
servername parameter to the build script as a command-line argument.
2. 'getprops' - obtains the properties file for the server that was chosen 
in the 'getserver' target. There is one property file for each server which 
can be the desination of the uploads; in this case, the properties files are 
server.Sago.properties and server.Tone.properties. In your case, you 
probably wouldn't have the 'getserver' target at all but would simply 
execute 'getprops' and it would grab the appropriate properties file based 
on the value of the servername property that was set on the command line.
3. 'upload' - executes the appropriate upload target via an 'antcall'. The 
target name includes the server name so the antcall can execute either 
'upload-Sago' or 'upload-Tone' in this case.
4. 'upload-Sago' - does the uploads for the Sago server. Uses the properties 
obtained from the server.Sago.properties file.
5. 'upload-Tone' - does the uploads for the Tone server. Uses the properties 
obtained from the server.Tone.properties file.

Important note: Although this particular example only chooses between two 
servers, this solution can easily scale to any number of servers by 
modifying the script as follows:
a. put more server options in the 'getserver' target.
b. write a properties file for each server.
c. write a specific 'upload-xxx' target for each server.
Therefore, if you wanted to add a third server, Alpha, to the build script:
- add a third option to 'getservers' that sets 'servername' to "Alpha"
- write a properties file for Alpha called 'server.Alpha.properties'
- add a target called 'upload-Alpha' which does the necessary uploading 
tasks.

Here is the code, with most of the real work stripped from upload-Sage and 
upload-Tone to keep it (relatively) concise:

<!--==================================================================

Determine which server is the target.

==================================================================-->

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

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

validargs="1,2"

addproperty="server.choice"

defaultvalue="2"/>

<condition property="servername" value="Sago">

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

</condition>

<condition property="servername" value="Tone">

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

</condition>

</target>

<!--==================================================================

Load the properties file for the appropriate server.

==================================================================-->

<target name="getprops" depends="getserver" description="Get the appropriate 
properties file depending on the server which was chosen">

<property 
file="${workspace311}\${resume.proj}\xml\server.${servername}.properties"/>

</target>

<!--==================================================================

Execute the appropriate upload target, depending on which server

was chosen.

==================================================================-->

<target name="upload" depends="getprops" description="Upload to the selected 
server.">

<antcall target="upload-${servername}"/>

</target>

<!--==================================================================

Upload to the Sago server.

==================================================================-->

<target name="upload-Sago" description="Upload to the Sago server.">


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

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


<echo message="Uploading to Sago...."/>


<echoproperties prefix="server"/>

<echo message="Deleting all files (but not subdirectories) *beneath* the 
resume directory."/>

<ftp action="del" server="${server.hostname}" userid="${userid}" 
password="${password}"

remotedir="${server.resume.dir}"

description="Delete all files under resume directory at any level.">

<fileset>

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

</fileset>

</ftp>

<!--ETC. ETC.-->


</target>

<!--==================================================================

Upload to the Tone server. The Tone server uses SSH so the 'scp'

task is used for each upload of a file or directory. The 'sshexec'

task is used to create directories.

==================================================================-->

<target name="upload-Tone" description="Upload to the Tone server.">

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

<input message="Please supply the SSH passphrase for the Tone server:" 
addproperty="passphrase" defaultvalue="francbpw"/>

<echo message="Uploading to Tone...."/>

<echoproperties prefix="server"/>

<echo message="Deleting resume directory and all files and directories below 
it."/>

<sshexec host="${server.hostname}" username="${userid}" trust="true"

keyfile="${server.keyfile}" passphrase="${passphrase}"

command="rm -rf ${server.resume.dir}"/>

<!--ETC. ETC. -->

</target>



I hope this helps!

--
Rhino

----- Original Message ----- 
From: "Trent Ohannessian" <to...@gmail.com>
To: <us...@ant.apache.org>
Sent: Tuesday, May 02, 2006 4:02 PM
Subject: Qustion about property prefix...


Hello.  I'm trying to use the <property> task with a prefix.  Here is the
code I'm using:

------------------------------------------
    <property file="./webtest.properties" prefix="${env}" />
    <echo message="host: ${host}" />
------------------------------------------

And here is the properties file I'm trying to load:

------------------------------------------
localhost.host=localhost
qa.host=qatest.domain.com

localhost.port=8080
qa.port=80
------------------------------------------

When I use the prefix property option, none of the properties are read and
they are not usable in the Ant script.  What I'm trying to do is pass in a
property on the command line and then use the correct set of properties
based on server.  I can see the localhost getting passed into the Ant script
correctly, but it doesn't work even if I hardcode localhost into prefix="".
  Is this the right way to go about doing this?

Thanks!
Trent

--
Learn from the mistakes of others. You can't live long enough to make them
all yourself.



--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.5.1/328 - Release Date: 01/05/2006



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.5.1/328 - Release Date: 01/05/2006


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


Re: Qustion about property prefix...

Posted by Matt Benson <gu...@yahoo.com>.
Looks like you've got prefix backwards.  When you set
env to localhost and load this file, you should end up
with property settings:

localhost.localhost.host=localhost
localhost.qa.host=qatest.domain.com

Ordinarily you would probably set up
localhost.properties and qa.properties files, and use
your env property to trigger which file to load:

localhost.properties:
host=localhost

qa.properties:
host=qatest.domain.com

Alternatively, you could copy the property after
loading them (without prefixes).  See
http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

HTH,
Matt

--- Trent Ohannessian <to...@gmail.com> wrote:

> Hello.  I'm trying to use the <property> task with a
> prefix.  Here is the
> code I'm using:
> 
> ------------------------------------------
>     <property file="./webtest.properties"
> prefix="${env}" />
>     <echo message="host: ${host}" />
> ------------------------------------------
> 
> And here is the properties file I'm trying to load:
> 
> ------------------------------------------
> localhost.host=localhost
> qa.host=qatest.domain.com
> 
> localhost.port=8080
> qa.port=80
> ------------------------------------------
> 
> When I use the prefix property option, none of the
> properties are read and
> they are not usable in the Ant script.  What I'm
> trying to do is pass in a
> property on the command line and then use the
> correct set of properties
> based on server.  I can see the localhost getting
> passed into the Ant script
> correctly, but it doesn't work even if I hardcode
> localhost into prefix="".
>   Is this the right way to go about doing this?
> 
> Thanks!
> Trent
> 
> --
> Learn from the mistakes of others. You can't live
> long enough to make them
> all yourself.
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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