You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Daniel Gröndal <da...@ericsson.com> on 2008/06/02 11:29:53 UTC

how to echo propertyset to file?

Hi all!
 
I have a problem echoing a set of properties to a specified file. I have a number of properties which have a common prefix, but the exact number is undefined, so these properties are selectable by a propertyset by I do not know the exakt number.
 
The reason for this somewhat uncommon setup is that I have created a common "base" file (common.xml) that is imported into other (project specific) build files in my workspace. This saves me a lot of time and typing since my projects have similiar setup. This base file has a target for creating a jad-file (a sort of manifest file used in MIDlet development) which holds information about a jar-file. The importing build files however holds some information about midlets that is not known when creating the common base build file, and therefore I have to be able to find these properties and print them in a generic way, regardless of how many they are.
 
The target just looks like this:
 
<!--_________Creates the jad file for the project_________
<target name="create.jad" description="Creates a jad file for the midlet suite.">
	<echo file="${ant.project.name}.jad" message="MIDlet-Version: ${MIDletVersion}${line.separator}" append="true"/>
	<echo file="${ant.project.name}.jad" message="MIDlet-Vendor: ${MIDletVendor}${line.separator}" append="true"/>
	<echo file="${ant.project.name}.jad" message="MIDlet-Jar-URL: ${MIDletJarUrl}${line.separator}" append="true"/>
	<!-- and on it goes for some more properties including my unknown number of specific properties -->
</target>

The properties echoed (such as MIDletVersion etc) out are set by the build file importing the base file.

At the end of this target I would like to echo out all properties with a certain prefix. The propertyset I want to output can be created like:

<propertyset id="midlet_properties">
	<propertyref prefix="MIDlet_"/>
</propertyset>

But how do I echo this propertyset to the specified file? I tried using <echoproperties> (I know this might not be the intention of echoproperties). That gives me some additional lines at the top of the file that I do not want. I also tried using pathconvert but that really needs a path, not a propertyset. 

Do I have to use foreach from ant-contrib? Are there any other (reasonable) way to do this? Any suggestions are more than welcome right now.

Thanks,

//daniel

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


RE: how to echo propertyset to file?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
 

-----Original Message-----
From: Daniel Gröndal [mailto:daniel.grondal@ericsson.com] 
Sent: Monday, June 02, 2008 11:30 AM
To: user@ant.apache.org
Subject: how to echo propertyset to file?

p.s. beware of the typos ;-) forgot also the append="true" attribute
in the echo task

corrected =

...

Just use =
<echo file="file/to/dump/to/props.ext">${toString:midlet.properties}</echo>

...

use antcontrib <for> to get it line separated, something like=

<for list="${toString:midlet.properties}" param="prop">
 <sequential>
   <echo file="file/to/dump/to/props.ext" append="true">@{prop}${line.separator}</echo>
 </sequential>
</for>


Regards, Gilbert

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


RE: how to echo propertyset to file?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Daniel Gröndal [mailto:daniel.grondal@ericsson.com] 
Sent: Monday, June 02, 2008 11:30 AM
To: user@ant.apache.org
Subject: how to echo propertyset to file?

/*
Hi all!
 
I have a problem echoing a set of properties to a specified file. I have a number of properties which have a common prefix, but the exact number is undefined, so these properties are selectable by a propertyset by I do not know the exakt number.

[ ... ] 

<propertyset id="midlet_properties">
	<propertyref prefix="MIDlet_"/>
</propertyset>

But how do I echo this propertyset to the specified file? I tried using <echoproperties> (I know this might not be the intention of echoproperties). That gives me some additional lines at the top of the file that I do not want. I also tried using pathconvert but that really needs a path, not a propertyset. 
*/


Just use =
<echo file="file/to/dump/to"props.ext">${toString:midlet.properties}</echo>

/*
Do I have to use foreach from ant-contrib? Are there any other (reasonable) way to do this? Any suggestions are more than welcome right now.
*/

use antcontrib <for> to get it line separated, something like=

<for list="${toString:midlet.properties} param="prop">
 <sequential>
   <echo file="file/to/dump/to/props.ext>@{prop}${line.separator}</echo>
 </sequential>
</for>


Regards, Gilbert

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


Re: how to echo propertyset to file?

Posted by Peter Reilly <pe...@gmail.com>.
On Thu, Jun 5, 2008 at 11:14 AM, Rebhan, Gilbert
<Gi...@huk-coburg.de> wrote:
>
>
> -----Original Message-----
> From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com]
> Sent: Thursday, June 05, 2008 11:53 AM
> To: Ant Users List
> Subject: Re: how to echo propertyset to file?
>
> /*
>
>>> Just curious... Where is the ${tostring:} function and other types of
> This should be toString - it is case sensitive
>>> functions documented in Ant
>
>> It's not documented in the manuals, but well known
>> among experienced ant users.
>
> It is documented in using.html and resources.html
>
> */
>
> in svn /cvs only ?
> Didn't find it in my official binary releases of 1.6.5 and 1.7.0 ...
Perhaps..
It will be in ant 1.7.1 for sure..
Peter

