3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00

Update yaml compat checker

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-03-16 20:41:03 +01:00
Ursprung 4e844a0095
Commit 74fb55d96b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 5 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -39,19 +39,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@SuppressWarnings("VulnerableCodeUsages")
public abstract class Config implements ConfigurationProvider { public abstract class Config implements ConfigurationProvider {
private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion2() ? new Yaml2Compat() : new Yaml1Compat(); private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion1() ? new Yaml1Compat() : new Yaml2Compat();
private static final ThreadLocal<Yaml> YAML = ThreadLocal.withInitial(() -> { private static final ThreadLocal<Yaml> YAML = ThreadLocal.withInitial(() -> {
DumperOptions options = new DumperOptions(); DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(false); options.setPrettyFlow(false);
options.setIndent(2); options.setIndent(2);
try {
return new Yaml(YAMP_COMPAT.createSafeConstructor(), YAMP_COMPAT.createRepresenter(options), options); return new Yaml(YAMP_COMPAT.createSafeConstructor(), YAMP_COMPAT.createRepresenter(options), options);
} catch (NoSuchMethodError e) {
YamlCompat compat = new Yaml1Compat();
return new Yaml(compat.createSafeConstructor(), compat.createRepresenter(options), options);
}
}); });
private final CommentStore commentStore = new CommentStore('.', 2); private final CommentStore commentStore = new CommentStore('.', 2);

Datei anzeigen

@ -27,9 +27,9 @@ public interface YamlCompat {
SafeConstructor createSafeConstructor(); SafeConstructor createSafeConstructor();
static boolean isVersion2() { static boolean isVersion1() {
try { try {
Representer.class.getDeclaredConstructor(DumperOptions.class); SafeConstructor.class.getDeclaredConstructor();
return true; return true;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
return false; return false;