Test module

This commit is contained in:
René Pfeuffer
2020-05-17 18:10:06 +02:00
committed by René Pfeuffer
parent 3a68e5ff2b
commit d8af1ea8d0
2 changed files with 110 additions and 4 deletions

View File

@@ -26,22 +26,23 @@ package sonia.scm.lifecycle.modules;
import com.google.inject.AbstractModule;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.repository.work.NoneCachingWorkingCopyPool;
import sonia.scm.repository.work.WorkingCopyPool;
public class WorkingCopyPoolModule extends AbstractModule {
public static final String DEFAULT_WORKING_COPY_POOL_STRATEGY = "sonia.scm.repository.work.NoneCachingWorkingCopyPool";
public static final String DEFAULT_WORKING_COPY_POOL_STRATEGY = NoneCachingWorkingCopyPool.class.getName();
public static final String WORKING_COPY_POOL_STRATEGY_PROPERTY = "scm.workingCopyPoolStrategy";
private final PluginLoader pluginLoader;
private final ClassLoader classLoader;
public WorkingCopyPoolModule(PluginLoader pluginLoader) {
this.pluginLoader = pluginLoader;
this.classLoader = pluginLoader.getUberClassLoader();
}
@Override
protected void configure() {
String workingCopyPoolStrategy = System.getProperty(WORKING_COPY_POOL_STRATEGY_PROPERTY, DEFAULT_WORKING_COPY_POOL_STRATEGY);
try {
Class<? extends WorkingCopyPool> strategyClass = (Class<? extends WorkingCopyPool>) pluginLoader.getUberClassLoader().loadClass(workingCopyPoolStrategy);
Class<? extends WorkingCopyPool> strategyClass = (Class<? extends WorkingCopyPool>) classLoader.loadClass(workingCopyPoolStrategy);
bind(WorkingCopyPool.class).to(strategyClass);
} catch (Exception e) {
throw new RuntimeException("could not instantiate class for working copy pool: " + workingCopyPoolStrategy, e);