2019-06-25 08:36:57 +02:00
|
|
|
package sonia.scm.lifecycle;
|
2019-05-09 10:36:27 +02:00
|
|
|
|
|
|
|
|
import com.google.inject.AbstractModule;
|
|
|
|
|
import com.google.inject.throwingproviders.ThrowingProviderBinder;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-05-14 14:12:08 +02:00
|
|
|
import sonia.scm.ClassOverrides;
|
|
|
|
|
import sonia.scm.SCMContext;
|
|
|
|
|
import sonia.scm.SCMContextProvider;
|
2019-05-09 10:36:27 +02:00
|
|
|
import sonia.scm.io.DefaultFileSystem;
|
|
|
|
|
import sonia.scm.io.FileSystem;
|
2019-05-15 15:05:35 +02:00
|
|
|
import sonia.scm.plugin.PluginLoader;
|
2019-05-10 08:06:36 +02:00
|
|
|
import sonia.scm.repository.RepositoryLocationResolver;
|
|
|
|
|
import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
|
2019-05-14 11:54:25 +02:00
|
|
|
import sonia.scm.security.CipherHandler;
|
|
|
|
|
import sonia.scm.security.CipherUtil;
|
2019-05-09 10:36:27 +02:00
|
|
|
import sonia.scm.security.DefaultKeyGenerator;
|
|
|
|
|
import sonia.scm.security.KeyGenerator;
|
|
|
|
|
import sonia.scm.store.BlobStoreFactory;
|
|
|
|
|
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
|
|
|
|
import sonia.scm.store.ConfigurationStoreFactory;
|
|
|
|
|
import sonia.scm.store.DataStoreFactory;
|
|
|
|
|
import sonia.scm.store.FileBlobStoreFactory;
|
|
|
|
|
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
|
|
|
|
import sonia.scm.store.JAXBConfigurationStoreFactory;
|
|
|
|
|
import sonia.scm.store.JAXBDataStoreFactory;
|
|
|
|
|
|
|
|
|
|
public class BootstrapModule extends AbstractModule {
|
|
|
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(BootstrapModule.class);
|
|
|
|
|
|
|
|
|
|
private final ClassOverrides overrides;
|
2019-05-15 15:05:35 +02:00
|
|
|
private final PluginLoader pluginLoader;
|
2019-05-09 10:36:27 +02:00
|
|
|
|
2019-05-23 15:45:58 +02:00
|
|
|
BootstrapModule(PluginLoader pluginLoader) {
|
2019-05-14 11:19:45 +02:00
|
|
|
this.overrides = ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
|
2019-05-15 15:05:35 +02:00
|
|
|
this.pluginLoader = pluginLoader;
|
2019-05-09 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void configure() {
|
|
|
|
|
install(ThrowingProviderBinder.forModule(this));
|
|
|
|
|
|
|
|
|
|
SCMContextProvider context = SCMContext.getContext();
|
|
|
|
|
|
|
|
|
|
bind(SCMContextProvider.class).toInstance(context);
|
|
|
|
|
|
|
|
|
|
bind(KeyGenerator.class).to(DefaultKeyGenerator.class);
|
|
|
|
|
|
2019-05-10 08:06:36 +02:00
|
|
|
bind(RepositoryLocationResolver.class).to(PathBasedRepositoryLocationResolver.class);
|
|
|
|
|
|
2019-05-09 10:36:27 +02:00
|
|
|
bind(FileSystem.class, DefaultFileSystem.class);
|
|
|
|
|
|
2019-05-14 11:54:25 +02:00
|
|
|
// note CipherUtil uses an other generator
|
|
|
|
|
bind(CipherHandler.class).toInstance(CipherUtil.getInstance().getCipherHandler());
|
2019-05-09 10:36:27 +02:00
|
|
|
|
|
|
|
|
// bind core
|
|
|
|
|
bind(ConfigurationStoreFactory.class, JAXBConfigurationStoreFactory.class);
|
|
|
|
|
bind(ConfigurationEntryStoreFactory.class, JAXBConfigurationEntryStoreFactory.class);
|
|
|
|
|
bind(DataStoreFactory.class, JAXBDataStoreFactory.class);
|
|
|
|
|
bind(BlobStoreFactory.class, FileBlobStoreFactory.class);
|
2019-05-15 15:05:35 +02:00
|
|
|
bind(PluginLoader.class).toInstance(pluginLoader);
|
2019-05-09 10:36:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T> void bind(Class<T> clazz, Class<? extends T> defaultImplementation) {
|
|
|
|
|
Class<? extends T> implementation = find(clazz, defaultImplementation);
|
|
|
|
|
LOG.debug("bind {} to {}", clazz, implementation);
|
|
|
|
|
bind(clazz).to(implementation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T> Class<? extends T> find(Class<T> clazz, Class<? extends T> defaultImplementation) {
|
|
|
|
|
Class<? extends T> implementation = overrides.getOverride(clazz);
|
|
|
|
|
|
|
|
|
|
if (implementation != null) {
|
|
|
|
|
LOG.info("found override {} for {}", implementation, clazz);
|
|
|
|
|
} else {
|
|
|
|
|
implementation = defaultImplementation;
|
|
|
|
|
|
|
|
|
|
LOG.trace(
|
|
|
|
|
"no override available for {}, using default implementation {}",
|
|
|
|
|
clazz, implementation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return implementation;
|
|
|
|
|
}
|
|
|
|
|
}
|