3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-25 15:50:10 +01:00

Improve Gradle scripts

Don't create runnable platform jars anymore, since all they really do is increase build time. Also fix texts and Gradle deprecations. Also also publish common with its shadowed configuration, not the plain java components.
Dieser Commit ist enthalten in:
Nassim Jahnke 2023-11-06 13:11:35 +10:00
Ursprung 0474810b8d
Commit e356a35aa7
20 geänderte Dateien mit 51 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,6 @@
plugins {
id("net.kyori.blossom")
id("org.jetbrains.gradle.plugin.idea-ext")
id("via.shadow-conventions")
}
sourceSets {

Datei anzeigen

@ -61,7 +61,9 @@ public class StringType extends Type<String> {
@Override
public void write(ByteBuf buffer, String object) throws Exception {
Preconditions.checkArgument(object.length() <= maxLength, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", object.length());
if (object.length() > maxLength) {
throw new IllegalArgumentException("Cannot send string longer than Short.MAX_VALUE characters (got " + object.length() + " characters)");
}
byte[] b = object.getBytes(StandardCharsets.UTF_8);
Type.VAR_INT.writePrimitive(buffer, b.length);

Datei anzeigen

@ -30,27 +30,21 @@ private fun Project.configurePublication(configurer: MavenPublication.() -> Unit
}
fun Project.latestCommitHash(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
}
fun Project.latestCommitMessage(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "log", "-1", "--pretty=%B")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
return runGitCommand(listOf("log", "-1", "--pretty=%B"))
}
fun Project.branchName(): String {
return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD"))
}
fun Project.runGitCommand(args: List<String>): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
commandLine = listOf("git") + args
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()

Datei anzeigen

@ -15,10 +15,12 @@ tasks {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
compileJava {
//options.release.set(8)
options.encoding = Charsets.UTF_8.name()
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-unchecked", "-Xlint:-deprecation"))
}
test {
useJUnitPlatform()
}
}
java {

Datei anzeigen

@ -1,12 +0,0 @@
import java.util.*
plugins {
id("via.shadow-conventions")
}
tasks {
shadowJar {
archiveFileName.set("ViaVersion-${project.name.substringAfter("viaversion-").replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}-${project.version}.jar")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
}
}

Datei anzeigen

@ -1,5 +1,3 @@
import org.gradle.api.plugins.JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME
plugins {
base
id("via.build-logic")
@ -11,7 +9,10 @@ allprojects {
description = "Allow newer clients to join older server versions."
}
val platforms = setOf(
val main = setOf(
projects.viaversion,
projects.viaversionCommon,
projects.viaversionApi,
projects.viaversionBukkit,
projects.viaversionBungee,
projects.viaversionFabric,
@ -20,23 +21,13 @@ val platforms = setOf(
).map { it.dependencyProject }
val special = setOf(
projects.viaversion,
projects.viaversionApi,
projects.adventure
).map { it.dependencyProject }
subprojects {
when (this) {
in platforms -> plugins.apply("via.platform-conventions")
in main -> plugins.apply("via.shadow-conventions")
in special -> plugins.apply("via.base-conventions")
else -> plugins.apply("via.standard-conventions")
}
// Note: If manually starting tests doesn't work for you in IJ, change 'Gradle -> Run Tests Using' to 'IntelliJ IDEA'
dependencies {
// The alternative to this long boi is writing "testImplementation", including the quotes
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.netty)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.guava)
TEST_IMPLEMENTATION_CONFIGURATION_NAME(rootProject.libs.bundles.junit)
}
}

Datei anzeigen

@ -1,5 +1,5 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.legacyBukkit) {
exclude("junit", "junit")
exclude("com.google.code.gson", "gson")

Datei anzeigen

@ -1,6 +1,6 @@
dependencies {
implementation(projects.viaversionBukkitLegacy)
implementation(projects.viaversionCommon)
compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.paper) {
exclude("junit", "junit")
exclude("com.google.code.gson", "gson")

Datei anzeigen

@ -72,7 +72,7 @@ public final class ProtocolSupportCompat {
} catch (NoSuchMethodException ignored) {
}
// Check for obfusacted b/c methods
// Check for obfuscated b/c methods
try {
if (clazz.getMethod("b").getReturnType() == int.class) {
return HandshakeProtocolType.OBFUSCATED_B;

Datei anzeigen

@ -1,4 +1,4 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.bungee)
}

Datei anzeigen

@ -3,6 +3,12 @@ dependencies {
api(projects.viaversionApiLegacy)
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.bundles.junit)
}
java {

Datei anzeigen

@ -32,9 +32,10 @@ public class ProtocolVersionTest {
@Test
void testVersionRange() {
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.0"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.1"));
Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20"));
Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20.0"));
Assertions.assertEquals(ProtocolVersion.v1_20, ProtocolVersion.getClosest("1.20.1"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.2"));
Assertions.assertEquals(ProtocolVersion.v1_7_1, ProtocolVersion.getClosest("1.7.5"));
}

Datei anzeigen

@ -38,7 +38,7 @@ public class ItemTypeTest {
// Test item read
Assertions.assertEquals(
new DataItem((int) Short.MAX_VALUE, (byte) -128, (short) 257, null),
new DataItem(Short.MAX_VALUE, (byte) -128, (short) 257, null),
Type.ITEM1_8.read(Unpooled.wrappedBuffer(new byte[]{
127, -1,
-128,
@ -83,7 +83,7 @@ public class ItemTypeTest {
ByteBuf buf = Unpooled.buffer();
// Test item write
Type.ITEM1_8.write(buf, new DataItem((int) Short.MAX_VALUE, (byte) -128, (short) 257, null));
Type.ITEM1_8.write(buf, new DataItem(Short.MAX_VALUE, (byte) -128, (short) 257, null));
Assertions.assertArrayEquals(toBytes(buf), new byte[]{
127, -1,
-128,

Datei anzeigen

@ -23,7 +23,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
public class StringTypeTest {
@Test
@ -41,45 +40,29 @@ public class StringTypeTest {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]));
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]).replace("\0", "ç"));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]).replace("\0", "ç"));
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE]).replace("\0", "a"));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE]).replace("\0", "a"));
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD"));
Assertions.assertEquals(Type.STRING.read(buf), new String(new char[Short.MAX_VALUE / 2]).replace("\0", "\uD83E\uDDFD"));
}
@Test
public void testStringReadOverflowException() throws Exception {
public void testStringReadOverflowException() {
// Read exception
final ByteBuf buf = Unpooled.buffer();
Type.VAR_INT.writePrimitive(buf, (Short.MAX_VALUE + 1) * 4);
for (int i = 0; i < Short.MAX_VALUE / 2 + 1; i++) {
buf.writeBytes(new byte[]{0x04, (byte) 0xf0, (byte) 0x9f, (byte) 0xa7, (byte) 0xbd}); // Sponge emoji
}
Assertions.assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() throws Throwable {
Type.STRING.read(buf);
}
});
Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.read(buf));
}
@Test
public void testStringWriteOverflowException() {
// Write exceptions
final ByteBuf buf = Unpooled.buffer();
Assertions.assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() throws Throwable {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2 + 1]).replace("\0", "\uD83E\uDDFD"));
}
});
Assertions.assertThrows(IllegalArgumentException.class, new Executable() {
@Override
public void execute() throws Throwable {
Type.STRING.write(buf, new String(new char[Short.MAX_VALUE + 1]));
}
});
Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2 + 1]).replace("\0", "\uD83E\uDDFD")));
Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.write(buf, new String(new char[Short.MAX_VALUE + 1])));
}
}

