Search in sources :

Example 1 with ConfigurationTransformation

use of org.spongepowered.configurate.transformation.ConfigurationTransformation in project SpongeCommon by SpongePowered.

the class SpongeConfigs method splitFiles.

private static void splitFiles() {
    final Path commonFile = SpongeConfigs.getDirectory().resolve(CommonConfig.FILE_NAME);
    final Path metricsFile = SpongeConfigs.getDirectory().resolve(SpongeConfigs.METRICS_NAME);
    final Path oldGlobalFile = SpongeConfigs.getDirectory().resolve(SpongeConfigs.GLOBAL_NAME);
    // Is this migration unnecessary?
    if (!Files.exists(oldGlobalFile) || Files.exists(commonFile) || Files.exists(metricsFile)) {
        return;
    }
    try {
        final ConfigurationTransformation xform = ConfigurationTransformation.chain(new FileMovingConfigurationTransformation(SpongeConfigs.MIGRATE_SPONGE_PATHS, SpongeConfigs.createLoader(commonFile), true), new FileMovingConfigurationTransformation(SpongeConfigs.MIGRATE_METRICS_PATHS, SpongeConfigs.createLoader(metricsFile), true));
        final ConfigurationLoader<CommentedConfigurationNode> globalLoader = SpongeConfigs.createLoader(oldGlobalFile);
        Files.copy(oldGlobalFile, oldGlobalFile.resolveSibling(SpongeConfigs.GLOBAL_NAME + ".old-backup"));
        final CommentedConfigurationNode source = globalLoader.load();
        xform.apply(source);
        globalLoader.save(source);
        SpongeConfigs.LOGGER.info("Migrated Sponge configuration to 1.15+ split-file layout");
    } catch (final IOException ex) {
        SpongeConfigs.LOGGER.error("An error occurred while trying to migrate to a split-file configuration layout", ex);
    }
}
Also used : NodePath(org.spongepowered.configurate.NodePath) Path(java.nio.file.Path) ConfigurationTransformation(org.spongepowered.configurate.transformation.ConfigurationTransformation) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)1 NodePath (org.spongepowered.configurate.NodePath)1 ConfigurationTransformation (org.spongepowered.configurate.transformation.ConfigurationTransformation)1