-
-
Save volgar1x/503818f318383f150b24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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