Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sisu-users] Maven Cli -> Plexus -> Sisu Woes

Stuart,

Thank you so much for the help!  Your solution was spot on.  I am not sure why the context classloader would change over the lifetime of the akka actor, but caching it, as you suggested, seems to do the trick!  Thanks again for the insight!

Kindest Regards,
jm  


---------

Hello,

I am attempting to run maven via maven cli and am running into a problem that I believe may be related to plexus/sisu.  I am running maven cli via an akka actor, reinstantiating maven cli each time a message is received and processed.  What I have found is that this works 80% of the time.  The other 20%, MavenCli will fail with 

org.apache.maven.cli.MavenCli - Error executing Maven.
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
      role: org.apache.maven.eventspy.internal.EventSpyDispatcher
  roleHint:
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:264)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:252)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:246)
        at org.apache.maven.cli.MavenCli.container(MavenCli.java:420)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:208)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)

I have been going through this code and eventually found a means to turn on sisu debugging.  What I noticed was that the run with maven cli that succeeds will have ~213 implicit & explicit bindings.  The run that fails will have only ~18 explicit bindings.  Sure enough the larger list has EventSpyDispatcher while the smaller list does not.    

My questions are:

1) what triggers plexus/sisu to scan for these bindings and

Whenever MavenCLI constructs the DefaultPlexusContainer it will look for any plexus.xml / components.xml on the classpath defined by the “classWorld” in the cliRequest. The EventSpyDispatcher component is defined in the components.xml from maven-core. Unless specified otherwise, the “classWorld” in the cliRequest is based on the current thread’s context classloader: Thread.currentThread().getContextClassLoader() - which is initially set to the application classpath and will therefore contain the maven-core jar. However, if another piece of code has reset the context classloader between requests then you could end up with a “classWorld” that doesn’t contain maven-core in which case it would then fail. The solution for this would be to set the “classWorld” explicitly in the request and either save the initial context classloader, or use the classloader of your class that’s calling MavenCLI:

// save this somewhere
ClassWorld myClassWorld = new ClassWorld( "plexus.core", getClass().getClassLoader() ); // or Thread.currentThread().getContextClassLoader() if you know it’s correct at this point

mavenCLI.doMain( new CliRequest( args, myClassWorld ) );
// …etc...
mavenCLI.doMain( new CliRequest( args, myClassWorld ) );

can I manually kick this off to ensure that I am not losing the bindings

Scanning for plexus.xml / components.xml is done whenever the DefaultPlexusContainer is constructed, no caching is involved and you don’t need to manually kick it off.

 (I noticed some caching in the sisu code and am wondering if I am doing something that is invalidating the cache but not triggering this binding scan)

MavenCLI disposes of the container after each request and constructs a new one each time, which invalidates any caches relating to bindings. 

2) what might be causing this akka actor to discover different bindings on one run vs. another when the classpath has not changed

I suspect the thread context classloader is different for the failing runs for some reason (whether it’s due to something else resetting it, or it’s a different thread which happens to have a different context classloader)

Thank you so much for any help you may be able to provide as this issue has been quite the challenge to debug.

Kindest Regards,
jm
_______________________________________________
sisu-users mailing list
sisu-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/sisu-users

_______________________________________________ sisu-users mailing list sisu-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/sisu-users

Back to the top