>
> Regards, Gilbert
>
>
> ---------------------------------------------------------------------
> 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: how to echo propertyset to file?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com] 
Sent: Thursday, June 05, 2008 11:53 AM
To: Ant Users List
Subject: Re: how to echo propertyset to file?

/*

>> Just curious... Where is the ${tostring:} function and other types of
This should be toString - it is case sensitive
>> functions documented in Ant

> It's not documented in the manuals, but well known
> among experienced ant users.

It is documented in using.html and resources.html

*/

in svn /cvs only ?
Didn't find it in my official binary releases of 1.6.5 and 1.7.0 ...

Regards, Gilbert


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


Re: how to echo propertyset to file?

Posted by Peter Reilly <pe...@gmail.com>.
On Mon, Jun 2, 2008 at 7:04 PM, Gilbert Rebhan <an...@schillbaer.de> wrote:
> Hi, David
>
> David Weintraub schrieb:
>>
>> Just curious... Where is the ${tostring:} function and other types of
This should be toString - it is case sensitive
>> functions documented in Ant
There are currently no other functions in ant.
>
> Once i've read here on the list about it and from that
> on i've used it all the time.
>
> It's not documented in the manuals, but well known
> among experienced ant users.

It is documented in using.html and resources.html

>
> The $[toString:nameOfID} syntax seems to be 'valid' with the most
> id / refid stuff, though i remember it didn't work with
> one special thing, but don't remember in detail.
>
> Means it works in my daily stuff with filesets, propertysets ...
> that's when i use it combined with antcontrib <for> or <script>
>
> As far as i know it's also mentioned in the 2nd Edition
> of 'Ant In Action' by Steve Loughran.
> Maybe the book has more details about ?!
>
>> It would be nice to see a list of all such functions.
>
> If you have a task with id/refid simply try and you'll see
> if it works, that's what i'd do.
>
> btw. if you are fan of such shorthand expressions (as i am)
> take a look at AntXtras,they have something they call valueuris
> http://antxtras.sourceforge.net/AntXtras/overview.html#valueuris
>
> maybe something similar is coming up with ant 1.8. see
> http://marc.info/?l=ant-user&m=118288301701425&w=2

Yes there are plans, at least to allow plugins to define the
namespaceie functions.

Peter

>
> Regards, Gilbert
>
>
>
> ---------------------------------------------------------------------
> 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: how to echo propertyset to file?

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi, David

David Weintraub schrieb:
> Just curious... Where is the ${tostring:} function and other types of
> functions documented in Ant

Once i've read here on the list about it and from that
on i've used it all the time.

It's not documented in the manuals, but well known
among experienced ant users.

The $[toString:nameOfID} syntax seems to be 'valid' with the most
id / refid stuff, though i remember it didn't work with
one special thing, but don't remember in detail.

Means it works in my daily stuff with filesets, propertysets ...
that's when i use it combined with antcontrib <for> or <script>

As far as i know it's also mentioned in the 2nd Edition
of 'Ant In Action' by Steve Loughran.
Maybe the book has more details about ?!

> It would be nice to see a list of all such functions.

If you have a task with id/refid simply try and you'll see
if it works, that's what i'd do.

btw. if you are fan of such shorthand expressions (as i am)
take a look at AntXtras,they have something they call valueuris
http://antxtras.sourceforge.net/AntXtras/overview.html#valueuris

maybe something similar is coming up with ant 1.8. see
http://marc.info/?l=ant-user&m=118288301701425&w=2

Regards, Gilbert



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


Re: how to echo propertyset to file?

Posted by David Weintraub <qa...@gmail.com>.
Just curious... Where is the ${tostring:} function and other types of
functions documented in Ant?

It would be nice to see a list of all such functions.

On Mon, Jun 2, 2008 at 10:36 AM, Rebhan, Gilbert
<Gi...@huk-coburg.de> wrote:
>
>
> -----Original Message-----
> From: David Weintraub [mailto:qazwart@gmail.com]
> Sent: Monday, June 02, 2008 4:13 PM
> To: Ant Users List
> Subject: Re: how to echo propertyset to file?
>
> /*
> The easiest way to turn a resource ID into something that can be
> echoed is to set a property via a resource ID:
>
> <propertyset id="midlet_properties">
>       <propertyref prefix="MIDlet_"/>
> </propertyset>
>
> <property name="midlet_property_set" refid="midlet_properties"/>
> <echo>Property Set: ${midlet_property_set}</echo>
> */
>
>  the easiest way, without setting another property =
> ${toString:midlet_properties} which gives the same result, a comma
> separated list
>
> /*
> <echo>Property = "${foo_prop}"</echo>
> */
>
> <echo>Property="{toString:midlet_properties}"</echo>
>
> Might not work with all id / refid, but that would always
> be my first attempt.
>
> Regards, Gilbert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

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


