mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Cleanup
- Mark PathBasedRepositoryLocationResolver as singleton so that other users will get the same instance and will not overwrite the paths set by migration. - Set path kept by InlineMigrationStrategy in location resolver to store the path. - Add logging - Add type of repository to migration web page
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
package sonia.scm.update;
|
||||
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import sonia.scm.update.repository.XmlRepositoryV1UpdateStep;
|
||||
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class MigrationWizardModule extends ServletModule {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MigrationWizardModule.class);
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
LOG.info("==========================================================");
|
||||
LOG.info("= =");
|
||||
LOG.info("= STARTING MIGRATION SERVLET =");
|
||||
LOG.info("= =");
|
||||
LOG.info("==========================================================");
|
||||
serve("/*").with(MigrationWizardServlet.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.RepositoryDirectoryHandler;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
@@ -10,6 +12,8 @@ import java.nio.file.Path;
|
||||
|
||||
class CopyMigrationStrategy extends BaseMigrationStrategy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CopyMigrationStrategy.class);
|
||||
|
||||
private final RepositoryLocationResolver locationResolver;
|
||||
|
||||
@Inject
|
||||
@@ -24,6 +28,7 @@ class CopyMigrationStrategy extends BaseMigrationStrategy {
|
||||
Path targetDataPath = repositoryBasePath
|
||||
.resolve(RepositoryDirectoryHandler.REPOSITORIES_NATIVE_DIRECTORY);
|
||||
Path sourceDataPath = getSourceDataPath(name, type);
|
||||
LOG.info("copying repository data from {} to {}", sourceDataPath, targetDataPath);
|
||||
copyData(sourceDataPath, targetDataPath);
|
||||
return repositoryBasePath;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.RepositoryDirectoryHandler;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.nio.file.Files;
|
||||
@@ -9,16 +12,23 @@ import java.nio.file.Path;
|
||||
|
||||
class InlineMigrationStrategy extends BaseMigrationStrategy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InlineMigrationStrategy.class);
|
||||
|
||||
private final RepositoryLocationResolver locationResolver;
|
||||
|
||||
@Inject
|
||||
public InlineMigrationStrategy(SCMContextProvider contextProvider) {
|
||||
public InlineMigrationStrategy(SCMContextProvider contextProvider, RepositoryLocationResolver locationResolver) {
|
||||
super(contextProvider);
|
||||
this.locationResolver = locationResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path migrate(String id, String name, String type) {
|
||||
Path repositoryBasePath = getSourceDataPath(name, type);
|
||||
locationResolver.forClass(Path.class).setLocation(id, repositoryBasePath);
|
||||
Path targetDataPath = repositoryBasePath
|
||||
.resolve(RepositoryDirectoryHandler.REPOSITORIES_NATIVE_DIRECTORY);
|
||||
LOG.info("moving repository data from {} to {}", repositoryBasePath, targetDataPath);
|
||||
moveData(repositoryBasePath, targetDataPath);
|
||||
return repositoryBasePath;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class MoveMigrationStrategy extends BaseMigrationStrategy {
|
||||
Path targetDataPath = repositoryBasePath
|
||||
.resolve(RepositoryDirectoryHandler.REPOSITORIES_NATIVE_DIRECTORY);
|
||||
Path sourceDataPath = getSourceDataPath(name, type);
|
||||
LOG.info("moving repository data from {} to {}", sourceDataPath, targetDataPath);
|
||||
moveData(sourceDataPath, targetDataPath);
|
||||
deleteOldDataDir(getTypeDependentPath(type), name);
|
||||
return repositoryBasePath;
|
||||
|
||||
@@ -157,6 +157,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
|
||||
private Path handleDataDirectory(V1Repository v1Repository) {
|
||||
MigrationStrategy dataMigrationStrategy = readMigrationStrategy(v1Repository);
|
||||
LOG.info("using strategy {} to migrate repository {} with id {}", dataMigrationStrategy.getClass(), v1Repository.name, v1Repository.id);
|
||||
return dataMigrationStrategy.from(injector).migrate(v1Repository.id, v1Repository.name, v1Repository.type);
|
||||
}
|
||||
|
||||
@@ -231,6 +232,10 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getNewNamespace() {
|
||||
String[] nameParts = getNameParts(name);
|
||||
return nameParts.length > 1 ? nameParts[0] : type;
|
||||
|
||||
Reference in New Issue
Block a user