Both that and trying to simply get the Class<T>.  After some investigation,
I made a table with the below  code:


matchR,matchT,loadclass,.lookup(),  realm
...... ......  ..!Ex! , ........  for realm plexus.core
PARENT ......  ..!Ex! , ........  for realm
coreExtension>io.takari.polyglot:polyglot-ruby:0.4.7
...... ......  ..!Ex! , ........  for realm maven.ext
...... ......  ..!Ex! , ........  for realm maven.api
...... ......  ..!Ex! , ........  for realm
extension>org.torquebox.mojo:mavengem-wagon:1.0.3
...... ......  ..!Ex! , ........  for realm
project>org.jruby:jruby-stdlib:9.4.0.0-SNAPSHOT
...... ......  Loaded,  null....  for realm
extension>org.apache.felix:maven-bundle-plugin:4.2.1
...... ......  ..!Ex! , ........  for realm
project>org.jruby:jruby-complete:9.4.0.0-SNAPSHOT
...... ......  ..!Ex! , ........  for realm
plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.0
...... THREAD  Loaded,  Instance  for realm
plugin>io.takari.polyglot:polyglot-maven-plugin:0.4.7


def test_realms(ctx)
ccl = java.lang.Thread.currentThread().getContextClassLoader()
parent = JRuby.runtime.jruby_class_loader.parent
ctx.session.container.class_world.realms.each do |realm|
results = []
print(if realm == parent then "PARENT " else "...... " end)
print(if realm == ccl then "THREAD " else "...... " end)
begin
clz =
realm.load_class("org.apache.maven.shared.dependency.graph.DependencyGraphBuilder")
print " Loaded, "
ctx.session.container.lookup(clz)
print " Instance "
rescue java.lang.ClassNotFoundException =>e
print " ..!Ex! , ........ "
rescue
Java::OrgCodehausPlexusComponentRepositoryException::ComponentLookupException
=>e
print " null.... "
end
puts " for realm #{realm.id}"
end
end

The interesting thing I notice here is that the parent classloader of the
ruby plugin is the original core extension. Would this be a bug for the
polyglot plugin itself? ie. should it transition the parent classloader to
the thread class loader?







On Wed, Nov 23, 2022 at 2:58 AM Romain Manni-Bucau <[email protected]>
wrote:

