mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
use PluginLoader instead of DefaultPluginLoader and split large contextInitialized method
This commit is contained in:
@@ -50,6 +50,7 @@ import sonia.scm.plugin.DefaultPluginLoader;
|
|||||||
import sonia.scm.plugin.Plugin;
|
import sonia.scm.plugin.Plugin;
|
||||||
import sonia.scm.plugin.PluginException;
|
import sonia.scm.plugin.PluginException;
|
||||||
import sonia.scm.plugin.PluginLoadException;
|
import sonia.scm.plugin.PluginLoadException;
|
||||||
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.plugin.PluginWrapper;
|
import sonia.scm.plugin.PluginWrapper;
|
||||||
import sonia.scm.plugin.PluginsInternal;
|
import sonia.scm.plugin.PluginsInternal;
|
||||||
import sonia.scm.plugin.SmpArchive;
|
import sonia.scm.plugin.SmpArchive;
|
||||||
@@ -137,6 +138,19 @@ public class BootstrapContextListener implements ServletContextListener {
|
|||||||
|
|
||||||
File pluginDirectory = getPluginDirectory();
|
File pluginDirectory = getPluginDirectory();
|
||||||
|
|
||||||
|
createContextListener(pluginDirectory);
|
||||||
|
|
||||||
|
contextListener.contextInitialized(sce);
|
||||||
|
|
||||||
|
// register for restart events
|
||||||
|
if (!registered && (SCMContext.getContext().getStage() == Stage.DEVELOPMENT)) {
|
||||||
|
logger.info("register for restart events");
|
||||||
|
ScmEventBus.getInstance().register(this);
|
||||||
|
registered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createContextListener(File pluginDirectory) {
|
||||||
try {
|
try {
|
||||||
if (!isCorePluginExtractionDisabled()) {
|
if (!isCorePluginExtractionDisabled()) {
|
||||||
extractCorePlugins(context, pluginDirectory);
|
extractCorePlugins(context, pluginDirectory);
|
||||||
@@ -148,22 +162,9 @@ public class BootstrapContextListener implements ServletContextListener {
|
|||||||
|
|
||||||
Set<PluginWrapper> plugins = PluginsInternal.collectPlugins(cl, pluginDirectory.toPath());
|
Set<PluginWrapper> plugins = PluginsInternal.collectPlugins(cl, pluginDirectory.toPath());
|
||||||
|
|
||||||
DefaultPluginLoader pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
PluginLoader pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
||||||
|
|
||||||
Module scmContextListenerModule = new ScmContextListenerModule();
|
Injector bootstrapInjector = createBootstrapInjector(pluginLoader);
|
||||||
BootstrapModule bootstrapModule = new BootstrapModule(pluginLoader);
|
|
||||||
ScmInitializerModule scmInitializerModule = new ScmInitializerModule();
|
|
||||||
EagerSingletonModule eagerSingletonModule = new EagerSingletonModule();
|
|
||||||
ScmEventBusModule scmEventBusModule = new ScmEventBusModule();
|
|
||||||
|
|
||||||
Injector bootstrapInjector =
|
|
||||||
Guice.createInjector(
|
|
||||||
bootstrapModule,
|
|
||||||
scmContextListenerModule,
|
|
||||||
scmEventBusModule,
|
|
||||||
scmInitializerModule,
|
|
||||||
eagerSingletonModule
|
|
||||||
);
|
|
||||||
|
|
||||||
processUpdates(pluginLoader, bootstrapInjector);
|
processUpdates(pluginLoader, bootstrapInjector);
|
||||||
|
|
||||||
@@ -171,19 +172,25 @@ public class BootstrapContextListener implements ServletContextListener {
|
|||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new PluginLoadException("could not load plugins", ex);
|
throw new PluginLoadException("could not load plugins", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
contextListener.contextInitialized(sce);
|
|
||||||
|
|
||||||
// register for restart events
|
|
||||||
if (!registered
|
|
||||||
&& (SCMContext.getContext().getStage() == Stage.DEVELOPMENT)) {
|
|
||||||
logger.info("register for restart events");
|
|
||||||
ScmEventBus.getInstance().register(this);
|
|
||||||
registered = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processUpdates(DefaultPluginLoader pluginLoader, Injector bootstrapInjector) {
|
private Injector createBootstrapInjector(PluginLoader pluginLoader) {
|
||||||
|
Module scmContextListenerModule = new ScmContextListenerModule();
|
||||||
|
BootstrapModule bootstrapModule = new BootstrapModule(pluginLoader);
|
||||||
|
ScmInitializerModule scmInitializerModule = new ScmInitializerModule();
|
||||||
|
EagerSingletonModule eagerSingletonModule = new EagerSingletonModule();
|
||||||
|
ScmEventBusModule scmEventBusModule = new ScmEventBusModule();
|
||||||
|
|
||||||
|
return Guice.createInjector(
|
||||||
|
bootstrapModule,
|
||||||
|
scmContextListenerModule,
|
||||||
|
scmEventBusModule,
|
||||||
|
scmInitializerModule,
|
||||||
|
eagerSingletonModule
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processUpdates(PluginLoader pluginLoader, Injector bootstrapInjector) {
|
||||||
Injector updateInjector = bootstrapInjector.createChildInjector(new UpdateStepModule(pluginLoader));
|
Injector updateInjector = bootstrapInjector.createChildInjector(new UpdateStepModule(pluginLoader));
|
||||||
|
|
||||||
UpdateEngine updateEngine = updateInjector.getInstance(UpdateEngine.class);
|
UpdateEngine updateEngine = updateInjector.getInstance(UpdateEngine.class);
|
||||||
@@ -403,7 +410,6 @@ public class BootstrapContextListener implements ServletContextListener {
|
|||||||
private static class ScmContextListenerModule extends AbstractModule {
|
private static class ScmContextListenerModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
|
||||||
install(new FactoryModuleBuilder().build(ScmContextListener.Factory.class));
|
install(new FactoryModuleBuilder().build(ScmContextListener.Factory.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import sonia.scm.SCMContext;
|
|||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.io.DefaultFileSystem;
|
import sonia.scm.io.DefaultFileSystem;
|
||||||
import sonia.scm.io.FileSystem;
|
import sonia.scm.io.FileSystem;
|
||||||
import sonia.scm.plugin.DefaultPluginLoader;
|
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
import sonia.scm.repository.RepositoryLocationResolver;
|
import sonia.scm.repository.RepositoryLocationResolver;
|
||||||
import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
|
import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
|
||||||
@@ -33,7 +32,7 @@ public class BootstrapModule extends AbstractModule {
|
|||||||
private final ClassOverrides overrides;
|
private final ClassOverrides overrides;
|
||||||
private final PluginLoader pluginLoader;
|
private final PluginLoader pluginLoader;
|
||||||
|
|
||||||
BootstrapModule(DefaultPluginLoader pluginLoader) {
|
BootstrapModule(PluginLoader pluginLoader) {
|
||||||
this.overrides = ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
|
this.overrides = ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
|
||||||
this.pluginLoader = pluginLoader;
|
this.pluginLoader = pluginLoader;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user