You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Tom Bujok <to...@gmail.com> on 2012/03/06 09:30:29 UTC

AbstractMavenLifecycleParticipant.afterSessionStart method not invoked

Hi guys,

I have implemented an AbstractMavenLifecycleParticipant to customize the standard build behavior a bit.
The declaration of the participant looks like this:

@Component(role = AbstractMavenLifecycleParticipant.class, hint = "testParticipant")
public class TestParticipant extends AbstractMavenLifecycleParticipant
        implements Initializable { 
…
}

I have noticed, however, that the afterSessionStart method is never invoked. I debugged the getLifecycleParticipants method in the DefaultMaven.java class and it looks like an class-loading issue.
Container.lookupList( AbstractMavenLifecycleParticipant.class ) method fetches my participant only when the context class loader is set to project realm's class loader, basically after this stuff is executed:
ClassLoader projectRealm = project.getClassRealm();
Thread.currentThread().setContextClassLoader( projectRealm );

afterSessionStart() method, however, is invoked before the projects are read, so in general, it look like it is impossible to use the "afterSessionStart" method from a plugin defined in a project...
Am I right, or maybe I am missing something? I am willing to provide a patch if you explain what the default behavior should be.

Thanks in advance,
Tom Bujok




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


Re: AbstractMavenLifecycleParticipant.afterSessionStart method not invoked

Posted by Olivier Lamy <ol...@apache.org>.
Agree I have added some documentation here:
http://maven.apache.org/examples/maven-3-lifecycle-extensions.html

Let me know if it's fine.

2012/3/7 Tom Bujok <to...@gmail.com>:
> Exactly, that is the case.
> - afterSessionStart is a maven extension,
> - afterProjectRead is a project extension,
> which in the end is quite confusing…
>
> Tom
>
>
> On Mar 6, 2012, at 11:09 PM, Jeff MAURY wrote:
>
>> It seems quite confusing: Tycho is using this functionality and does not
>> require to be installed in M2_HOME/lib/ext.
>> My understanding is the following:
>> - for afterSessionStart, must be installed in M2_HOME/lib/ext
>> - for afterProjectRead, can be an extension in the POM
>>
>> Jeff
>>
>> On Tue, Mar 6, 2012 at 10:51 PM, Olivier Lamy <ol...@apache.org> wrote:
>>
>>> 2012/3/6 Tom Bujok <to...@gmail.com>:
>>>> Hi guys,
>>>>
>>>> I have implemented an AbstractMavenLifecycleParticipant to customize the
>>> standard build behavior a bit.
>>>> The declaration of the participant looks like this:
>>>>
>>>> @Component(role = AbstractMavenLifecycleParticipant.class, hint =
>>> "testParticipant")
>>>> public class TestParticipant extends AbstractMavenLifecycleParticipant
>>>>       implements Initializable {
>>>> …
>>>> }
>>>>
>>>> I have noticed, however, that the afterSessionStart method is never
>>> invoked. I debugged the getLifecycleParticipants method in the
>>> DefaultMaven.java class and it looks like an class-loading issue.
>>>> Container.lookupList( AbstractMavenLifecycleParticipant.class ) method
>>> fetches my participant only when the context class loader is set to project
>>> realm's class loader, basically after this stuff is executed:
>>>> ClassLoader projectRealm = project.getClassRealm();
>>>> Thread.currentThread().setContextClassLoader( projectRealm );
>>>>
>>>> afterSessionStart() method, however, is invoked before the projects are
>>> read, so in general, it look like it is impossible to use the
>>> "afterSessionStart" method from a plugin defined in a project...
>>>> Am I right, or maybe I am missing something? I am willing to provide a
>>> patch if you explain what the default behavior should be.
>>> AFAIK AbstractMavenLifecycleParticipant are maven extension (i.e.
>>> placed in $M2_HOME/lib/ext/ ) and not project extension.
>>> And btw afterSessionStart is executed before reading project so
>>> "project realm" is unknown at this stage.
>>>>
>>>> Thanks in advance,
>>>> Tom Bujok
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>
>>>
>>>
>>> --
>>> Olivier Lamy
>>> Talend: http://coders.talend.com
>>> http://twitter.com/olamy | http://linkedin.com/in/olamy
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>
>>
>> --
>> Jeff MAURY
>>
>> "Legacy code" often differs from its suggested alternative by actually
>> working and scaling.
>> - Bjarne Stroustrup
>>
>> http://www.jeffmaury.com
>> http://riadiscuss.jeffmaury.com
>> http://www.twitter.com/jeffmaury
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

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


Re: AbstractMavenLifecycleParticipant.afterSessionStart method not invoked

Posted by Tom Bujok <to...@gmail.com>.
Exactly, that is the case.
- afterSessionStart is a maven extension,
- afterProjectRead is a project extension,
which in the end is quite confusing…

Tom


On Mar 6, 2012, at 11:09 PM, Jeff MAURY wrote:

