You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rinku <ra...@gmail.com> on 2006/05/20 07:40:04 UTC

How to configure a Plexus Component from pom.xml

Hi,

Here's my use case. I have created:
1)  a Plexus Database Component, which expects some configuration bits 
to run (connection url, username, password etc)
2)  a Maven Database Plugin which uses the DatabaseComponent to allow a 
Maven Project to setup a database instance.

So far so good; but now I am not sure how to configure the Plexus 
component I created in (1) from pom.xml? I guess I will have to push the 
configuration via the Database Plugin's <configuration> element in 
pom.xml - but I don't know how? Appreciate any pointers.

TIA!

Cheers,
Rahul 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to configure a Plexus Component from pom.xml

Posted by Rinku <ra...@gmail.com>.
Hi Brett,

I tried this and I am getting an instantiation error (attached below). I 
am using the last releases for Plexus Container  (1.0-alpha-9) and 
Plexus Utils (1.2)

a) Here's my Mojo source: 
http://www.rafb.net/paste/results/iZnfJW63.html

b) the unit test conf for the Mojo: 
http://rafb.net/paste/results/yZAo0s88.html

c) and the unit test source: 
http://rafb.net/paste/results/YejPjK67.html

Cheers,

Rahul


---------------------------- snip -------------------------------

org.codehaus.plexus.component.configurator.ComponentConfigurationException: 
Class 'org.codehaus.plexus.util.xml.Xpp3Dom' cannot be instantiated
 at 
org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.instantiateObject(AbstractConfigurationConverter.java:121)
 at 
org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter.fromConfiguration(ObjectWithFieldsConverter.java:88)
 at 
org.codehaus.plexus.component.configurator.converters.ComponentValueSetter.configure(ComponentValueSetter.java:247)
 at 
org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter.processConfiguration(ObjectWithFieldsConverter.java:137)
 at 
org.codehaus.plexus.component.configurator.BasicComponentConfigurator.configureComponent(BasicComponentConfigurator.java:56)
 at 
org.codehaus.plexus.component.configurator.AbstractComponentConfigurator.configureComponent(AbstractComponentConfigurator.java:54)
 at 
org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:177)
 at 
org.codehaus.plexus.m2.PlexusGreeterMojoTest.testMojoLookup(PlexusGreeterMojoTest.java:42)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at junit.framework.TestCase.runTest(TestCase.java:154)
 at junit.framework.TestCase.runBare(TestCase.java:127)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.framework.TestSuite.runTest(TestSuite.java:208)
 at junit.framework.TestSuite.run(TestSuite.java:203)
 at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
 at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:457)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:670)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.InstantiationException: 
org.codehaus.plexus.util.xml.Xpp3Dom
 at java.lang.Class.newInstance0(Class.java:335)
 at java.lang.Class.newInstance(Class.java:303)
 at 
org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.instantiateObject(AbstractConfigurationConverter.java:111)
 ... 25 more

---------------------------- snip -------------------------------


----- Original Message ----- 
From: "Brett Porter" <br...@gmail.com>
To: "Maven Users List" <us...@maven.apache.org>
Sent: Sunday, May 21, 2006 7:01 AM
Subject: Re: How to configure a Plexus Component from pom.xml


there's a converter for (1), IIRC. So:

<configuration>
  <foo>
    <bar>
      <baz name="..." />
    </bar>
  </foo>
</configuration>

Should work with:
/** @parameter */
private Xpp3Dom foo;

(2) Not beyond the above, no.

On 20/05/06, Rinku <ra...@gmail.com> wrote:
> Hi Brett,
>
> I still have a few questions on your suggestion:
>
> 1) How can I pass and set value to an Xpp3Dom field in a Mojo? Is that 
> a
> CData section in the Mojo <configuration>. M2/Plexus currently expects
> the class that implements and maps to Mojo's <configuration> to be a
> POJO with no-arg construction. I am not sure if this will map to
> Xpp3Dom.
>
> 2) I am assuming this is not yet available in Mojo API yet, right?
>
> Thanks again,
>
> Rahul
>
>
>
> ----- Original Message -----
> From: "Brett Porter" <br...@gmail.com>
> To: "Maven Users List" <us...@maven.apache.org>
> Sent: Sunday, May 21, 2006 3:46 AM
> Subject: Re: How to configure a Plexus Component from pom.xml
>
>
> I think if you want to dynamically control the implementation or
> configuration of a component from the POM, you'll need to pass the
> configuration in to the mojo as a separate field (Xpp3Dom), then setup
> the mojo to get the container instance and look it up/configure it
> manually.
>
> This would be a good enhancement to the mojo API though, eg:
> /** @component configuration="databaseConfig" */
> Component component;
>
> /** @parameter */
> Xpp3Dom databaseConfig;
>
> - Brett
>
> On 19/05/06, Rinku <ra...@gmail.com> wrote:
> > Hi,
> >
> > Here's my use case. I have created:
> > 1)  a Plexus Database Component, which expects some configuration 
> > bits
> > to run (connection url, username, password etc)
> > 2)  a Maven Database Plugin which uses the DatabaseComponent to 
> > allow
> > a
> > Maven Project to setup a database instance.
> >
> > So far so good; but now I am not sure how to configure the Plexus
> > component I created in (1) from pom.xml? I guess I will have to push
> > the
> > configuration via the Database Plugin's <configuration> element in
> > pom.xml - but I don't know how? Appreciate any pointers.
> >
> > TIA!
> >
> > Cheers,
> > Rahul
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
> --
> Apache Maven - http://maven.apache.org
> "Better Builds with Maven" book - http://library.mergere.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Apache Maven - http://maven.apache.org
"Better Builds with Maven" book - http://library.mergere.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to configure a Plexus Component from pom.xml

