3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00
Dieser Commit ist enthalten in:
Camotoy 2024-09-12 16:45:40 -04:00
Ursprung 1271505c26
Commit e99759d701
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 42 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.configuration;
import com.google.common.annotations.VisibleForTesting;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.returnsreceiver.qual.This;
import org.geysermc.geyser.Constants;
@ -75,7 +76,10 @@ public final class ConfigLoader {
--------------------------------
""";
private final GeyserBootstrap bootstrap;
/**
* Only nullable for testing.
*/
private final @Nullable GeyserBootstrap bootstrap;
private @Nullable Consumer<CommentedConfigurationNode> transformer;
private File configFile;
@ -84,6 +88,12 @@ public final class ConfigLoader {
configFile = new File(bootstrap.getConfigFolder().toFile(), "config.yml");
}
@VisibleForTesting
ConfigLoader(File file) {
this.bootstrap = null;
configFile = file;
}
/**
* Creates the directory as indicated by {@link GeyserBootstrap#getConfigFolder()}
*/
@ -236,7 +246,9 @@ public final class ConfigLoader {
config.advanced(advancedConfig);
bootstrap.getGeyserLogger().setDebug(config.debugMode());
if (this.bootstrap != null) { // Null for testing only.
this.bootstrap.getGeyserLogger().setDebug(config.debugMode());
}
return config;
}
@ -292,9 +304,12 @@ public final class ConfigLoader {
.file(file)
.indent(2)
.nodeStyle(NodeStyle.BLOCK)
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options, builder ->
builder.addProcessor(ExcludePlatform.class, excludePlatform(bootstrap.platformType().platformName()))
.addProcessor(PluginSpecific.class, integrationSpecific(bootstrap.platformType() != PlatformType.STANDALONE)))
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options, builder -> {
if (this.bootstrap != null) { // Testing only.
builder.addProcessor(ExcludePlatform.class, excludePlatform(bootstrap.platformType().platformName()))
.addProcessor(PluginSpecific.class, integrationSpecific(bootstrap.platformType() != PlatformType.STANDALONE));
}
})
.shouldCopyDefaults(false) // If we use ConfigurationNode#get(type, default), do not write the default back to the node.
.header(header)
.serializers(builder -> builder.register(new LowercaseEnumSerializer())))

Datei anzeigen

@ -31,7 +31,12 @@ import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.util.CheckedConsumer;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ConfigLoaderTest {
@ -49,23 +54,23 @@ public class ConfigLoaderTest {
File file = tempDirectory.resolve("config.yml").toFile();
// Sorry Konicai...
// forAllConfigs(type -> {
// ConfigLoader.load(file, type, n -> this.config1 = n.copy());
// long initialModification = file.lastModified();
// assertTrue(file.exists()); // should have been created
// List<String> firstContents = Files.readAllLines(file.toPath());
//
// ConfigLoader.load(file, type, n -> this.config2 = n.copy());
// List<String> secondContents = Files.readAllLines(file.toPath());
//
// assertEquals(initialModification, file.lastModified()); // should not have been touched
// assertEquals(firstContents, secondContents);
//
// // Must ignore this, as when the config is read back, the header is interpreted as a comment on the first node in the map
// config1.node("java").comment(null);
// config2.node("java").comment(null);
// assertEquals(config1, config2);
// });
forAllConfigs(type -> {
new ConfigLoader(file).transformer(n -> this.config1 = n.copy()).load(type);
long initialModification = file.lastModified();
assertTrue(file.exists()); // should have been created
List<String> firstContents = Files.readAllLines(file.toPath());
new ConfigLoader(file).transformer(n -> this.config2 = n.copy()).load(type);
List<String> secondContents = Files.readAllLines(file.toPath());
assertEquals(initialModification, file.lastModified()); // should not have been touched
assertEquals(firstContents, secondContents);
// Must ignore this, as when the config is read back, the header is interpreted as a comment on the first node in the map
config1.node("java").comment(null);
config2.node("java").comment(null);
assertEquals(config1, config2);
});
}
void forAllConfigs(CheckedConsumer<Class<? extends GeyserConfig>, Exception> consumer) throws Exception {