mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Cleanup
This commit is contained in:
@@ -141,35 +141,43 @@ public class BootstrapContextListener implements ServletContextListener {
|
||||
}
|
||||
|
||||
private void createContextListener(File pluginDirectory) {
|
||||
ClassLoader cl;
|
||||
Set<PluginWrapper> plugins;
|
||||
PluginLoader pluginLoader;
|
||||
|
||||
try {
|
||||
renameOldPluginsFolder(pluginDirectory);
|
||||
|
||||
if (!isCorePluginExtractionDisabled()) {
|
||||
extractCorePlugins(context, pluginDirectory);
|
||||
} else {
|
||||
logger.info("core plugin extraction is disabled");
|
||||
}
|
||||
|
||||
ClassLoader cl = ClassLoaders.getContextClassLoader(BootstrapContextListener.class);
|
||||
cl = ClassLoaders.getContextClassLoader(BootstrapContextListener.class);
|
||||
|
||||
Set<PluginWrapper> plugins = PluginsInternal.collectPlugins(cl, pluginDirectory.toPath());
|
||||
plugins = PluginsInternal.collectPlugins(cl, pluginDirectory.toPath());
|
||||
|
||||
PluginLoader pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
||||
pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
||||
|
||||
Injector bootstrapInjector = createBootstrapInjector(pluginLoader);
|
||||
|
||||
MigrationWizardContextListener wizardContextListener = prepareWizardIfNeeded(bootstrapInjector);
|
||||
|
||||
if (wizardContextListener.wizardNecessary()) {
|
||||
contextListener = wizardContextListener;
|
||||
} else {
|
||||
processUpdates(pluginLoader, bootstrapInjector);
|
||||
|
||||
contextListener = bootstrapInjector.getInstance(ScmContextListener.Factory.class).create(cl, plugins);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new PluginLoadException("could not load plugins", ex);
|
||||
}
|
||||
|
||||
Injector bootstrapInjector = createBootstrapInjector(pluginLoader);
|
||||
|
||||
startEitherMigrationOrNormalServlet(cl, plugins, pluginLoader, bootstrapInjector);
|
||||
}
|
||||
|
||||
private void startEitherMigrationOrNormalServlet(ClassLoader cl, Set<PluginWrapper> plugins, PluginLoader pluginLoader, Injector bootstrapInjector) {
|
||||
MigrationWizardContextListener wizardContextListener = prepareWizardIfNeeded(bootstrapInjector);
|
||||
|
||||
if (wizardContextListener.wizardNecessary()) {
|
||||
contextListener = wizardContextListener;
|
||||
} else {
|
||||
processUpdates(pluginLoader, bootstrapInjector);
|
||||
contextListener = bootstrapInjector.getInstance(ScmContextListener.Factory.class).create(cl, plugins);
|
||||
}
|
||||
}
|
||||
|
||||
private void renameOldPluginsFolder(File pluginDirectory) {
|
||||
|
||||
@@ -16,6 +16,8 @@ class MigrationWizardModule extends ServletModule {
|
||||
LOG.info("= =");
|
||||
LOG.info("= STARTING MIGRATION SERVLET =");
|
||||
LOG.info("= =");
|
||||
LOG.info("= Open SCM-Manager in a browser to start the wizard. =");
|
||||
LOG.info("= =");
|
||||
LOG.info("==========================================================");
|
||||
bind(PushStateDispatcher.class).toInstance((request, response, uri) -> {});
|
||||
serve("/images/*", "/styles/*").with(WebResourceServlet.class);
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@Singleton
|
||||
class MigrationWizardServlet extends HttpServlet {
|
||||
@@ -41,18 +40,19 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
public boolean wizardNecessary() {
|
||||
return !repositoryV1UpdateStep.missingMigrationStrategies().isEmpty();
|
||||
return !repositoryV1UpdateStep.getRepositoriesWithoutMigrationStrategies().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
List<XmlRepositoryV1UpdateStep.V1Repository> missingMigrationStrategies = repositoryV1UpdateStep.missingMigrationStrategies();
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
List<XmlRepositoryV1UpdateStep.V1Repository> repositoriesWithoutMigrationStrategies =
|
||||
repositoryV1UpdateStep.getRepositoriesWithoutMigrationStrategies();
|
||||
|
||||
HashMap<String, Object> model = new HashMap<>();
|
||||
|
||||
model.put("contextPath", req.getContextPath());
|
||||
model.put("submitUrl", req.getRequestURI());
|
||||
model.put("repositories", missingMigrationStrategies);
|
||||
model.put("repositories", repositoriesWithoutMigrationStrategies);
|
||||
model.put("strategies", getMigrationStrategies());
|
||||
|
||||
MustacheFactory mf = new DefaultMustacheFactory();
|
||||
@@ -60,10 +60,6 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
respondWithTemplate(resp, model, template);
|
||||
}
|
||||
|
||||
private List<String> getMigrationStrategies() {
|
||||
return stream(MigrationStrategy.values()).map(Enum::name).collect(toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
resp.setStatus(200);
|
||||
@@ -81,6 +77,10 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
ScmEventBus.getInstance().post(new RestartEvent(MigrationWizardServlet.class, "wrote migration data"));
|
||||
}
|
||||
|
||||
private MigrationStrategy[] getMigrationStrategies() {
|
||||
return MigrationStrategy.values();
|
||||
}
|
||||
|
||||
private void respondWithTemplate(HttpServletResponse resp, Map<String, Object> model, Mustache template) {
|
||||
PrintWriter writer;
|
||||
try {
|
||||
|
||||
@@ -111,7 +111,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
);
|
||||
}
|
||||
|
||||
public List<V1Repository> missingMigrationStrategies() {
|
||||
public List<V1Repository> getRepositoriesWithoutMigrationStrategies() {
|
||||
if (!resolveV1File().exists()) {
|
||||
LOG.info("no v1 repositories database file found");
|
||||
return emptyList();
|
||||
|
||||
Reference in New Issue
Block a user