You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by jm <jm...@gmail.com> on 2006/12/19 11:44:52 UTC
set a property in a .properties file
hi,
I have been looking for a way to set a property in a .properties file
via ant. Could not find any easy way...somebody knows a way to do it
or a external task or something?
I know about the <replace> stuff, but I am trying to change the
property without knowing the value it had before, that is, I cannot
assume it is 'aproperty=@replaceme@'
thanks,
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: set a property in a .properties file
Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hi,
there are a lots of ways to write to a property file in ant.
Look at the following :
<echo file="some.properties">
somekey=somevalue
</echo>
there is also the propertyfile task which can do some limited
arithmetics on properties (in the Optional Tasks section of the manual).
there might also be the option of using the <copy/> task with a
nested filterchain (see explanations about filterchains under
Concepts and Types).
Regards,
Antoine
On Dec 19, 2006, at 5:44 AM, jm wrote:
> hi,
>
> I have been looking for a way to set a property in a .properties file
> via ant. Could not find any easy way...somebody knows a way to do it
> or a external task or something?
>
> I know about the <replace> stuff, but I am trying to change the
> property without knowing the value it had before, that is, I cannot
> assume it is 'aproperty=@replaceme@'
>
> thanks,
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: set a property in a .properties file
Posted by jm <jm...@gmail.com>.
Peter,
thanks for pointing that out, I'll check that if it works that would
be perfect. The 'maybe its easy' comment was moslty thinking aloud
without any prior knowledge obviously...
On 12/19/06, Peter Reilly <pe...@gmail.com> wrote:
> On 12/19/06, jm <jm...@gmail.com> wrote:
> > Antoine,
> > echoing would add a second line with the property no?, and I want the
> > exisiting line to be modified...propertyFile would do, I had missed
> > that one, it's a pity comments are lost though...
> >
> > Gilbert ,
> > yes I think that would work, but I have never used any of these
> > scripting languages.
> >
> > does anybody know where the souce code for propertyFile is? maybe its
> > easy to make it keep the comments...
> >
> There is a patch for this.
> http://issues.apache.org/bugzilla/show_bug.cgi?id=36901
> I would not call it "easy".
>
> Peter
>
> > thanks both,
> > javi
> >
> > On 12/19/06, Rebhan, Gilbert <Gi...@huk-coburg.de> wrote:
> > >
> > > Oops,
> > >
> > > should have been =
> > >
> > > test.props afterwards :
> > > foo=nobar
> > >
> > >
> > > Regards, Gilbert
> > >
> > >
> > > -----Original Message-----
> > > From: jm [mailto:jmuguruza@gmail.com]
> > > Sent: Tuesday, December 19, 2006 11:45 AM
> > > To: Ant Users List
> > > Subject: set a property in a .properties file
> > >
> > > hi,
> > >
> > > I have been looking for a way to set a property in a .properties file
> > > via ant. Could not find any easy way...somebody knows a way to do it
> > > or a external task or something?
> > >
> > > I know about the <replace> stuff, but I am trying to change the
> > > property without knowing the value it had before, that is, I cannot
> > > assume it is 'aproperty=@replaceme@'
> > >
> > > thanks,
> > >
> > > ---------------------------------------------------------------------
> > > 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
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> ---------------------------------------------------------------------
> 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: set a property in a .properties file
Posted by Peter Reilly <pe...@gmail.com>.
On 12/19/06, jm <jm...@gmail.com> wrote:
> Antoine,
> echoing would add a second line with the property no?, and I want the
> exisiting line to be modified...propertyFile would do, I had missed
> that one, it's a pity comments are lost though...
>
> Gilbert ,
> yes I think that would work, but I have never used any of these
> scripting languages.
>
> does anybody know where the souce code for propertyFile is? maybe its
> easy to make it keep the comments...
>
There is a patch for this.
http://issues.apache.org/bugzilla/show_bug.cgi?id=36901
I would not call it "easy".
Peter
> thanks both,
> javi
>
> On 12/19/06, Rebhan, Gilbert <Gi...@huk-coburg.de> wrote:
> >
> > Oops,
> >
> > should have been =
> >
> > test.props afterwards :
> > foo=nobar
> >
> >
> > Regards, Gilbert
> >
> >
> > -----Original Message-----
> > From: jm [mailto:jmuguruza@gmail.com]
> > Sent: Tuesday, December 19, 2006 11:45 AM
> > To: Ant Users List
> > Subject: set a property in a .properties file
> >
> > hi,
> >
> > I have been looking for a way to set a property in a .properties file
> > via ant. Could not find any easy way...somebody knows a way to do it
> > or a external task or something?
> >
> > I know about the <replace> stuff, but I am trying to change the
> > property without knowing the value it had before, that is, I cannot
> > assume it is 'aproperty=@replaceme@'
> >
> > thanks,
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: set a property in a .properties file
Posted by jm <jm...@gmail.com>.
Antoine,
echoing would add a second line with the property no?, and I want the
exisiting line to be modified...propertyFile would do, I had missed
that one, it's a pity comments are lost though...
Gilbert ,
yes I think that would work, but I have never used any of these
scripting languages.
does anybody know where the souce code for propertyFile is? maybe its
easy to make it keep the comments...
thanks both,
javi
On 12/19/06, Rebhan, Gilbert <Gi...@huk-coburg.de> wrote:
>
> Oops,
>
> should have been =
>
> test.props afterwards :
> foo=nobar
>
>
> Regards, Gilbert
>
>
> -----Original Message-----
> From: jm [mailto:jmuguruza@gmail.com]
> Sent: Tuesday, December 19, 2006 11:45 AM
> To: Ant Users List
> Subject: set a property in a .properties file
>
> hi,
>
> I have been looking for a way to set a property in a .properties file
> via ant. Could not find any easy way...somebody knows a way to do it
> or a external task or something?
>
> I know about the <replace> stuff, but I am trying to change the
> property without knowing the value it had before, that is, I cannot
> assume it is 'aproperty=@replaceme@'
>
> thanks,
>
> ---------------------------------------------------------------------
> 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
>
>
> ---------------------------------------------------------------------
> 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: set a property in a .properties file
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Oops,
should have been =
test.props afterwards :
foo=nobar
Regards, Gilbert
-----Original Message-----
From: jm [mailto:jmuguruza@gmail.com]
Sent: Tuesday, December 19, 2006 11:45 AM
To: Ant Users List
Subject: set a property in a .properties file
hi,
I have been looking for a way to set a property in a .properties file
via ant. Could not find any easy way...somebody knows a way to do it
or a external task or something?
I know about the <replace> stuff, but I am trying to change the
property without knowing the value it had before, that is, I cannot
assume it is 'aproperty=@replaceme@'
thanks,
---------------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: set a property in a .properties file
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi,
forgot the replacement in my last mail =
given propertyfile test.props :
foo=bar
<script language="ruby">
<![CDATA[
#replace in your property file
# optionally create a new file just use
# a different outfile
infile = 'Y:/test.props'
outfile = 'Y:/test.props'
old = File.read(infile)
old.gsub!(/#{$foo}/, 'nobar')
File.open(outfile, "w") {|new| new.write(old)}
if infile == outfile
puts 'Modified = '<<infile<<' inplace'
else
puts 'Modified = '<<infile<<' to = '<<outfile
end
# reset for further ant processing
$project.setProperty "foo","nobar"
]]>
</script>
test.props afterwards :
foo=foobar
Regards, Gilbert
-----Original Message-----
From: jm [mailto:jmuguruza@gmail.com]
Sent: Tuesday, December 19, 2006 11:45 AM
To: Ant Users List
Subject: set a property in a .properties file
hi,
I have been looking for a way to set a property in a .properties file
via ant. Could not find any easy way...somebody knows a way to do it
or a external task or something?
I know about the <replace> stuff, but I am trying to change the
property without knowing the value it had before, that is, I cannot
assume it is 'aproperty=@replaceme@'
thanks,
---------------------------------------------------------------------
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: set a property in a .properties file
Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi,
if you want to reset / overwrite an existing property the easiest way is
via script
task and language of your choice (ruby,javascript,groovy ...) , f.e. =
<project name="bla" default="main" basedir=".">
<!-- // Properties -->
<property name="foo" value="bar"/>
<!-- Properties // -->
<target name="depends">
<!-- using javascript -->
<script language="javascript">
<![CDATA[
project.setProperty("foo","nobar")
]]>
</script>
<!-- using jruby -->
<script language="ruby">
<![CDATA[
$project.setProperty("foo","nobar")
]]>
</script>
</target>
<target name="main" depends="depends">
<script language="ruby">
<![CDATA[
case $foo
when /^bar/
puts 'yup, one beer please !!'
else
puts 'no beer today ...'
end
]]>
</script>
</target>
Regards, Gilbert
-----Original Message-----
From: jm [mailto:jmuguruza@gmail.com]
Sent: Tuesday, December 19, 2006 11:45 AM
To: Ant Users List
Subject: set a property in a .properties file
hi,
I have been looking for a way to set a property in a .properties file
via ant. Could not find any easy way...somebody knows a way to do it
or a external task or something?
I know about the <replace> stuff, but I am trying to change the
property without knowing the value it had before, that is, I cannot
assume it is 'aproperty=@replaceme@'
thanks,
---------------------------------------------------------------------
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