#1467 Rearrange old keys migration so no entries get lost

- 'error' was an old entry but now we have multiple entries under 'error' (which is now a section), so we need to ensure that we migrate the old 'error' entry before the migration sets anything under that path
This commit is contained in:
ljacqu
2018-02-02 18:53:08 +01:00
parent f44353ed4c
commit 1d6d9eb764
34 changed files with 154 additions and 105 deletions
@@ -25,7 +25,7 @@ import java.util.regex.Pattern;
* were at the top of the file and to separate comments by new lines (which ConfigMe
* currently doesn't support).
*/
public class MessagesFileWriter {
public final class MessagesFileWriter {
/** Marker used inside a text to signal that it should be a comment later on. */
private static final String COMMENT_MARKER = "::COMMENT::";
@@ -52,7 +52,7 @@ public class MessagesFileWriter {
// Create property resource with new defaults, save with ConfigMe for proper sections & comments
PropertyResource resource = createPropertyResourceWithCommentEntries();
new SettingsManager(resource, null, MessageUpdater.CONFIGURATION_DATA).save();
new SettingsManager(resource, null, MessageUpdater.getConfigurationData()).save();
// Go through the newly saved file and replace texts with comment marker to actual YAML comments
// and add initial comments back to the file
@@ -89,7 +89,7 @@ public class MessagesFileWriter {
* @return the first comment generated by ConfigMe (comment of the first root path)
*/
private static String getFirstCommentByConfigMe() {
ConfigurationData configurationData = MessageUpdater.CONFIGURATION_DATA;
ConfigurationData configurationData = MessageUpdater.getConfigurationData();
String firstRootPath = configurationData.getProperties().get(0).getPath().split("\\.")[0];
return "# " + configurationData.getCommentsForSection(firstRootPath)[0];
}
@@ -100,7 +100,7 @@ public class MessagesFileWriter {
*/
private PropertyResource createPropertyResourceWithCommentEntries() {
YamlFileResource resource = new MigraterYamlFileResource(file);
for (Property<?> property : MessageUpdater.CONFIGURATION_DATA.getProperties()) {
for (Property<?> property : MessageUpdater.getConfigurationData().getProperties()) {
String text = resource.getString(property.getPath());
if (text == null) {
resource.setValue(property.getPath(), COMMENT_MARKER + defaultFile.getString(property.getPath()));
@@ -132,6 +132,7 @@ public class MessagesFileWriter {
newLines.add(line);
}
}
newLines.add(""); // Makes sure file ends with new line
FileIoUtils.writeToFile(file.toPath(), String.join("\n", newLines));
}