You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Jason Dillon <ja...@planet57.com> on 2006/09/04 02:57:41 UTC
Using plexus to inject custom objects (and inject their parameters)?
Hi, I asked about this in #maven a while ago, but I forgot what the
answer was.
How can I configure plexus to inject custom objects into my mojo, and
have plexus inject parameters into that object?
For example, say I have:
<snip>
public class ConntectionConfig
{
/**
* The port number to connect to the server..
*
* @parameter expression="${port}" default-value="1099"
*/
public int port = -1;
/**
* The username to authenticate with.
*
* @parameter expression="${username}" default-value="system"
*/
public String username = null;
/**
* The password to authenticate with.
*
* @parameter expression="${password}" default-value="manager"
*/
public String password = null;
}
</snip>
And a mojo like:
<snip>
/**
* @goal test
*/
public class TestMojo
extends ...
{
/**
* Connection configuration
*
* @parameter
*/
protected ConntectionConfig connection = null;
}
</snip>
I'd like to be able to:
mvn whatever:test -Dusername=foo
Which will create a new ConnectionConfig, inject username from $
{username} and then initialize the other fields to to their default-
values.
I tried briefly, using @plexus.component for ConnectionConfig, and
then @component for the connection parameter... but it did not inject
anything into the ConnectionConfig object. If I specify something like:
<configuration>
<connection>
<username>foo</username>
</connection>
</configuration>
Then username does get set to foo, but the others are left as nulls.
I really need a better way to share configuration and logic among
mojo's... inheritance is not cutting it, as some mojos end up with
more than they really need, and I'm forced to create a bunch of
intermediate abstract classes to organize which mojos need what.
Is this possible? And if so, can someone point me at a simple example?
Thanks,
--jason
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Using plexus to inject custom objects (and inject their parameters)?
Posted by Jason van Zyl <ja...@maven.org>.
On 3 Sep 06, at 9:46 PM 3 Sep 06, Jason Dillon wrote:
> Thanks, but I can wait until this is rolled up into a release. I
> think having this will really make it easier to create more
> powerful mojos... and to share commonly used configuration and
> logic objects w/o needing to sub-class.
>
Yes, it would be generally useful for plexus components in general.
> --jason
>
>
> On Sep 3, 2006, at 6:12 PM, Jason van Zyl wrote:
>
>>
>> On 3 Sep 06, at 8:57 PM 3 Sep 06, Jason Dillon wrote:
>>
>>> Hi, I asked about this in #maven a while ago, but I forgot what
>>> the answer was.
>>>
>>> How can I configure plexus to inject custom objects into my mojo,
>>> and have plexus inject parameters into that object?
>>>
>>> For example, say I have:
>>>
>>> <snip>
>>> public class ConntectionConfig
>>> {
>>> /**
>>> * The port number to connect to the server..
>>> *
>>> * @parameter expression="${port}" default-value="1099"
>>> */
>>> public int port = -1;
>>>
>>> /**
>>> * The username to authenticate with.
>>> *
>>> * @parameter expression="${username}" default-value="system"
>>> */
>>> public String username = null;
>>>
>>> /**
>>> * The password to authenticate with.
>>> *
>>> * @parameter expression="${password}" default-value="manager"
>>> */
>>> public String password = null;
>>> }
>>> </snip>
>>>
>>> And a mojo like:
>>>
>>> <snip>
>>> /**
>>> * @goal test
>>> */
>>> public class TestMojo
>>> extends ...
>>> {
>>> /**
>>> * Connection configuration
>>> *
>>> * @parameter
>>> */
>>> protected ConntectionConfig connection = null;
>>> }
>>> </snip>
>>>
>>> I'd like to be able to:
>>>
>>> mvn whatever:test -Dusername=foo
>>>
>>> Which will create a new ConnectionConfig, inject username from $
>>> {username} and then initialize the other fields to to their
>>> default-values.
>>>
>>> I tried briefly, using @plexus.component for ConnectionConfig,
>>> and then @component for the connection parameter... but it did
>>> not inject anything into the ConnectionConfig object. If I
>>> specify something like:
>>>
>>> <configuration>
>>> <connection>
>>> <username>foo</username>
>>> </connection>
>>> </configuration>
>>>
>>> Then username does get set to foo, but the others are left as nulls.
>>>
>>> I really need a better way to share configuration and logic among
>>> mojo's... inheritance is not cutting it, as some mojos end up
>>> with more than they really need, and I'm forced to create a bunch
>>> of intermediate abstract classes to organize which mojos need what.
>>>
>>> Is this possible? And if so, can someone point me at a simple
>>> example?
>>>
>>
>> The configuration model for a mojo is not inspected for
>> annotations what what you have above for the ConnectionConfig is
>> not going to processed. I've added:
>>
>> http://jira.codehaus.org/browse/PLX-266
>>
>> As this would be generally useful. There are some issues related
>> to the component descriptor creator (CDC) for default
>> configuration values as well. So, short answer right now with
>> 2.0.4 it's not possible. If you're using trunk and you're
>> desperate I can do something.
>>
>>> Thanks,
>>>
>>> --jason
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: dev-help@maven.apache.org
>>>
>>>
>>
>> Jason van Zyl
>> jason@maven.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
Jason van Zyl
jason@maven.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Using plexus to inject custom objects (and inject their parameters)?
Posted by Jason Dillon <ja...@planet57.com>.
Thanks, but I can wait until this is rolled up into a release. I
think having this will really make it easier to create more powerful
mojos... and to share commonly used configuration and logic objects w/
o needing to sub-class.
--jason
On Sep 3, 2006, at 6:12 PM, Jason van Zyl wrote:
>
> On 3 Sep 06, at 8:57 PM 3 Sep 06, Jason Dillon wrote:
>
>> Hi, I asked about this in #maven a while ago, but I forgot what
>> the answer was.
>>
>> How can I configure plexus to inject custom objects into my mojo,
>> and have plexus inject parameters into that object?
>>
>> For example, say I have:
>>
>> <snip>
>> public class ConntectionConfig
>> {
>> /**
>> * The port number to connect to the server..
>> *
>> * @parameter expression="${port}" default-value="1099"
>> */
>> public int port = -1;
>>
>> /**
>> * The username to authenticate with.
>> *
>> * @parameter expression="${username}" default-value="system"
>> */
>> public String username = null;
>>
>> /**
>> * The password to authenticate with.
>> *
>> * @parameter expression="${password}" default-value="manager"
>> */
>> public String password = null;
>> }
>> </snip>
>>
>> And a mojo like:
>>
>> <snip>
>> /**
>> * @goal test
>> */
>> public class TestMojo
>> extends ...
>> {
>> /**
>> * Connection configuration
>> *
>> * @parameter
>> */
>> protected ConntectionConfig connection = null;
>> }
>> </snip>
>>
>> I'd like to be able to:
>>
>> mvn whatever:test -Dusername=foo
>>
>> Which will create a new ConnectionConfig, inject username from $
>> {username} and then initialize the other fields to to their
>> default-values.
>>
>> I tried briefly, using @plexus.component for ConnectionConfig, and
>> then @component for the connection parameter... but it did not
>> inject anything into the ConnectionConfig object. If I specify
>> something like:
>>
>> <configuration>
>> <connection>
>> <username>foo</username>
>> </connection>
>> </configuration>
>>
>> Then username does get set to foo, but the others are left as nulls.
>>
>> I really need a better way to share configuration and logic among
>> mojo's... inheritance is not cutting it, as some mojos end up with
>> more than they really need, and I'm forced to create a bunch of
>> intermediate abstract classes to organize which mojos need what.
>>
>> Is this possible? And if so, can someone point me at a simple
>> example?
>>
>
> The configuration model for a mojo is not inspected for annotations
> what what you have above for the ConnectionConfig is not going to
> processed. I've added:
>
> http://jira.codehaus.org/browse/PLX-266
>
> As this would be generally useful. There are some issues related to
> the component descriptor creator (CDC) for default configuration
> values as well. So, short answer right now with 2.0.4 it's not
> possible. If you're using trunk and you're desperate I can do
> something.
>
>> Thanks,
>>
>> --jason
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>
>
> Jason van Zyl
> jason@maven.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Using plexus to inject custom objects (and inject their parameters)?
Posted by Jason van Zyl <ja...@maven.org>.
On 3 Sep 06, at 8:57 PM 3 Sep 06, Jason Dillon wrote:
> Hi, I asked about this in #maven a while ago, but I forgot what the
> answer was.
>
> How can I configure plexus to inject custom objects into my mojo,
> and have plexus inject parameters into that object?
>
> For example, say I have:
>
> <snip>
> public class ConntectionConfig
> {
> /**
> * The port number to connect to the server..
> *
> * @parameter expression="${port}" default-value="1099"
> */
> public int port = -1;
>
> /**
> * The username to authenticate with.
> *
> * @parameter expression="${username}" default-value="system"
> */
> public String username = null;
>
> /**
> * The password to authenticate with.
> *
> * @parameter expression="${password}" default-value="manager"
> */
> public String password = null;
> }
> </snip>
>
> And a mojo like:
>
> <snip>
> /**
> * @goal test
> */
> public class TestMojo
> extends ...
> {
> /**
> * Connection configuration
> *
> * @parameter
> */
> protected ConntectionConfig connection = null;
> }
> </snip>
>
> I'd like to be able to:
>
> mvn whatever:test -Dusername=foo
>
> Which will create a new ConnectionConfig, inject username from $
> {username} and then initialize the other fields to to their default-
> values.
>
> I tried briefly, using @plexus.component for ConnectionConfig, and
> then @component for the connection parameter... but it did not
> inject anything into the ConnectionConfig object. If I specify
> something like:
>
> <configuration>
> <connection>
> <username>foo</username>
> </connection>
> </configuration>
>
> Then username does get set to foo, but the others are left as nulls.
>
> I really need a better way to share configuration and logic among
> mojo's... inheritance is not cutting it, as some mojos end up with
> more than they really need, and I'm forced to create a bunch of
> intermediate abstract classes to organize which mojos need what.
>
> Is this possible? And if so, can someone point me at a simple
> example?
>
The configuration model for a mojo is not inspected for annotations
what what you have above for the ConnectionConfig is not going to
processed. I've added:
http://jira.codehaus.org/browse/PLX-266
As this would be generally useful. There are some issues related to
the component descriptor creator (CDC) for default configuration
values as well. So, short answer right now with 2.0.4 it's not
possible. If you're using trunk and you're desperate I can do something.
> Thanks,
>
> --jason
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
Jason van Zyl
jason@maven.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org