mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Resolve config files via resolve method of context provider
This commit is contained in:
@@ -21,10 +21,10 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -96,9 +96,8 @@ public class XmlGroupV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
|
||||
private Optional<Path> determineV1File() {
|
||||
Path configDirectory = determineConfigDirectory();
|
||||
Path existingGroupsFile = configDirectory.resolve("groups" + StoreConstants.FILE_EXTENSION);
|
||||
Path groupsV1File = configDirectory.resolve("groupsV1" + StoreConstants.FILE_EXTENSION);
|
||||
Path existingGroupsFile = resolveConfigFile("groups");
|
||||
Path groupsV1File = resolveConfigFile("groupsV1");
|
||||
if (existingGroupsFile.toFile().exists()) {
|
||||
try {
|
||||
Files.move(existingGroupsFile, groupsV1File);
|
||||
@@ -111,8 +110,11 @@ public class XmlGroupV1UpdateStep implements UpdateStep {
|
||||
return empty();
|
||||
}
|
||||
|
||||
private Path determineConfigDirectory() {
|
||||
return new File(contextProvider.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME).toPath();
|
||||
private Path resolveConfigFile(String name) {
|
||||
return contextProvider
|
||||
.resolve(
|
||||
Paths.get(StoreConstants.CONFIG_DIRECTORY_NAME).resolve(name + StoreConstants.FILE_EXTENSION)
|
||||
);
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -94,7 +95,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
|
||||
@Override
|
||||
public void doUpdate() throws JAXBException {
|
||||
if (!determineV1File().exists()) {
|
||||
if (!resolveV1File().exists()) {
|
||||
LOG.info("no v1 repositories database file found");
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +180,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
|
||||
private Optional<V1RepositoryDatabase> readV1Database(JAXBContext jaxbContext) throws JAXBException {
|
||||
Object unmarshal = jaxbContext.createUnmarshaller().unmarshal(determineV1File());
|
||||
Object unmarshal = jaxbContext.createUnmarshaller().unmarshal(resolveV1File());
|
||||
if (unmarshal instanceof V1RepositoryDatabase) {
|
||||
return of((V1RepositoryDatabase) unmarshal);
|
||||
} else {
|
||||
@@ -187,9 +188,11 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
}
|
||||
|
||||
private File determineV1File() {
|
||||
File configDirectory = new File(contextProvider.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME);
|
||||
return new File(configDirectory, "repositories" + StoreConstants.FILE_EXTENSION);
|
||||
private File resolveV1File() {
|
||||
return contextProvider
|
||||
.resolve(
|
||||
Paths.get(StoreConstants.CONFIG_DIRECTORY_NAME).resolve("repositories" + StoreConstants.FILE_EXTENSION)
|
||||
).toFile();
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
||||
@@ -22,10 +22,10 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -107,9 +107,8 @@ public class XmlUserV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
|
||||
private Optional<Path> determineV1File() {
|
||||
Path configDirectory = determineConfigDirectory();
|
||||
Path existingUsersFile = configDirectory.resolve("users" + StoreConstants.FILE_EXTENSION);
|
||||
Path usersV1File = configDirectory.resolve("usersV1" + StoreConstants.FILE_EXTENSION);
|
||||
Path existingUsersFile = resolveConfigFile("users");
|
||||
Path usersV1File = resolveConfigFile("usersV1");
|
||||
if (existingUsersFile.toFile().exists()) {
|
||||
try {
|
||||
Files.move(existingUsersFile, usersV1File);
|
||||
@@ -122,8 +121,11 @@ public class XmlUserV1UpdateStep implements UpdateStep {
|
||||
return empty();
|
||||
}
|
||||
|
||||
private Path determineConfigDirectory() {
|
||||
return new File(contextProvider.getBaseDirectory(), StoreConstants.CONFIG_DIRECTORY_NAME).toPath();
|
||||
private Path resolveConfigFile(String name) {
|
||||
return contextProvider
|
||||
.resolve(
|
||||
Paths.get(StoreConstants.CONFIG_DIRECTORY_NAME).resolve(name + StoreConstants.FILE_EXTENSION)
|
||||
);
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
||||
Reference in New Issue
Block a user