This message was deleted.
# plugin-development
s
This message was deleted.
e
a plugin can have any number of IDs
🤔 1
s
Ahh, that is interesting. Can I still query them at runtime for a given project? I'm creating a report and I'd love to be able to show which plugins have been applied. Most devs will only understand IDs though and not class names.
e
there is an internal
PluginRegistry
that keeps track of which plugins Gradle has seen so far, but otherwise no
a plugin can be directly applied by class and not ID, a plugin may have no IDs (thus only applicable by class), there may be multiple plugin IDs pointed at the same implementation class in any part of the classpath
s
It looks like
org.gradle.api.internal.plugins.PluginRegistry
is under the
.internal.
package, but how do I programatically get an instance of it? I see a constructor, but not sure how I'd get the constructor args for
public DefaultPluginRegistry(PluginInspector pluginInspector, ClassLoaderScope classLoaderScope)
v
To get the id -> class mapping, you can simply list all
META-INF/gradle-plugins/...properties
files and read them, then you have the id -> class mappings and can build a class -> possible ids mapping. But as @ephemient said, it could also be that a plugin has no ID but is only applied by class and you also don't know in which way the plugin was actually applied.
s
Okay, that should all be available on the classpath, and therefore accessible via the classloader? Interesting, okay, can 👀
v
Yes, it should
e
you have to make sure to include parent classloaders too when you do that scan
it is also entirely possible for a plugin marker to be published which points to a plugin defined elsewhere, which means there are potentially usable IDs for plugin implementations in your classpath that don't exist in your classpath
so listing "all IDs that might cause this plugin to be loaded" is not really possible. "all IDs within this current build" is doable though
v
Yes, that's basically then the same as mentioned above, not having an ID at all. 🙂
Do you really need to look at parent class loaders manually?
e
there's no public way of enumerating all resources in a classloader
if you just go up to the nearest URLClassLoader and take its URLs, that's insufficient because it doesn't include parents
s
Yeah... all the solutions require you to walk the JAR file via inspecting it as a ZIP file. I think I'll end up doing the hard-coded list. It's only like 10 things, just wanted to make it dynamic.
v
Hm, I always forget I just wish there was such an api 😄
🟰 1
e
originally ClassLoader worked for applets too, loading resources from some ordinary HTTP server, which I think is why it isn't enumerable
but basically none of that works anymore so it's just an annoying API now
s
At first pass it seems like something that should be part of Gradle... but I guess it is not because that
META-INF/gradle-plugins/my-plugin.properties
will exist, and it will refer to the fully qualified plugin class. Therefore they are explicitly able to look it up from the classloader. 🤔 So maybe there really isn't a need.
e
yes Gradle only ever needs resolve an ID to a class, which is easy
v
You could brute-force all possible plugin IDs 😄
😨 1
e
ah yes, all ℵ₀ of them 😂
😱 1
s
Instead... Gradle could keep a registry that could keep the id/class mapping after each was applied. It wouldn't be guaranteed to be correct until after configuration though. Since gradle is doing the lookup, it could be nice enough to expose what those were 🤔
v
Well, Gradle is not interested in it and most post probably noone else should either I guess. 😄
But feel free to open a feature request or pull request, maybe the Gradle folks are open to it.
🆗 1
🤷‍♂️