RE: how to echo propertyset to file?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com] 
Sent: Monday, June 02, 2008 4:13 PM
To: Ant Users List
Subject: Re: how to echo propertyset to file?

/*
The easiest way to turn a resource ID into something that can be
echoed is to set a property via a resource ID:

<propertyset id="midlet_properties">
       <propertyref prefix="MIDlet_"/>
</propertyset>

<property name="midlet_property_set" refid="midlet_properties"/>
<echo>Property Set: ${midlet_property_set}</echo>
*/

 the easiest way, without setting another property =
${toString:midlet_properties} which gives the same result, a comma
separated list

/*
<echo>Property = "${foo_prop}"</echo>
*/

<echo>Property="{toString:midlet_properties}"</echo>

Might not work with all id / refid, but that would always
be my first attempt.

Regards, Gilbert

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


RE: how to echo propertyset to file?

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
-----Original Message-----
From: Daniel Gröndal [mailto:daniel.grondal@ericsson.com] 
Sent: Monday, June 02, 2008 4:25 PM
To: Ant Users List
Subject: RE: how to echo propertyset to file?

/*
Hi!

Well, not too bad. This might be a good starting point. I would however like to replace the "," with a newline and get an output like this:

foo_four=four
foo_one=one
foo_three=three
foo_two=two

Any ideas on how to do this as well?

//daniel
*/

As already posted in this thread =

means, you get automatically a comma separated list when using
${toString:midlet.properties} and you can dump it separated with
linefeed as you want it with antcontrib <for>

<for list="${toString:midlet.properties}" param="prop">
 <sequential>
   <echo file="file/to/dump/to/props.ext" append="true">@{prop}${line.separator}</echo>
 </sequential>
</for>

that's all


Regards, Gilbert

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


RE: how to echo propertyset to file?

Posted by Daniel Gröndal <da...@ericsson.com>.
Hi!

Well, not too bad. This might be a good starting point. I would however like to replace the "," with a newline and get an output like this:

foo_four=four
foo_one=one
foo_three=three
foo_two=two

Any ideas on how to do this as well?

//daniel

-----Original Message-----
From: David Weintraub [mailto:qazwart@gmail.com] 
Sent: den 2 juni 2008 16:13
To: Ant Users List
Subject: Re: how to echo propertyset to file?

The easiest way to turn a resource ID into something that can be echoed is to set a property via a resource ID:

<propertyset id="midlet_properties">
       <propertyref prefix="MIDlet_"/>
</propertyset>

<property name="midlet_property_set" refid="midlet_properties"/> <echo>Property Set: ${midlet_property_set}</echo>

I just ran a test:

project name="myapp" default="test" basedir=".">
     <target name="test">
         <property name="bar_one" value="one"/>
         <property name="bar_two" value="two"/>
         <property name="bar_three" value="three"/>
         <property name="bar_four" value="four"/>

         <property name="foo_one" value="one"/>
         <property name="foo_two" value="two"/>
         <property name="foo_three" value="three"/>
         <property name="foo_four" value="four"/>

         <propertyset id="foo_props">
             <propertyref prefix="foo_"/>
         </propertyset>

         <property name="foo_prop" refid="foo_props"/>

         <echo>Property = "${foo_prop}"</echo>
     </target>
</project>


/Users/david$ ant
Buildfile: build.xml

test:
     [echo] Property = "foo_four=four, foo_one=one, foo_three=three, foo_two=two"

BUILD SUCCESSFUL
Total time: 2 seconds

Is this what you're looking for?