Posted by Brett Porter <br...@gmail.com>.
there's a converter for (1), IIRC. So:

<configuration>
  <foo>
    <bar>
      <baz name="..." />
    </bar>
  </foo>
</configuration>

Should work with:
/** @parameter */
private Xpp3Dom foo;

(2) Not beyond the above, no.

On 20/05/06, Rinku <ra...@gmail.com> wrote:
> Hi Brett,
>
> I still have a few questions on your suggestion:
>
> 1) How can I pass and set value to an Xpp3Dom field in a Mojo? Is that a
> CData section in the Mojo <configuration>. M2/Plexus currently expects
> the class that implements and maps to Mojo's <configuration> to be a
> POJO with no-arg construction. I am not sure if this will map to
> Xpp3Dom.
>
> 2) I am assuming this is not yet available in Mojo API yet, right?
>
> Thanks again,
>
> Rahul
>
>
>
> ----- Original Message -----
> From: "Brett Porter" <br...@gmail.com>
> To: "Maven Users List" <us...@maven.apache.org>
> Sent: Sunday, May 21, 2006 3:46 AM
> Subject: Re: How to configure a Plexus Component from pom.xml
>
>
> I think if you want to dynamically control the implementation or
> configuration of a component from the POM, you'll need to pass the
> configuration in to the mojo as a separate field (Xpp3Dom), then setup
> the mojo to get the container instance and look it up/configure it
> manually.
>
> This would be a good enhancement to the mojo API though, eg:
> /** @component configuration="databaseConfig" */
> Component component;
>
> /** @parameter */
> Xpp3Dom databaseConfig;
>
> - Brett
>
> On 19/05/06, Rinku <ra...@gmail.com> wrote:
> > Hi,
> >
> > Here's my use case. I have created:
> > 1)  a Plexus Database Component, which expects some configuration bits
> > to run (connection url, username, password etc)
> > 2)  a Maven Database Plugin which uses the DatabaseComponent to allow
> > a
> > Maven Project to setup a database instance.
> >
> > So far so good; but now I am not sure how to configure the Plexus
> > component I created in (1) from pom.xml? I guess I will have to push
> > the
> > configuration via the Database Plugin's <configuration> element in
> > pom.xml - but I don't know how? Appreciate any pointers.
> >
> > TIA!
> >
> > Cheers,
> > Rahul
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>
> --
> Apache Maven - http://maven.apache.org
> "Better Builds with Maven" book - http://library.mergere.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Apache Maven - http://maven.apache.org
"Better Builds with Maven" book - http://library.mergere.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to configure a Plexus Component from pom.xml

Posted by Rinku <ra...@gmail.com>.
Hi Brett,

I still have a few questions on your suggestion:

1) How can I pass and set value to an Xpp3Dom field in a Mojo? Is that a 
CData section in the Mojo <configuration>. M2/Plexus currently expects 
the class that implements and maps to Mojo's <configuration> to be a 
POJO with no-arg construction. I am not sure if this will map to 
Xpp3Dom.

2) I am assuming this is not yet available in Mojo API yet, right?

Thanks again,

Rahul



----- Original Message ----- 
From: "Brett Porter" <br...@gmail.com>
To: "Maven Users List" <us...@maven.apache.org>
Sent: Sunday, May 21, 2006 3:46 AM
Subject: Re: How to configure a Plexus Component from pom.xml


I think if you want to dynamically control the implementation or
configuration of a component from the POM, you'll need to pass the
configuration in to the mojo as a separate field (Xpp3Dom), then setup
the mojo to get the container instance and look it up/configure it
manually.

This would be a good enhancement to the mojo API though, eg:
/** @component configuration="databaseConfig" */
Component component;

/** @parameter */
Xpp3Dom databaseConfig;

- Brett

On 19/05/06, Rinku <ra...@gmail.com> wrote:
> Hi,
>
> Here's my use case. I have created:
> 1)  a Plexus Database Component, which expects some configuration bits
> to run (connection url, username, password etc)
> 2)  a Maven Database Plugin which uses the DatabaseComponent to allow 
> a
> Maven Project to setup a database instance.
>
> So far so good; but now I am not sure how to configure the Plexus
> component I created in (1) from pom.xml? I guess I will have to push 
> the
> configuration via the Database Plugin's <configuration> element in
> pom.xml - but I don't know how? Appreciate any pointers.
>
> TIA!
>
> Cheers,
> Rahul
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Apache Maven - http://maven.apache.org
"Better Builds with Maven" book - http://library.mergere.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to configure a Plexus Component from pom.xml

Posted by Brett Porter <br...@gmail.com>.
I think if you want to dynamically control the implementation or
configuration of a component from the POM, you'll need to pass the
configuration in to the mojo as a separate field (Xpp3Dom), then setup
the mojo to get the container instance and look it up/configure it
manually.

This would be a good enhancement to the mojo API though, eg:
/** @component configuration="databaseConfig" */
Component component;

/** @parameter */
Xpp3Dom databaseConfig;

- Brett

On 19/05/06, Rinku <ra...@gmail.com> wrote:
> Hi,
>
> Here's my use case. I have created:
> 1)  a Plexus Database Component, which expects some configuration bits
> to run (connection url, username, password etc)
> 2)  a Maven Database Plugin which uses the DatabaseComponent to allow a
> Maven Project to setup a database instance.
>
> So far so good; but now I am not sure how to configure the Plexus
> component I created in (1) from pom.xml? I guess I will have to push the
> configuration via the Database Plugin's <configuration> element in
> pom.xml - but I don't know how? Appreciate any pointers.
>
> TIA!
>
> Cheers,
> Rahul
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Apache Maven - http://maven.apache.org
"Better Builds with Maven" book - http://library.mergere.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org