> Do you mean the container.lookup fails?
> Normally, with the metadata in the jar, the default impl (
>
> https://github.com/apache/maven-dependency-tree/blob/master/src/main/java/org/apache/maven/shared/dependency/graph/internal/DefaultDependencyGraphBuilder.java
> )
> should be returned.
>
> If not maybe ensure the ruby plugin does not ignore the plugin dependencies
> with a custom classloader.
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://rmannibucau.metawerx.net/> | Old Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> <
> https://www.packtpub.com/application-development/java-ee-8-high-performance
> >
>
>
> Le mer. 23 nov. 2022 à 02:10, Patrick Plenefisch <[email protected]> a
> écrit :
>
> > Getting the DependencyGraphBuilder to be on the classpath is turning out
> > trickier than anticipated. I added both normal dependencies, and as a
> > dependency inside the plugin, but neither seems to be resolved. Do I have
> > to manually resolve this dependency inside the mojo?
> >
> > <plugin>
> > ...
> >         <dependencies>
> >           <dependency>
> >             <groupId>org.apache.maven.shared</groupId>
> >             <artifactId>maven-dependency-tree</artifactId>
> >             <version>3.2.1</version>
> >           </dependency>
> >         </dependencies>
> >       </plugin>
> >
> >
> >
> >
> >
> > On Tue, Nov 22, 2022 at 10:49 AM Patrick Plenefisch <[email protected]
> >
> > wrote:
> >
> > > irb(#<Maven::Polyglot::Parser:0x62c6db99>):002:0> ctx.session.container
> > > => #<Java::OrgCodehausPlexus::DefaultPlexusContainer:0x3efe7086>
> > >
> > > Well, would you look at that! Literal hours of staring at the javadoc
> > over
> > > multiple days and yet somehow I missed that. Though to be fair I did
> type
> > > .context and search the javadoc and code for "context" before I
> realized
> > > you said "container". Though it is deprecated? Good enough for me
> though.
> > > Thanks!
> > >
> > > Thanks,
> > > Patrick
> > >
> > > On Tue, Nov 22, 2022 at 10:33 AM Romain Manni-Bucau <
> > [email protected]>
> > > wrote:
> > >
> > >> *ctx.session.container* ?
> > >>
> > >>
> > >> Le mar. 22 nov. 2022 à 16:23, Patrick Plenefisch <[email protected]
> >
> > a
> > >> écrit :
> > >>
> > >> > No, how would I do that with the released version of Mojo today? I
> > know
> > >> the
> > >> > standard version of injecting for java uses a field and an
> annotation,
> > >> but
> > >> > I'm not writing java, and I don't know how to adapt that to my
> > polyglot
> > >> > pom-inline code:
> > >> > https://github.com/jruby/jruby/blob/master/lib/pom.rb#L209
> > >> >
> > >> > Patrick
> > >> >
> > >> > On Tue, Nov 22, 2022 at 10:13 AM Romain Manni-Bucau <
> > >> [email protected]
> > >> > >
> > >> > wrote:
> > >> >
> > >> > > Hi Patrick,
> > >> > >
> > >> > > Did you try injecting PlexusContainer?
> > >> > > It is not the most sexy and modern way to do it but it fits quite
> > well
> > >> > the
> > >> > > scripting language since the container enables to lookup anything,
> > it
> > >> is
> > >> > > just a matter of injecting it in the mojo then forwarding it to
> the
> > >> > script.
> > >> > >
> > >> > > Side note: I assume a more modern solution is to inject the sisu
> > >> > > BeanLocator but its package is not exposed to mojo (intentionally)
> > so
> > >> it
> > >> > > can be trickier to play with ClassRealms to get it.
> > >> > >
> > >> > > I would also avoid the generation trick since it will also have
> > >> pitfalls
> > >> > > (leaks, manual registration, cache) and is not simpler.
> > >> > >
> > >> > > Hope it helps a bit.
> > >> > >
> > >> > > Romain Manni-Bucau
> > >> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > >> > > <https://rmannibucau.metawerx.net/> | Old Blog
> > >> > > <http://rmannibucau.wordpress.com> | Github <
> > >> > > https://github.com/rmannibucau> |
> > >> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> > >> > > <
> > >> > >
> > >> >
> > >>
> >
> https://www.packtpub.com/application-development/java-ee-8-high-performance
> > >> > > >
> > >> > >
> > >> > >
> > >> > > Le mar. 22 nov. 2022 à 16:04, Patrick Plenefisch <
> > [email protected]>
> > >> a
> > >> > > écrit :
> > >> > >
> > >> > > > Hi,
> > >> > > > How can I query a specific dependency's *resolved* transitive
> > >> > > dependencies
> > >> > > > inside a class executed by a mojo? I have access to session and
> > >> > project,
> > >> > > > and that's it.
> > >> > > > I looked at DependencyGraphBuilder and the underlying
> > >> > > > ProjectDependenciesResolver, but those seem to be injected.
> While
> > I
> > >> can
> > >> > > > generate a class at runtime, I don't see how to access the
> > injector
> > >> > even
> > >> > > if
> > >> > > > I have a class
> > >> > > >
> > >> > > > The environment I'm running inside is JRuby inside
> > >> > > >
> > >> > > >
> > >> > >
> > >> >
> > >>
> >
> https://github.com/takari/polyglot-maven/blob/master/polyglot-maven-plugin/src/main/java/org/sonatype/maven/polyglot/plugin/ExecuteMojo.java
> > >> > > > which is why I can't just use an @Inject annotation. But, being
> > >> JRuby,
> > >> > I
> > >> > > > can easily generate classes at runtime if necessary.
> > >> > > >
> > >> > > > How can I go about this?
> > >> > > >
> > >> > > > Thanks,
> > >> > > >
> > >> > > > Patrick
> > >> > > >
> > >> > >
> > >> >
> > >>
> > >
> >
>

Reply via email to