Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +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.
Dieser Commit ist enthalten in:
Ursprung
864beef341
Commit
60b3ba6bb7
@ -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)
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
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" }
|
||||
|
@ -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")
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren