diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 065145c8c..ee08a31c3 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -24,8 +24,8 @@ dependencies { exclude("com.google.code.gson", "gson") exclude("com.viaversion", "nbt") } + api(libs.snakeYaml) - compileOnlyApi(libs.snakeYaml) compileOnlyApi(libs.netty) compileOnlyApi(libs.guava) compileOnlyApi(libs.checkerQual) diff --git a/build-logic/src/main/kotlin/via.shadow-conventions.gradle.kts b/build-logic/src/main/kotlin/via.shadow-conventions.gradle.kts index fe4b82796..d3d04250e 100644 --- a/build-logic/src/main/kotlin/via.shadow-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/via.shadow-conventions.gradle.kts @@ -45,6 +45,7 @@ fun ShadowJar.configureRelocations() { relocate("com.google.gson", "com.viaversion.viaversion.libs.gson") relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil") relocate("net.lenni0451.mcstructs", "com.viaversion.viaversion.libs.mcstructs") + relocate("org.yaml.snakeyaml", "com.viaversion.viaversion.libs.snakeyaml") } fun ShadowJar.configureExcludes() { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 785bdbd5f..0997957e6 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -3,13 +3,11 @@ dependencies { api(rootProject.libs.text) { exclude("com.google.code.gson", "gson") } - implementation(projects.compat.snakeyaml2Compat) - implementation(projects.compat.snakeyaml1Compat) // Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA' testImplementation(rootProject.libs.netty) testImplementation(rootProject.libs.guava) - testImplementation(rootProject.libs.snakeYaml2) + testImplementation(rootProject.libs.snakeYaml) testImplementation(rootProject.libs.bundles.junit) } diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index e5d27d7f3..a38cf491d 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -18,9 +18,6 @@ package com.viaversion.viaversion.util; import com.google.gson.JsonElement; -import com.viaversion.viaversion.compatibility.YamlCompat; -import com.viaversion.viaversion.compatibility.unsafe.Yaml1Compat; -import com.viaversion.viaversion.compatibility.unsafe.Yaml2Compat; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -34,19 +31,32 @@ import java.util.concurrent.ConcurrentSkipListMap; import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.Nullable; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.SafeConstructor; +import org.yaml.snakeyaml.nodes.NodeId; +import org.yaml.snakeyaml.nodes.Tag; +import org.yaml.snakeyaml.representer.Representer; @SuppressWarnings("VulnerableCodeUsages") public abstract class Config { - private static final YamlCompat YAMP_COMPAT = YamlCompat.isVersion1() ? new Yaml1Compat() : new Yaml2Compat(); private static final ThreadLocal YAML = ThreadLocal.withInitial(() -> { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setPrettyFlow(false); options.setIndent(2); - return new Yaml(YAMP_COMPAT.createSafeConstructor(), YAMP_COMPAT.createRepresenter(options), options); + return new Yaml(new CustomSafeConstructor(), new Representer(options), options); }); + private static final class CustomSafeConstructor extends SafeConstructor { + + public CustomSafeConstructor() { + super(new LoaderOptions()); + yamlClassConstructors.put(NodeId.mapping, new ConstructYamlMap()); + yamlConstructors.put(Tag.OMAP, new ConstructYamlOmap()); + } + } + private final CommentStore commentStore = new CommentStore('.', 2); private final File configFile; protected final Logger logger; @@ -254,4 +264,4 @@ public abstract class Config { return null; } } -} \ No newline at end of file +} diff --git a/compat/build.gradle.kts b/compat/build.gradle.kts deleted file mode 100644 index 5d91813ce..000000000 --- a/compat/build.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - api(projects.compat.snakeyamlCompatCommon) - api(projects.compat.snakeyaml2Compat) - api(projects.compat.snakeyaml1Compat) -} diff --git a/compat/snakeyaml-compat-common/build.gradle.kts b/compat/snakeyaml-compat-common/build.gradle.kts deleted file mode 100644 index 45ffe7145..000000000 --- a/compat/snakeyaml-compat-common/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - compileOnly(rootProject.libs.snakeYaml2) -} diff --git a/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java b/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java deleted file mode 100644 index 8cdb4bd6c..000000000 --- a/compat/snakeyaml-compat-common/src/main/java/com/viaversion/viaversion/compatibility/YamlCompat.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.compatibility; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.representer.Representer; - -public interface YamlCompat { - - Representer createRepresenter(DumperOptions dumperOptions); - - SafeConstructor createSafeConstructor(); - - static boolean isVersion1() { - try { - SafeConstructor.class.getDeclaredConstructor(); - return true; - } catch (NoSuchMethodException e) { - return false; - } - } -} diff --git a/compat/snakeyaml1-compat/build.gradle.kts b/compat/snakeyaml1-compat/build.gradle.kts deleted file mode 100644 index 17a8d1e62..000000000 --- a/compat/snakeyaml1-compat/build.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - api(projects.compat.snakeyamlCompatCommon) - compileOnly(rootProject.libs.snakeYaml) -} diff --git a/compat/snakeyaml1-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml1Compat.java b/compat/snakeyaml1-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml1Compat.java deleted file mode 100644 index 16f1eaf7c..000000000 --- a/compat/snakeyaml1-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml1Compat.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.compatibility.unsafe; - -import com.viaversion.viaversion.compatibility.YamlCompat; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.nodes.NodeId; -import org.yaml.snakeyaml.nodes.Tag; -import org.yaml.snakeyaml.representer.Representer; - -public final class Yaml1Compat implements YamlCompat { - - @Override - public Representer createRepresenter(DumperOptions dumperOptions) { - return new Representer(); - } - - @Override - public SafeConstructor createSafeConstructor() { - return new CustomSafeConstructor(); - } - - private static final class CustomSafeConstructor extends SafeConstructor { - - public CustomSafeConstructor() { - yamlClassConstructors.put(NodeId.mapping, new ConstructYamlMap()); - yamlConstructors.put(Tag.OMAP, new ConstructYamlOmap()); - } - } -} diff --git a/compat/snakeyaml2-compat/build.gradle.kts b/compat/snakeyaml2-compat/build.gradle.kts deleted file mode 100644 index 0b54f4982..000000000 --- a/compat/snakeyaml2-compat/build.gradle.kts +++ /dev/null @@ -1,4 +0,0 @@ -dependencies { - api(projects.compat.snakeyamlCompatCommon) - compileOnly(rootProject.libs.snakeYaml2) -} diff --git a/compat/snakeyaml2-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml2Compat.java b/compat/snakeyaml2-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml2Compat.java deleted file mode 100644 index dacb5d720..000000000 --- a/compat/snakeyaml2-compat/src/main/java/com/viaversion/viaversion/compatibility/unsafe/Yaml2Compat.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.compatibility.unsafe; - -import com.viaversion.viaversion.compatibility.YamlCompat; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import org.yaml.snakeyaml.nodes.NodeId; -import org.yaml.snakeyaml.nodes.Tag; -import org.yaml.snakeyaml.representer.Representer; - -public final class Yaml2Compat implements YamlCompat { - - @Override - public Representer createRepresenter(DumperOptions dumperOptions) { - return new Representer(dumperOptions); - } - - @Override - public SafeConstructor createSafeConstructor() { - return new CustomSafeConstructor(); - } - - private static final class CustomSafeConstructor extends SafeConstructor { - - public CustomSafeConstructor() { - super(new LoaderOptions()); - yamlClassConstructors.put(NodeId.mapping, new ConstructYamlMap()); - yamlConstructors.put(Tag.OMAP, new ConstructYamlOmap()); - } - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e474987df..745761671 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,8 +10,7 @@ mcstructs = "5-2.5.0-SNAPSHOT" # Common provided netty = "4.0.20.Final" guava = "17.0" -snakeYaml = "1.18" -snakeYaml2 = "2.0" +snakeYaml = "2.2" junit = "5.10.2" checkerQual = "3.43.0" @@ -33,7 +32,6 @@ text = { group = "com.viaversion.mcstructs", name = "text", version.ref = "mcstr netty = { group = "io.netty", name = "netty-all", version.ref = "netty" } guava = { group = "com.google.guava", name = "guava", version.ref = "guava" } snakeYaml = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeYaml" } -snakeYaml2 = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeYaml2" } jupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" } jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 976ffcefb..355642975 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,8 +24,6 @@ rootProject.name = "viaversion-parent" includeBuild("build-logic") -include("compat", "compat:snakeyaml-compat-common", "compat:snakeyaml2-compat", "compat:snakeyaml1-compat") - setupViaSubproject("api") setupViaSubproject("common") setupViaSubproject("bukkit")