Resolve config files via resolve method of context provider

This commit is contained in:
René Pfeuffer
2019-06-03 16:02:04 +02:00
parent 7c50ad07ec
commit da4f3e6691
5 changed files with 34 additions and 29 deletions

View File

@@ -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)