Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Forked from Romain-P/PluginManager.java
Last active August 29, 2015 14:02
Show Gist options
  • Save volgar1x/503818f318383f150b24 to your computer and use it in GitHub Desktop.
Save volgar1x/503818f318383f150b24 to your computer and use it in GitHub Desktop.
package org.heater.core.plugin;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.heater.api.HeaterActivator;
import java.util.ArrayList;
import java.util.List;
public class PluginManager {
private final List<HeaterActivator> instances;
private Module cache;
public PluginManager() {
this.instances = new ArrayList<>();
}
public PluginManager initialize() {
//TODO: insert modules main class
if (cache == null) {
cache = buildModule();
}
return this;
}
private Module buildModule() {
return new AbstractModule() {
@Override
protected void configure() {
Multibinder<HeaterActivator> binder = Multibinder.newSetBinder(binder(), HeaterActivator.class);
for(HeaterActivator instance: instances) {
binder.addBinding().toInstance(instance);
install(instance.pluginModule());
}
}
};
}
public Module getModule() {
if (cache == null) {
throw new IllegalStateException("please initialize first");
}
return this.module;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment