Hi, I got no response, but I did some more research. Debugging which Classloader Grapes uses, I get this chain:
groovy.lang.GroovyClassLoader.InnerLoader@aas2d21 <- Grape adds URL to this one groovy.lang.GroovyClassLoader@dc7df28 <- Groovysh knows only this one sun.misc.Launcher$AppClassLoader@1b28cdfa sun.misc.Launcher$ExtClassLoader@bef2d72 Since it seems that it is generally impossible to traverse the classloader hierarchy downwards, I tried instead to make Grapes add the new URLs to the same Classloader that Groovysh sees, which seems like the "main" GroovyClassloader. This is not difficult to achieve: https://github.com/tkruse/incubator-groovy/commit/000968c8 As a result, I could make my use-case work, in this branch: https://github.com/tkruse/incubator-groovy/tree/groovysh-grab Example: groovy:000> :grab 'joda-time:joda-time:2.8.2' ===> null groovy:000> import org.j<tab> jcp. jdom. jetbrains. joda. jsoup. junit. groovy:000> import org.j Hooray, it there is (joda). However, this required tampering with the classloaders, in https://github.com/tkruse/incubator-groovy/commit/000968c8 Does anyone here know enough about Grapes and classloaders to see big problems with this solution? Could this be merged? regards, Thibault On Tue, Aug 11, 2015 at 12:15 AM, Thibault Kruse <[email protected]> wrote: > Hi, > > I was thinking about allowing tab completion for classes loaded by > Grapes. However I struggle to > programmatically find out what jars Grape has loaded so far. I believe > this is all about classloaders, > and I know very little about them. > > I believe the GrapeIvy class adds URLs to a classloader, and all I > would need to do is to query that classloader in PackageHelperImpl. > > In PackageHelperImpl the classloader hierarchy is moved upwards > starting with Thread.currentThread().contextClassLoader, but it seems > that moving up that hierarchy, I do not meet the same classloader that > GrapeIvy uses. > > So is there any nice way to find that classloader? > > regards, > Thibault
