Check if a Plugin main class is a Guice module
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 959
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Description
At the moment in order to create your own bindings, you have to create a child injector. This isn't ideal (due to bugs such as https://github.com/google/guice/issues/973 - injecting an Injector will inject the parent, not the child that the module was bound with).
I believe the logic in JavaPluginLoader#loadPlugin should be something similar to:
Class<?> mainClass = ((JavaVelocityPluginDescription) description).getMainClass();
Object instance;
if (Module.class.isAssignableFrom(mainClass)) {
instance = mainClass.newInstance();
Module[] tmp = new Module[modules.length + 1];
System.arraycopy(modules, 0, tmp, 0, modules.length);
tmp[modules.length] = (Module) instance;
Guice.createInjector(tmp);
} else {
Injector injector = Guice.createInjector(modules);
instance = injector.getInstance(mainClass);
}
if (instance == null) {
throw new IllegalStateException("Got nothing from injector for plugin " + description.getId());
}
((VelocityPluginContainer) container).setInstance(instance);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java at JavaPluginLoader#loadPlugin, then review the linked Guice issue for the injector behavior. Check how plugin main classes and existing modules are loaded. Done means a main class that is a Guice Module can provide bindings without a child injector while regular plugin loading still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100