On Mon, Jun 2, 2008 at 5:29 AM, Daniel Gröndal <da...@ericsson.com> wrote:
> Hi all!
>
> I have a problem echoing a set of properties to a specified file. I have a number of properties which have a common prefix, but the exact number is undefined, so these properties are selectable by a propertyset by I do not know the exakt number.
>
> The reason for this somewhat uncommon setup is that I have created a common "base" file (common.xml) that is imported into other (project specific) build files in my workspace. This saves me a lot of time and typing since my projects have similiar setup. This base file has a target for creating a jad-file (a sort of manifest file used in MIDlet development) which holds information about a jar-file. The importing build files however holds some information about midlets that is not known when creating the common base build file, and therefore I have to be able to find these properties and print them in a generic way, regardless of how many they are.
>
> The target just looks like this:
>
> <!--_________Creates the jad file for the project_________ <target 
> name="create.jad" description="Creates a jad file for the midlet suite.">
>        <echo file="${ant.project.name}.jad" message="MIDlet-Version: ${MIDletVersion}${line.separator}" append="true"/>
>        <echo file="${ant.project.name}.jad" message="MIDlet-Vendor: ${MIDletVendor}${line.separator}" append="true"/>
>        <echo file="${ant.project.name}.jad" message="MIDlet-Jar-URL: ${MIDletJarUrl}${line.separator}" append="true"/>
>        <!-- and on it goes for some more properties including my 
> unknown number of specific properties --> </target>
>
> The properties echoed (such as MIDletVersion etc) out are set by the build file importing the base file.
>
> At the end of this target I would like to echo out all properties with a certain prefix. The propertyset I want to output can be created like:
>
> <propertyset id="midlet_properties">
>        <propertyref prefix="MIDlet_"/> </propertyset>
>
> But how do I echo this propertyset to the specified file? I tried using <echoproperties> (I know this might not be the intention of echoproperties). That gives me some additional lines at the top of the file that I do not want. I also tried using pathconvert but that really needs a path, not a propertyset.
>
> Do I have to use foreach from ant-contrib? Are there any other (reasonable) way to do this? Any suggestions are more than welcome right now.
>
> Thanks,
>
> //daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional 
> commands, e-mail: user-help@ant.apache.org
>
>



--
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
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: how to echo propertyset to file?

Posted by David Weintraub <qa...@gmail.com>.
The easiest way to turn a resource ID into something that can be
echoed is to set a property via a resource ID:

<propertyset id="midlet_properties">
       <propertyref prefix="MIDlet_"/>
</propertyset>

<property name="midlet_property_set" refid="midlet_properties"/>
<echo>Property Set: ${midlet_property_set}</echo>

I just ran a test:

project name="myapp" default="test" basedir=".">
     <target name="test">
         <property name="bar_one" value="one"/>
         <property name="bar_two" value="two"/>
         <property name="bar_three" value="three"/>
         <property name="bar_four" value="four"/>

         <property name="foo_one" value="one"/>
         <property name="foo_two" value="two"/>
         <property name="foo_three" value="three"/>
         <property name="foo_four" value="four"/>

         <propertyset id="foo_props">
             <propertyref prefix="foo_"/>
         </propertyset>

         <property name="foo_prop" refid="foo_props"/>

         <echo>Property = "${foo_prop}"</echo>
     </target>
</project>


/Users/david$ ant
Buildfile: build.xml

test:
     [echo] Property = "foo_four=four, foo_one=one, foo_three=three,
foo_two=two"

BUILD SUCCESSFUL
Total time: 2 seconds

Is this what you're looking for?

On Mon, Jun 2, 2008 at 5:29 AM, Daniel Gröndal
<da...@ericsson.com> wrote:
> Hi all!
>
> I have a problem echoing a set of properties to a specified file. I have a number of properties which have a common prefix, but the exact number is undefined, so these properties are selectable by a propertyset by I do not know the exakt number.
>
> The reason for this somewhat uncommon setup is that I have created a common "base" file (common.xml) that is imported into other (project specific) build files in my workspace. This saves me a lot of time and typing since my projects have similiar setup. This base file has a target for creating a jad-file (a sort of manifest file used in MIDlet development) which holds information about a jar-file. The importing build files however holds some information about midlets that is not known when creating the common base build file, and therefore I have to be able to find these properties and print them in a generic way, regardless of how many they are.
>
> The target just looks like this:
>
> <!--_________Creates the jad file for the project_________
> <target name="create.jad" description="Creates a jad file for the midlet suite.">
>        <echo file="${ant.project.name}.jad" message="MIDlet-Version: ${MIDletVersion}${line.separator}" append="true"/>
>        <echo file="${ant.project.name}.jad" message="MIDlet-Vendor: ${MIDletVendor}${line.separator}" append="true"/>
>        <echo file="${ant.project.name}.jad" message="MIDlet-Jar-URL: ${MIDletJarUrl}${line.separator}" append="true"/>
>        <!-- and on it goes for some more properties including my unknown number of specific properties -->
> </target>
>
> The properties echoed (such as MIDletVersion etc) out are set by the build file importing the base file.
>
> At the end of this target I would like to echo out all properties with a certain prefix. The propertyset I want to output can be created like:
>
> <propertyset id="midlet_properties">
>        <propertyref prefix="MIDlet_"/>
> </propertyset>
>
> But how do I echo this propertyset to the specified file? I tried using <echoproperties> (I know this might not be the intention of echoproperties). That gives me some additional lines at the top of the file that I do not want. I also tried using pathconvert but that really needs a path, not a propertyset.
>
> Do I have to use foreach from ant-contrib? Are there any other (reasonable) way to do this? Any suggestions are more than welcome right now.
>
> Thanks,
>
> //daniel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

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