Datei anzeigen

@ -1,3 +1,2 @@
dependencies {
implementation(projects.viaversionCommon)
}

Datei anzeigen

@ -22,7 +22,6 @@ paper = "1.16.5-R0.1-SNAPSHOT"
legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
bungee = "1.19-R0.1-SNAPSHOT"
sponge = "8.0.0"
legacySponge = "4.0.0"
velocity = "3.1.1"
@ -52,7 +51,6 @@ paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "
legacyBukkit = { group = "org.bukkit", name = "bukkit", version.ref = "legacyBukkit" }
bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" }
sponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "sponge" }
legacySponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "legacySponge" }
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }

Datei anzeigen

@ -1,4 +1,4 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.sponge)
}

Datei anzeigen

@ -1,3 +1,3 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnly(projects.viaversionCommon)
}

Datei anzeigen

@ -1,48 +1,26 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.hangarpublishplugin.model.Platforms
plugins {
id("com.github.johnrengelman.shadow")
id("io.papermc.hangar-publish-plugin") version "0.1.0"
id("com.modrinth.minotaur") version "2.+"
}
val platforms = setOf(
rootProject.projects.viaversionBukkit,
rootProject.projects.viaversionBungee,
rootProject.projects.viaversionFabric,
rootProject.projects.viaversionSponge,
rootProject.projects.viaversionVelocity
).map { it.dependencyProject }
dependencies {
api(projects.viaversionCommon)
api(projects.viaversionBukkit)
api(projects.viaversionBungee)
api(projects.viaversionFabric)
api(projects.viaversionSponge)
api(projects.viaversionVelocity)
}
tasks {
shadowJar {
archiveClassifier.set("")
archiveFileName.set("ViaVersion-${project.version}.jar")
destinationDirectory.set(rootProject.projectDir.resolve("build/libs"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
platforms.forEach { platform ->
val shadowJarTask = platform.tasks.named<ShadowJar>("shadowJar").forUseAtConfigurationTime().get()
dependsOn(shadowJarTask)
dependsOn(platform.tasks.withType<Jar>())
from(zipTree(shadowJarTask.archiveFile))
}
}
build {
dependsOn(shadowJar)
}
sourcesJar {
rootProject.subprojects.forEach { subproject ->
if (subproject == project) return@forEach
val platformSourcesJarTask = subproject.tasks.findByName("sourcesJar") as? Jar ?: return@forEach
dependsOn(platformSourcesJarTask)
from(zipTree(platformSourcesJarTask.archiveFile))
}
}
}
publishShadowJar()
val branch = rootProject.branchName()
val baseVersion = project.version as String
val isRelease = !baseVersion.contains('-')

Datei anzeigen

@ -1,5 +1,5 @@
dependencies {
implementation(projects.viaversionCommon)
compileOnlyApi(projects.viaversionCommon)
compileOnly(libs.velocity) {
// Requires Java 11
exclude("com.velocitypowered", "velocity-brigadier")