You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dean Schulze <de...@yahoo.com> on 2010/06/22 17:25:01 UTC

Need cross platform way of assigning users name to a property

My build.xml starts with the following lines:
 
<property environment="env"/>
<property name="user.username.dir" value="user/${env.USERNAME}"/>
<import file="${user.username.dir}/build.local.xml" optional="true"/>
 
This imports a build.local.xml file that holds machine-specific properties for each developer.
 
The problem is that this does not work on UNIX because the username is in env.USER in unix.  I need a cross-platform way to assign a user.name property in Ant.  
 
This has to be done at the top of the build.xml so that the <import ... /> is done before any other property assignments (the properties in build.local.xml are used if build.local.xml exists).  This means that the user.name property can't be assigned in a target so the condition statement is useless here.
 
Is there some way that I can read the username from the environment in a cross-platform way given that it has to happen at the top of the script?
 
 


      

AW: Need cross platform way of assigning users name to a property

Posted by Ja...@rzf.fin-nrw.de.
http://ant.apache.org/manual/properties.html#built-in-props

Jan 

>-----Ursprüngliche Nachricht-----
>Von: Dean Schulze [mailto:dean_w_schulze@yahoo.com] 
>Gesendet: Donnerstag, 24. Juni 2010 19:47
>An: Ant Users List
>Betreff: Re: Need cross platform way of assigning users name 
>to a property
>
> 
>Thanks for the responses.
> 
>The ${user.name} was the answer to my problem.  I didn't know 
>that all the Java System.getProperties() were available in Ant.
> 
>
>
>--- On Tue, 6/22/10, Michael Ludwig <mi...@gmx.de> wrote:
>
>
>From: Michael Ludwig <mi...@gmx.de>
>Subject: Re: Need cross platform way of assigning users name 
>to a property
>To: "Ant Users List" <us...@ant.apache.org>
>Date: Tuesday, June 22, 2010, 10:30 AM
>
>
>Matt Benson schrieb am 22.06.2010 um 11:06 (-0500):
>
>> > I'm probably missing something, but what's wrong with the 
>following,
>> > which is provided by Ant out of the box:
>> 
>> Provided by Java out of the box, if I'm not mistaken.  :)
>
>Indeed, it is all of *Java's* System.getProperties() which is 
>in the Ant
>box, and even comes out of it if asked to :-)
>
>-- 
>Michael Ludwig
>
>
>
>      
>

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


Re: Need cross platform way of assigning users name to a property

Posted by Dean Schulze <de...@yahoo.com>.
 
Thanks for the responses.
 
The ${user.name} was the answer to my problem.  I didn't know that all the Java System.getProperties() were available in Ant.
 


--- On Tue, 6/22/10, Michael Ludwig <mi...@gmx.de> wrote:


From: Michael Ludwig <mi...@gmx.de>
Subject: Re: Need cross platform way of assigning users name to a property
To: "Ant Users List" <us...@ant.apache.org>
Date: Tuesday, June 22, 2010, 10:30 AM


Matt Benson schrieb am 22.06.2010 um 11:06 (-0500):

> > I'm probably missing something, but what's wrong with the following,
> > which is provided by Ant out of the box:
> 
> Provided by Java out of the box, if I'm not mistaken.  :)

Indeed, it is all of *Java's* System.getProperties() which is in the Ant
box, and even comes out of it if asked to :-)

-- 
Michael Ludwig



      

Re: Need cross platform way of assigning users name to a property

Posted by Michael Ludwig <mi...@gmx.de>.
Matt Benson schrieb am 22.06.2010 um 11:06 (-0500):

> > I'm probably missing something, but what's wrong with the following,
> > which is provided by Ant out of the box:
> 
> Provided by Java out of the box, if I'm not mistaken.  :)

Indeed, it is all of *Java's* System.getProperties() which is in the Ant
box, and even comes out of it if asked to :-)

-- 
Michael Ludwig

Re: Need cross platform way of assigning users name to a property

Posted by Matt Benson <gu...@gmail.com>.
On Jun 22, 2010, at 11:03 AM, Michael Ludwig wrote:

> Dean Schulze schrieb am 22.06.2010 um 08:25 (-0700):
> 
>> <property environment="env"/>
>> <property name="user.username.dir" value="user/${env.USERNAME}"/>
>> <import file="${user.username.dir}/build.local.xml" optional="true"/>
> 
>> I need a cross-platform way to assign a user.name property in Ant.  
> 
>> Is there some way that I can read the username from the environment in
>> a cross-platform way given that it has to happen at the top of the
>> script?
> 
> I'm probably missing something, but what's wrong with the following,
> which is provided by Ant out of the box:
> 

Provided by Java out of the box, if I'm not mistaken.  :)

-Matt

> <project>
>  <echo level="info" message="${user.name}"/>
> </project>
> 
> -- 
> Michael Ludwig
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 


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


Re: Need cross platform way of assigning users name to a property

Posted by Michael Ludwig <mi...@gmx.de>.
Dean Schulze schrieb am 22.06.2010 um 08:25 (-0700):

> <property environment="env"/>
> <property name="user.username.dir" value="user/${env.USERNAME}"/>
> <import file="${user.username.dir}/build.local.xml" optional="true"/>

> I need a cross-platform way to assign a user.name property in Ant.  

> Is there some way that I can read the username from the environment in
> a cross-platform way given that it has to happen at the top of the
> script?

I'm probably missing something, but what's wrong with the following,
which is provided by Ant out of the box:

<project>
  <echo level="info" message="${user.name}"/>
</project>

-- 
Michael Ludwig

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


Re: Need cross platform way of assigning users name to a property

Posted by Vinayak <vn...@gmail.com>.
To put all together;

<property environment="env"/>
<condition property="user.username.dir" value="user/${env.USERNAME}" else="
user/${env.USER}">
  <os family="windows"  />
</condition>

<echo message="user.username.dir=${user.username.dir}" />
<import file="${user.username.dir}/build.local.xml" optional="true"/>

I think env.USER will return username on mac systems as well.

RE: Need cross platform way of assigning users name to a property

Posted by "John W. Lewis" <Jo...@sas.com>.
I had a similar problem:

			<condition property="appdata.dir" value="${env.USERPROFILE}\Application Data\MyProject">
				<os family="windows"  />
			</condition>
			<condition property="appdata.dir" value="${env.HOME}/.myproject">
				<os family="unix"  />
			</condition>


-----Original Message-----
From: Dean Schulze [mailto:dean_w_schulze@yahoo.com] 
Sent: Tuesday, June 22, 2010 11:25 AM
To: user@ant.apache.org
Subject: Need cross platform way of assigning users name to a property

My build.xml starts with the following lines:
 
<property environment="env"/>
<property name="user.username.dir" value="user/${env.USERNAME}"/>
<import file="${user.username.dir}/build.local.xml" optional="true"/>
 
This imports a build.local.xml file that holds machine-specific properties for each developer.
 
The problem is that this does not work on UNIX because the username is in env.USER in unix.  I need a cross-platform way to assign a user.name property in Ant.  
 
This has to be done at the top of the build.xml so that the <import ... /> is done before any other property assignments (the properties in build.local.xml are used if build.local.xml exists).  This means that the user.name property can't be assigned in a target so the condition statement is useless here.
 
Is there some way that I can read the username from the environment in a cross-platform way given that it has to happen at the top of the script?
 
 


      

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