mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Store repository id in svn config for each repository
This is needed after migration from v1 to v2 and is done in SvnV1UpdateStep.java.
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
import sonia.scm.ContextEntry;
|
||||||
|
import sonia.scm.io.INIConfiguration;
|
||||||
|
import sonia.scm.io.INIConfigurationReader;
|
||||||
|
import sonia.scm.io.INIConfigurationWriter;
|
||||||
|
import sonia.scm.io.INISection;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
class SvnConfigHelper {
|
||||||
|
|
||||||
|
private static final String CONFIG_FILE_NAME = "scm-manager.conf";
|
||||||
|
private static final String CONFIG_SECTION_SCMM = "scmm";
|
||||||
|
private static final String CONFIG_KEY_REPOSITORY_ID = "repositoryid";
|
||||||
|
|
||||||
|
void writeRepositoryId(Repository repository, File directory) throws IOException {
|
||||||
|
INISection iniSection = new INISection(CONFIG_SECTION_SCMM);
|
||||||
|
iniSection.setParameter(CONFIG_KEY_REPOSITORY_ID, repository.getId());
|
||||||
|
INIConfiguration iniConfiguration = new INIConfiguration();
|
||||||
|
iniConfiguration.addSection(iniSection);
|
||||||
|
new INIConfigurationWriter().write(iniConfiguration, new File(directory, CONFIG_FILE_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
String getRepositoryId(File directory) {
|
||||||
|
try {
|
||||||
|
return new INIConfigurationReader().read(new File(directory, CONFIG_FILE_NAME)).getSection(CONFIG_SECTION_SCMM).getParameter(CONFIG_KEY_REPOSITORY_ID);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("Directory", directory.toString()), "could not read scm configuration file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,11 +46,6 @@ import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
|
|||||||
import org.tmatesoft.svn.core.io.SVNRepository;
|
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||||
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
|
||||||
import org.tmatesoft.svn.util.SVNDebugLog;
|
import org.tmatesoft.svn.util.SVNDebugLog;
|
||||||
import sonia.scm.ContextEntry;
|
|
||||||
import sonia.scm.io.INIConfiguration;
|
|
||||||
import sonia.scm.io.INIConfigurationReader;
|
|
||||||
import sonia.scm.io.INIConfigurationWriter;
|
|
||||||
import sonia.scm.io.INISection;
|
|
||||||
import sonia.scm.logging.SVNKitLogger;
|
import sonia.scm.logging.SVNKitLogger;
|
||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
import sonia.scm.plugin.PluginLoader;
|
import sonia.scm.plugin.PluginLoader;
|
||||||
@@ -87,9 +82,6 @@ public class SvnRepositoryHandler
|
|||||||
public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME,
|
public static final RepositoryType TYPE = new RepositoryType(TYPE_NAME,
|
||||||
TYPE_DISPLAYNAME,
|
TYPE_DISPLAYNAME,
|
||||||
SvnRepositoryServiceProvider.COMMANDS);
|
SvnRepositoryServiceProvider.COMMANDS);
|
||||||
private static final String CONFIG_FILE_NAME = "scm-manager.conf";
|
|
||||||
private static final String CONFIG_SECTION_SCMM = "scmm";
|
|
||||||
private static final String CONFIG_KEY_REPOSITORY_ID = "repositoryid";
|
|
||||||
|
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(SvnRepositoryHandler.class);
|
LoggerFactory.getLogger(SvnRepositoryHandler.class);
|
||||||
@@ -223,18 +215,10 @@ public class SvnRepositoryHandler
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void postCreate(Repository repository, File directory) throws IOException {
|
protected void postCreate(Repository repository, File directory) throws IOException {
|
||||||
INISection iniSection = new INISection(CONFIG_SECTION_SCMM);
|
new SvnConfigHelper().writeRepositoryId(repository, directory);
|
||||||
iniSection.setParameter(CONFIG_KEY_REPOSITORY_ID, repository.getId());
|
|
||||||
INIConfiguration iniConfiguration = new INIConfiguration();
|
|
||||||
iniConfiguration.addSection(iniSection);
|
|
||||||
new INIConfigurationWriter().write(iniConfiguration, new File(directory, CONFIG_FILE_NAME));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getRepositoryId(File directory) {
|
String getRepositoryId(File directory) {
|
||||||
try {
|
return new SvnConfigHelper().getRepositoryId(directory);
|
||||||
return new INIConfigurationReader().read(new File(directory, CONFIG_FILE_NAME)).getSection(CONFIG_SECTION_SCMM).getParameter(CONFIG_KEY_REPOSITORY_ID);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new InternalRepositoryException(ContextEntry.ContextBuilder.entity("Directory", directory.toString()), "could not read scm configuration file", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
import sonia.scm.migration.UpdateException;
|
||||||
|
import sonia.scm.migration.UpdateStep;
|
||||||
|
import sonia.scm.plugin.Extension;
|
||||||
|
import sonia.scm.update.UpdateStepRepositoryMetadataAccess;
|
||||||
|
import sonia.scm.version.Version;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import static sonia.scm.version.Version.parse;
|
||||||
|
|
||||||
|
@Extension
|
||||||
|
public class SvnV1UpdateStep implements UpdateStep {
|
||||||
|
|
||||||
|
private final RepositoryLocationResolver locationResolver;
|
||||||
|
private final UpdateStepRepositoryMetadataAccess<Path> repositoryMetadataAccess;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SvnV1UpdateStep(RepositoryLocationResolver locationResolver, UpdateStepRepositoryMetadataAccess<Path> repositoryMetadataAccess) {
|
||||||
|
this.locationResolver = locationResolver;
|
||||||
|
this.repositoryMetadataAccess = repositoryMetadataAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doUpdate() {
|
||||||
|
locationResolver.forClass(Path.class).forAllLocations(
|
||||||
|
(repositoryId, path) -> {
|
||||||
|
Repository repository = repositoryMetadataAccess.read(path);
|
||||||
|
if (isSvnDirectory(repository)) {
|
||||||
|
try {
|
||||||
|
new SvnConfigHelper().writeRepositoryId(repository, path.toFile());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UpdateException("could not update repository with id " + repositoryId + " in path " + path, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSvnDirectory(Repository repository) {
|
||||||
|
return SvnRepositoryHandler.TYPE_NAME.equals(repository.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Version getTargetVersion() {
|
||||||
|
return parse("2.0.0");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAffectedDataType() {
|
||||||
|
return "sonia.scm.plugin.svn";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user