> It seems quite confusing: Tycho is using this functionality and does not
> require to be installed in M2_HOME/lib/ext.
> My understanding is the following:
> - for afterSessionStart, must be installed in M2_HOME/lib/ext
> - for afterProjectRead, can be an extension in the POM
> 
> Jeff
> 
> On Tue, Mar 6, 2012 at 10:51 PM, Olivier Lamy <ol...@apache.org> wrote:
> 
>> 2012/3/6 Tom Bujok <to...@gmail.com>:
>>> Hi guys,
>>> 
>>> I have implemented an AbstractMavenLifecycleParticipant to customize the
>> standard build behavior a bit.
>>> The declaration of the participant looks like this:
>>> 
>>> @Component(role = AbstractMavenLifecycleParticipant.class, hint =
>> "testParticipant")
>>> public class TestParticipant extends AbstractMavenLifecycleParticipant
>>>       implements Initializable {
>>> …
>>> }
>>> 
>>> I have noticed, however, that the afterSessionStart method is never
>> invoked. I debugged the getLifecycleParticipants method in the
>> DefaultMaven.java class and it looks like an class-loading issue.
>>> Container.lookupList( AbstractMavenLifecycleParticipant.class ) method
>> fetches my participant only when the context class loader is set to project
>> realm's class loader, basically after this stuff is executed:
>>> ClassLoader projectRealm = project.getClassRealm();
>>> Thread.currentThread().setContextClassLoader( projectRealm );
>>> 
>>> afterSessionStart() method, however, is invoked before the projects are
>> read, so in general, it look like it is impossible to use the
>> "afterSessionStart" method from a plugin defined in a project...
>>> Am I right, or maybe I am missing something? I am willing to provide a
>> patch if you explain what the default behavior should be.
>> AFAIK AbstractMavenLifecycleParticipant are maven extension (i.e.
>> placed in $M2_HOME/lib/ext/ ) and not project extension.
>> And btw afterSessionStart is executed before reading project so
>> "project realm" is unknown at this stage.
>>> 
>>> Thanks in advance,
>>> Tom Bujok
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>> 
>> 
>> 
>> 
>> --
>> Olivier Lamy
>> Talend: http://coders.talend.com
>> http://twitter.com/olamy | http://linkedin.com/in/olamy
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>> 
>> 
> 
> 
> -- 
> Jeff MAURY
> 
> "Legacy code" often differs from its suggested alternative by actually
> working and scaling.
> - Bjarne Stroustrup
> 
> http://www.jeffmaury.com
> http://riadiscuss.jeffmaury.com
> http://www.twitter.com/jeffmaury


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


Re: AbstractMavenLifecycleParticipant.afterSessionStart method not invoked

Posted by Jeff MAURY <je...@jeffmaury.com>.
It seems quite confusing: Tycho is using this functionality and does not
require to be installed in M2_HOME/lib/ext.
My understanding is the following:
- for afterSessionStart, must be installed in M2_HOME/lib/ext
- for afterProjectRead, can be an extension in the POM

Jeff

On Tue, Mar 6, 2012 at 10:51 PM, Olivier Lamy <ol...@apache.org> wrote:

> 2012/3/6 Tom Bujok <to...@gmail.com>:
> > Hi guys,
> >
> > I have implemented an AbstractMavenLifecycleParticipant to customize the
> standard build behavior a bit.
> > The declaration of the participant looks like this:
> >
> > @Component(role = AbstractMavenLifecycleParticipant.class, hint =
> "testParticipant")
> > public class TestParticipant extends AbstractMavenLifecycleParticipant
> >        implements Initializable {
> > …
> > }
> >
> > I have noticed, however, that the afterSessionStart method is never
> invoked. I debugged the getLifecycleParticipants method in the
> DefaultMaven.java class and it looks like an class-loading issue.
> > Container.lookupList( AbstractMavenLifecycleParticipant.class ) method
> fetches my participant only when the context class loader is set to project
> realm's class loader, basically after this stuff is executed:
> > ClassLoader projectRealm = project.getClassRealm();
> > Thread.currentThread().setContextClassLoader( projectRealm );
> >
> > afterSessionStart() method, however, is invoked before the projects are
> read, so in general, it look like it is impossible to use the
> "afterSessionStart" method from a plugin defined in a project...
> > Am I right, or maybe I am missing something? I am willing to provide a
> patch if you explain what the default behavior should be.
> AFAIK AbstractMavenLifecycleParticipant are maven extension (i.e.
> placed in $M2_HOME/lib/ext/ ) and not project extension.
> And btw afterSessionStart is executed before reading project so
> "project realm" is unknown at this stage.
> >
> > Thanks in advance,
> > Tom Bujok
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
>
>
>
> --
> Olivier Lamy
> Talend: http://coders.talend.com
> http://twitter.com/olamy | http://linkedin.com/in/olamy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Jeff MAURY

"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Re: AbstractMavenLifecycleParticipant.afterSessionStart method not invoked

Posted by Olivier Lamy <ol...@apache.org>.
2012/3/6 Tom Bujok <to...@gmail.com>:
> Hi guys,
>
> I have implemented an AbstractMavenLifecycleParticipant to customize the standard build behavior a bit.
> The declaration of the participant looks like this:
>
> @Component(role = AbstractMavenLifecycleParticipant.class, hint = "testParticipant")
> public class TestParticipant extends AbstractMavenLifecycleParticipant
>        implements Initializable {
> …
> }
>
> I have noticed, however, that the afterSessionStart method is never invoked. I debugged the getLifecycleParticipants method in the DefaultMaven.java class and it looks like an class-loading issue.
> Container.lookupList( AbstractMavenLifecycleParticipant.class ) method fetches my participant only when the context class loader is set to project realm's class loader, basically after this stuff is executed:
> ClassLoader projectRealm = project.getClassRealm();
> Thread.currentThread().setContextClassLoader( projectRealm );
>
> afterSessionStart() method, however, is invoked before the projects are read, so in general, it look like it is impossible to use the "afterSessionStart" method from a plugin defined in a project...
> Am I right, or maybe I am missing something? I am willing to provide a patch if you explain what the default behavior should be.
AFAIK AbstractMavenLifecycleParticipant are maven extension (i.e.
placed in $M2_HOME/lib/ext/ ) and not project extension.
And btw afterSessionStart is executed before reading project so
"project realm" is unknown at this stage.
>
> Thanks in advance,
> Tom Bujok
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>



-- 
Olivier Lamy
Talend: http://coders.talend.com
http://twitter.com/olamy | http://linkedin.com/in/olamy

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