mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Drop iris.json settings migration
This commit is contained in:
1 parent
0bf7c346a2
commit
4141c0bead
2 files changed
+1
-68
No files matched your search
@@ -3,7 +3,6 @@ package art.arcane.iris.configuration;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.config.TomlCodec;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,12 +10,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
/**
|
||||
* Reads and writes the Iris settings file. Settings live in iris.toml so each key can carry a comment; a file
|
||||
* left by a build that used iris.json is moved over once on first load.
|
||||
* Reads and writes the Iris settings file. Settings live in iris.toml so each key can carry a comment.
|
||||
*/
|
||||
public final class IrisSettingsFile {
|
||||
public static final String FILE_NAME = "iris.toml";
|
||||
static final String LEGACY_FILE_NAME = "iris.json";
|
||||
private static final String SOURCE_TAG = "iris";
|
||||
|
||||
private IrisSettingsFile() {
|
||||
@@ -37,11 +34,6 @@ public final class IrisSettingsFile {
|
||||
return loadExisting(file);
|
||||
}
|
||||
|
||||
File legacyFile = new File(file.getParentFile(), LEGACY_FILE_NAME);
|
||||
if (legacyFile.exists()) {
|
||||
return migrateLegacy(legacyFile, file);
|
||||
}
|
||||
|
||||
IrisSettings defaults = new IrisSettings();
|
||||
rewrite(file, defaults);
|
||||
return defaults;
|
||||
@@ -79,31 +71,6 @@ public final class IrisSettingsFile {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
private static IrisSettings migrateLegacy(File legacyFile, File file) {
|
||||
IrisSettings migrated;
|
||||
try {
|
||||
migrated = parseLegacy(Files.readString(legacyFile.toPath(), StandardCharsets.UTF_8));
|
||||
} catch (Throwable failure) {
|
||||
IrisLogging.error("Configuration Error in " + LEGACY_FILE_NAME + "! " + rootCause(failure)
|
||||
+ ". Using defaults; fix the file to move it to " + FILE_NAME + ".");
|
||||
return new IrisSettings();
|
||||
}
|
||||
|
||||
if (!rewrite(file, migrated)) {
|
||||
return migrated;
|
||||
}
|
||||
deleteMigratedLegacy(legacyFile);
|
||||
IrisLogging.info("Moved Iris settings from " + LEGACY_FILE_NAME + " to " + FILE_NAME + ".");
|
||||
return migrated;
|
||||
}
|
||||
|
||||
private static IrisSettings parseLegacy(String json) {
|
||||
IrisSettings parsed = new Gson().fromJson(json, IrisSettings.class);
|
||||
IrisSettings migrated = parsed == null ? new IrisSettings() : parsed;
|
||||
migrated.fillMissingSections();
|
||||
return migrated;
|
||||
}
|
||||
|
||||
private static boolean rewrite(File file, IrisSettings settings) {
|
||||
try {
|
||||
write(settings, file);
|
||||
@@ -115,15 +82,6 @@ public final class IrisSettingsFile {
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteMigratedLegacy(File legacyFile) {
|
||||
try {
|
||||
Files.deleteIfExists(legacyFile.toPath());
|
||||
} catch (IOException | SecurityException failure) {
|
||||
IrisLogging.warn("Could not delete " + legacyFile.getAbsolutePath() + " after moving it to "
|
||||
+ FILE_NAME + ": " + failure.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean sameContent(String raw, String canonical) {
|
||||
return normalizeLineEndings(raw).strip().equals(normalizeLineEndings(canonical).strip());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ public class IrisSettingsFileTest {
|
||||
private IrisPlatform previousPlatform;
|
||||
private IrisSettings previousSettings;
|
||||
private File settingsFile;
|
||||
private File legacyFile;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() throws Exception {
|
||||
@@ -38,7 +37,6 @@ public class IrisSettingsFileTest {
|
||||
IrisPlatforms.unbind();
|
||||
File dataFolder = temporaryFolder.newFolder("Iris");
|
||||
settingsFile = new File(dataFolder, IrisSettingsFile.FILE_NAME);
|
||||
legacyFile = new File(dataFolder, IrisSettingsFile.LEGACY_FILE_NAME);
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
doReturn(settingsFile).when(platform).dataFile(IrisSettingsFile.FILE_NAME);
|
||||
IrisPlatforms.bind(platform);
|
||||
@@ -78,29 +76,6 @@ public class IrisSettingsFileTest {
|
||||
assertEquals(IrisSettingsFile.render(new IrisSettings()), Files.readString(settingsFile.toPath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacyJsonMovesToToml() throws Exception {
|
||||
Files.writeString(legacyFile.toPath(), "{\"general\":{\"debug\":true},\"pregen\":{\"runtimeSchedulerMode\":\"FOLIA\"}}");
|
||||
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertTrue(loaded.getGeneral().isDebug());
|
||||
assertEquals(IrisRuntimeSchedulerMode.FOLIA, loaded.getPregen().getRuntimeSchedulerMode());
|
||||
assertFalse(legacyFile.exists());
|
||||
assertTrue(IrisSettingsFile.parse(Files.readString(settingsFile.toPath())).getGeneral().isDebug());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brokenLegacyJsonStaysWhereItIs() throws Exception {
|
||||
Files.writeString(legacyFile.toPath(), "{\"general\":");
|
||||
|
||||
IrisSettings loaded = IrisSettingsFile.load();
|
||||
|
||||
assertFalse(loaded.getGeneral().isDebug());
|
||||
assertEquals("{\"general\":", Files.readString(legacyFile.toPath()));
|
||||
assertFalse(settingsFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brokenTomlIsNotOverwritten() throws Exception {
|
||||
String broken = "[general]\ndebug = tru\n";
|
||||
|
||||
Reference in new issue
Block a user