Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created June 8, 2014 18:50
Show Gist options
  • Save Romain-P/2f2be677ed4d222570e1 to your computer and use it in GitHub Desktop.
Save Romain-P/2f2be677ed4d222570e1 to your computer and use it in GitHub Desktop.
plugin manager
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 List<HeaterActivator> instances;
private AbstractModule module;
public PluginManager() {
this.instances = new ArrayList<>();
}
public PluginManager initialize() {
//TODO: insert modules main class
buildModule();
return this;
}
private void buildModule() {
this.module = 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 AbstractModule getModule() {
return this.module;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment