You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Ken Wood <kw...@i2.com> on 2002/03/06 15:36:36 UTC
Probably dumb question about accessing system properties in build
listeners.
I wrote a simple build listener,
and I initially designed it to be configured
from a file. Now, I want it to be configured
from system properties on the command line.
So, I changed the code that reads the property
files to instead us java.lang.System.getProperty()...
When I invoke Ant, I used the -Dproperty=value syntax.
Well, when I test the listener, the properties are not
there! I suspect Ant is grabbing them because I see that
Project has getProperty methods. Problem is, I can't
see a way to get a handle on the project object in
a build listener. Everything else I looked at that
references a project object is extended from Project
in one way or another, so the access is easy.
Am I missing something? Is there some way for a build
listener to get the 'project' object so it can
get the properties? Any advice on how I should do this?
Or, should System.getProperty work???
Thanks!
-ken
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build listeners.
Posted by Magesh Umasankar <um...@apache.org>.
From: "Ken Wood" <kw...@i2.com>
Ken:
> So, I changed the code that reads the property
> files to instead us java.lang.System.getProperty()...
> When I invoke Ant, I used the -Dproperty=value syntax.
Don't supply -D to Ant; supply it to the
*java command* that invokes Ant.
>
> -ken
>
Cheers,
Magesh
****************************************
* Divorce: Future tense of marriage. *
****************************************
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build listeners.
Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 06 Mar 2002, Ken Wood <kw...@i2.com> wrote:
> Well, what I tried was to use lava.lang.System.getProperty
> in the constructor of the listener. The properties were
> always empty, even though they were set on the command line.
You need to specify them before Ant's main class to make the system
properties, if you put them after Main, they are only Ant properties.
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build listeners.
Posted by Jose Alberto Fernandez <j_...@yahoo.com>.
From: "Ken Wood" <kw...@i2.com>
> I'll try moving where I use "System.getProperty" to
> a differnet place, such as build started...
>
If you are calling Ant with something like:
ant -DpropA=y -listener x.y.z ...
"propA" will never be on the System properties. The only way to make it into
System.properties is by doing:
set ANT_OPTS=-DpropA=y
ant -listener x.y.z ...
this is do to the way the ant script works.
Jose Alberto
> Erik Hatcher wrote:
> >
> > Are you grabbing them in buildStarted? (Un?)fortunately the Ant properties
> > have not been set then. You will have to grab them during another event
> > (lazy initialize in the first event where you need the property other than
> > buildStarted, and cache whatever you need from buildStarted until then).
> >
> > Although System.getProperty should work, I'd think, although I've not tried
> > it. That would mean you'd have to set them on the command-line rather than
> > within a build file, but that seems ok for your needs at least.
> >
> > Erik
> >
> > ----- Original Message -----
> > From: "Ken Wood" <kw...@i2.com>
> > To: "Ant Developers List" <an...@jakarta.apache.org>
> > Sent: Wednesday, March 06, 2002 9:36 AM
> > Subject: Probably dumb question about accessing system properties in build
> > listeners.
> >
> > > I wrote a simple build listener,
> > > and I initially designed it to be configured
> > > from a file. Now, I want it to be configured
> > > from system properties on the command line.
> > >
> > > So, I changed the code that reads the property
> > > files to instead us java.lang.System.getProperty()...
> > > When I invoke Ant, I used the -Dproperty=value syntax.
> > >
> > > Well, when I test the listener, the properties are not
> > > there! I suspect Ant is grabbing them because I see that
> > > Project has getProperty methods. Problem is, I can't
> > > see a way to get a handle on the project object in
> > > a build listener. Everything else I looked at that
> > > references a project object is extended from Project
> > > in one way or another, so the access is easy.
> > >
> > > Am I missing something? Is there some way for a build
> > > listener to get the 'project' object so it can
> > > get the properties? Any advice on how I should do this?
> > > Or, should System.getProperty work???
> > >
> > > Thanks!
> > >
> > > -ken
> > >
> > > --
> > > To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > >
> > >
> >
> > --
> > To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build listeners.
Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Yes, the project object is available as part of all event objects passed to
the events. And sometimes the target and task objects are available also
(depends on the event), but always project is there. Again, the properties
don't get populated before buildStarted fires though, so you're out of luck
there.
----- Original Message -----
From: "Ken Wood" <kw...@i2.com>
To: "Ant Developers List" <an...@jakarta.apache.org>
Sent: Wednesday, March 06, 2002 10:12 AM
Subject: Re: Probably dumb question about accessing system properties in
build listeners.
> Well, what I tried was to use lava.lang.System.getProperty
> in the constructor of the listener. The properties were
> always empty, even though they were set on the command line.
>
> As you guess, I don't want them in the build.xml, because the build.xml
works
> generically, and then these command line properties tailor
> what I want on a branch to branch basis...
>
> I'll try moving where I use "System.getProperty" to
> a differnet place, such as build started...
>
> But, I take it from the lack of info in your reply there is no way to
> access the 'project' object?
>
> Erik Hatcher wrote:
> >
> > Are you grabbing them in buildStarted? (Un?)fortunately the Ant
properties
> > have not been set then. You will have to grab them during another event
> > (lazy initialize in the first event where you need the property other
than
> > buildStarted, and cache whatever you need from buildStarted until then).
> >
> > Although System.getProperty should work, I'd think, although I've not
tried
> > it. That would mean you'd have to set them on the command-line rather
than
> > within a build file, but that seems ok for your needs at least.
> >
> > Erik
> >
> > ----- Original Message -----
> > From: "Ken Wood" <kw...@i2.com>
> > To: "Ant Developers List" <an...@jakarta.apache.org>
> > Sent: Wednesday, March 06, 2002 9:36 AM
> > Subject: Probably dumb question about accessing system properties in
build
> > listeners.
> >
> > > I wrote a simple build listener,
> > > and I initially designed it to be configured
> > > from a file. Now, I want it to be configured
> > > from system properties on the command line.
> > >
> > > So, I changed the code that reads the property
> > > files to instead us java.lang.System.getProperty()...
> > > When I invoke Ant, I used the -Dproperty=value syntax.
> > >
> > > Well, when I test the listener, the properties are not
> > > there! I suspect Ant is grabbing them because I see that
> > > Project has getProperty methods. Problem is, I can't
> > > see a way to get a handle on the project object in
> > > a build listener. Everything else I looked at that
> > > references a project object is extended from Project
> > > in one way or another, so the access is easy.
> > >
> > > Am I missing something? Is there some way for a build
> > > listener to get the 'project' object so it can
> > > get the properties? Any advice on how I should do this?
> > > Or, should System.getProperty work???
> > >
> > > Thanks!
> > >
> > > -ken
> > >
> > > --
> > > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> > >
> > >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build
listeners.
Posted by Ken Wood <kw...@i2.com>.
Well, what I tried was to use lava.lang.System.getProperty
in the constructor of the listener. The properties were
always empty, even though they were set on the command line.
As you guess, I don't want them in the build.xml, because the build.xml works
generically, and then these command line properties tailor
what I want on a branch to branch basis...
I'll try moving where I use "System.getProperty" to
a differnet place, such as build started...
But, I take it from the lack of info in your reply there is no way to
access the 'project' object?
Erik Hatcher wrote:
>
> Are you grabbing them in buildStarted? (Un?)fortunately the Ant properties
> have not been set then. You will have to grab them during another event
> (lazy initialize in the first event where you need the property other than
> buildStarted, and cache whatever you need from buildStarted until then).
>
> Although System.getProperty should work, I'd think, although I've not tried
> it. That would mean you'd have to set them on the command-line rather than
> within a build file, but that seems ok for your needs at least.
>
> Erik
>
> ----- Original Message -----
> From: "Ken Wood" <kw...@i2.com>
> To: "Ant Developers List" <an...@jakarta.apache.org>
> Sent: Wednesday, March 06, 2002 9:36 AM
> Subject: Probably dumb question about accessing system properties in build
> listeners.
>
> > I wrote a simple build listener,
> > and I initially designed it to be configured
> > from a file. Now, I want it to be configured
> > from system properties on the command line.
> >
> > So, I changed the code that reads the property
> > files to instead us java.lang.System.getProperty()...
> > When I invoke Ant, I used the -Dproperty=value syntax.
> >
> > Well, when I test the listener, the properties are not
> > there! I suspect Ant is grabbing them because I see that
> > Project has getProperty methods. Problem is, I can't
> > see a way to get a handle on the project object in
> > a build listener. Everything else I looked at that
> > references a project object is extended from Project
> > in one way or another, so the access is easy.
> >
> > Am I missing something? Is there some way for a build
> > listener to get the 'project' object so it can
> > get the properties? Any advice on how I should do this?
> > Or, should System.getProperty work???
> >
> > Thanks!
> >
> > -ken
> >
> > --
> > To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Probably dumb question about accessing system properties in build listeners.
Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Are you grabbing them in buildStarted? (Un?)fortunately the Ant properties
have not been set then. You will have to grab them during another event
(lazy initialize in the first event where you need the property other than
buildStarted, and cache whatever you need from buildStarted until then).
Although System.getProperty should work, I'd think, although I've not tried
it. That would mean you'd have to set them on the command-line rather than
within a build file, but that seems ok for your needs at least.
Erik
----- Original Message -----
From: "Ken Wood" <kw...@i2.com>
To: "Ant Developers List" <an...@jakarta.apache.org>
Sent: Wednesday, March 06, 2002 9:36 AM
Subject: Probably dumb question about accessing system properties in build
listeners.
> I wrote a simple build listener,
> and I initially designed it to be configured
> from a file. Now, I want it to be configured
> from system properties on the command line.
>
> So, I changed the code that reads the property
> files to instead us java.lang.System.getProperty()...
> When I invoke Ant, I used the -Dproperty=value syntax.
>
> Well, when I test the listener, the properties are not
> there! I suspect Ant is grabbing them because I see that
> Project has getProperty methods. Problem is, I can't
> see a way to get a handle on the project object in
> a build listener. Everything else I looked at that
> references a project object is extended from Project
> in one way or another, so the access is easy.
>
> Am I missing something? Is there some way for a build
> listener to get the 'project' object so it can
> get the properties? Any advice on how I should do this?
> Or, should System.getProperty work???
>
> Thanks!
>
> -ken
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>