mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Include snakeyaml into final jar, delete compat layers (#4070)
Snakeyaml is an untypical library which most Via platforms don't have and also broke in the past with V2, having it directly in the jar like Gson cleans up the build scripts massively, reduces the build time and also doesn't break in the future if they release V3 or any other breaking changes.
This commit is contained in:
parent
864beef341
commit
60b3ba6bb7
@ -24,8 +24,8 @@ dependencies {
|
|||||||
exclude("com.google.code.gson", "gson")
|
exclude("com.google.code.gson", "gson")
|
||||||
exclude("com.viaversion", "nbt")
|
exclude("com.viaversion", "nbt")
|
||||||
}
|
}
|
||||||
|
api(libs.snakeYaml)
|
||||||
|
|
||||||
compileOnlyApi(libs.snakeYaml)
|
|
||||||
compileOnlyApi(libs.netty)
|
compileOnlyApi(libs.netty)
|
||||||
compileOnlyApi(libs.guava)
|
compileOnlyApi(libs.guava)
|
||||||
compileOnlyApi(libs.checkerQual)
|
compileOnlyApi(libs.checkerQual)
|
||||||
|
@ -45,6 +45,7 @@ fun ShadowJar.configureRelocations() {
|
|||||||
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
|
relocate("com.google.gson", "com.viaversion.viaversion.libs.gson")
|
||||||
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
|
relocate("it.unimi.dsi.fastutil", "com.viaversion.viaversion.libs.fastutil")
|
||||||
relocate("net.lenni0451.mcstructs", "com.viaversion.viaversion.libs.mcstructs")
|
relocate("net.lenni0451.mcstructs", "com.viaversion.viaversion.libs.mcstructs")
|
||||||
|
relocate("org.yaml.snakeyaml", "com.viaversion.viaversion.libs.snakeyaml")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ShadowJar.configureExcludes() {
|
fun ShadowJar.configureExcludes() {
|
||||||
|
@ -3,13 +3,11 @@ dependencies {
|
|||||||
api(rootProject.libs.text) {
|
api(rootProject.libs.text) {
|
||||||
exclude("com.google.code.gson", "gson")
|
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'
|
// 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.netty)
|
||||||
testImplementation(rootProject.libs.guava)
|
testImplementation(rootProject.libs.guava)
|
||||||
testImplementation(rootProject.libs.snakeYaml2)
|
testImplementation(rootProject.libs.snakeYaml)
|
||||||
testImplementation(rootProject.libs.bundles.junit)
|
testImplementation(rootProject.libs.bundles.junit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
package com.viaversion.viaversion.util;
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
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.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -34,19 +31,32 @@ import java.util.concurrent.ConcurrentSkipListMap;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
import org.yaml.snakeyaml.LoaderOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
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")
|
@SuppressWarnings("VulnerableCodeUsages")
|
||||||
public abstract class Config {
|
public abstract class Config {
|
||||||
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);
|
||||||
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 CommentStore commentStore = new CommentStore('.', 2);
|
||||||
private final File configFile;
|
private final File configFile;
|
||||||
protected final Logger logger;
|
protected final Logger logger;
|
||||||
@ -254,4 +264,4 @@ public abstract class Config {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
api(projects.compat.snakeyamlCompatCommon)
|
|
||||||
api(projects.compat.snakeyaml2Compat)
|
|
||||||
api(projects.compat.snakeyaml1Compat)
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
compileOnly(rootProject.libs.snakeYaml2)
|
|
||||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
api(projects.compat.snakeyamlCompatCommon)
|
|
||||||
compileOnly(rootProject.libs.snakeYaml)
|
|
||||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
api(projects.compat.snakeyamlCompatCommon)
|
|
||||||
compileOnly(rootProject.libs.snakeYaml2)
|
|
||||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,8 +10,7 @@ mcstructs = "5-2.5.0-SNAPSHOT"
|
|||||||
# Common provided
|
# Common provided
|
||||||
netty = "4.0.20.Final"
|
netty = "4.0.20.Final"
|
||||||
guava = "17.0"
|
guava = "17.0"
|
||||||
snakeYaml = "1.18"
|
snakeYaml = "2.2"
|
||||||
snakeYaml2 = "2.0"
|
|
||||||
|
|
||||||
junit = "5.10.2"
|
junit = "5.10.2"
|
||||||
checkerQual = "3.43.0"
|
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" }
|
netty = { group = "io.netty", name = "netty-all", version.ref = "netty" }
|
||||||
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
|
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
|
||||||
snakeYaml = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeYaml" }
|
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" }
|
jupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
|
||||||
jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
|
jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
|
||||||
|
@ -24,8 +24,6 @@ rootProject.name = "viaversion-parent"
|
|||||||
|
|
||||||
includeBuild("build-logic")
|
includeBuild("build-logic")
|
||||||
|
|
||||||
include("compat", "compat:snakeyaml-compat-common", "compat:snakeyaml2-compat", "compat:snakeyaml1-compat")
|
|
||||||
|
|
||||||
setupViaSubproject("api")
|
setupViaSubproject("api")
|
||||||
setupViaSubproject("common")
|
setupViaSubproject("common")
|
||||||
setupViaSubproject("bukkit")
|
setupViaSubproject("bukkit")
|
||||||
|
Loading…
Reference in New Issue
Block a user