mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Do not fail when v1 file does not exist
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package sonia.scm.repository.update;
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.migration.UpdateStep;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -49,6 +48,9 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
|
||||
@Override
|
||||
public void doUpdate() throws JAXBException {
|
||||
if (!determineV1File().exists()) {
|
||||
return;
|
||||
}
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(V1RepositoryDatabase.class);
|
||||
V1RepositoryDatabase v1Database = readV1Database(jaxbContext);
|
||||
v1Database.repositoryList.repositories.forEach(this::update);
|
||||
@@ -109,7 +111,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "permissions")
|
||||
public static class V1Permission {
|
||||
private static class V1Permission {
|
||||
private boolean groupPermission;
|
||||
private String name;
|
||||
private String type;
|
||||
@@ -117,7 +119,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "repositories")
|
||||
public static class V1Repository {
|
||||
private static class V1Repository {
|
||||
private Map<String, String> properties;
|
||||
private String contact;
|
||||
private long creationDate;
|
||||
@@ -147,14 +149,14 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
}
|
||||
|
||||
public static class RepositoryList {
|
||||
private static class RepositoryList {
|
||||
@XmlElement(name = "repository")
|
||||
private List<V1Repository> repositories;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "repository-db")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public static class V1RepositoryDatabase {
|
||||
private static class V1RepositoryDatabase {
|
||||
private long creationTime;
|
||||
private Long lastModified;
|
||||
@XmlElement(name = "repositories")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package sonia.scm.repository.update;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
@@ -44,8 +44,15 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
XmlRepositoryV1UpdateStep updateStep;
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@Nested
|
||||
class WithExistingDatabase {
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
ZippedRepositoryTestBase.extract(tempDir.toFile(), "sonia/scm/repository/update/scm-home.v1.zip");
|
||||
}
|
||||
|
||||
@@ -70,8 +77,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
.get()
|
||||
.hasFieldOrPropertyWithValue("type", "git")
|
||||
.hasFieldOrPropertyWithValue("contact", "arthur@dent.uk")
|
||||
.hasFieldOrPropertyWithValue("description", "A simple repository without directories.")
|
||||
;
|
||||
.hasFieldOrPropertyWithValue("description", "A simple repository without directories.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +89,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
assertThat(repository)
|
||||
.get()
|
||||
.hasFieldOrPropertyWithValue("namespace", "git")
|
||||
.hasFieldOrPropertyWithValue("name", "simple")
|
||||
;
|
||||
.hasFieldOrPropertyWithValue("name", "simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +101,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
assertThat(repository)
|
||||
.get()
|
||||
.hasFieldOrPropertyWithValue("namespace", "one")
|
||||
.hasFieldOrPropertyWithValue("name", "directory")
|
||||
;
|
||||
.hasFieldOrPropertyWithValue("name", "directory");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,8 +113,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
assertThat(repository)
|
||||
.get()
|
||||
.hasFieldOrPropertyWithValue("namespace", "some")
|
||||
.hasFieldOrPropertyWithValue("name", "more_directories_than_one")
|
||||
;
|
||||
.hasFieldOrPropertyWithValue("name", "more_directories_than_one");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +128,14 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
new RepositoryPermission("mice", "WRITE", true),
|
||||
new RepositoryPermission("dent", "OWNER", false),
|
||||
new RepositoryPermission("trillian", "READ", false)
|
||||
)
|
||||
;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotFailIfNoOldDatabaseExists() throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
|
||||
}
|
||||
|
||||
private Optional<Repository> findByNamespace(String namespace) {
|
||||
|
||||
Reference in New Issue
Block a user