From ee0e5df98c09536662af356f9ebeca2bbff1548b Mon Sep 17 00:00:00 2001 From: modmuss Date: Mon, 6 Nov 2023 10:40:49 +0000 Subject: [PATCH] Fix server only jars. (#968) * Actally fix server only jars. * Cleanup the single jar names --- .../providers/minecraft/MinecraftJar.java | 39 +++++++++++++++---- .../minecraft/MinecraftSourceSets.java | 12 +++--- .../providers/minecraft/SingleJarEnvType.java | 12 ++++-- .../mapped/MappedMinecraftProvider.java | 8 ++-- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJar.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJar.java index 6686a1311..311d20212 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJar.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftJar.java @@ -28,7 +28,7 @@ import java.nio.file.Path; import java.util.Objects; -public abstract sealed class MinecraftJar permits MinecraftJar.Merged, MinecraftJar.Common, MinecraftJar.ServerOnly, MinecraftJar.ClientOnly { +public abstract sealed class MinecraftJar permits MinecraftJar.Client, MinecraftJar.ClientOnly, MinecraftJar.Common, MinecraftJar.Merged, MinecraftJar.Server { private final Path path; private final boolean merged, client, server; private final String name; @@ -68,8 +68,10 @@ public String getName() { public abstract MinecraftJar forPath(Path path); public static final class Merged extends MinecraftJar { + public static final String NAME = "merged"; + public Merged(Path path) { - super(path, true, true, true, "merged"); + super(path, true, true, true, NAME); } @Override @@ -79,8 +81,10 @@ public MinecraftJar forPath(Path path) { } public static final class Common extends MinecraftJar { + public static final String NAME = "common"; + public Common(Path path) { - super(path, false, false, true, "common"); + super(path, false, false, true, NAME); } @Override @@ -89,20 +93,39 @@ public MinecraftJar forPath(Path path) { } } - public static final class ServerOnly extends MinecraftJar { - public ServerOnly(Path path) { - super(path, false, false, true, "serverOnly"); + public static final class Server extends MinecraftJar { + public static final String NAME = "server"; + + public Server(Path path) { + super(path, false, false, true, NAME); + } + + @Override + public MinecraftJar forPath(Path path) { + return new Server(path); + } + } + + // Un-split client jar + public static final class Client extends MinecraftJar { + public static final String NAME = "client"; + + public Client(Path path) { + super(path, false, true, false, NAME); } @Override public MinecraftJar forPath(Path path) { - return new ServerOnly(path); + return new Client(path); } } + // Split client jar public static final class ClientOnly extends MinecraftJar { + public static final String NAME = "clientOnly"; + public ClientOnly(Path path) { - super(path, false, true, false, "clientOnly"); + super(path, false, true, false, NAME); } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftSourceSets.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftSourceSets.java index 7542ea282..683aacb9d 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftSourceSets.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftSourceSets.java @@ -152,13 +152,13 @@ public static final class Split extends MinecraftSourceSets { @Override public void applyDependencies(BiConsumer consumer, List targets) { Preconditions.checkArgument(targets.size() == 2); - Preconditions.checkArgument(targets.contains("common")); - Preconditions.checkArgument(targets.contains("clientOnly")); + Preconditions.checkArgument(targets.contains(MinecraftJar.Common.NAME)); + Preconditions.checkArgument(targets.contains(MinecraftJar.ClientOnly.NAME)); - consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), "common"); - consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), "clientOnly"); - consumer.accept(MINECRAFT_COMMON_NAMED.compile(), "common"); - consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), "clientOnly"); + consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), MinecraftJar.Common.NAME); + consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), MinecraftJar.ClientOnly.NAME); + consumer.accept(MINECRAFT_COMMON_NAMED.compile(), MinecraftJar.Common.NAME); + consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), MinecraftJar.ClientOnly.NAME); } @Override diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/SingleJarEnvType.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/SingleJarEnvType.java index 7063c166b..1101de5f0 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/SingleJarEnvType.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/SingleJarEnvType.java @@ -28,16 +28,22 @@ import java.util.function.Function; public enum SingleJarEnvType { - CLIENT(MinecraftJar.ClientOnly::new), - SERVER(MinecraftJar.ServerOnly::new); + CLIENT(MinecraftJar.Client::new, MinecraftJar.Client.NAME), + SERVER(MinecraftJar.Server::new, MinecraftJar.Server.NAME); private final Function jarFunction; + private final String name; - SingleJarEnvType(Function jarFunction) { + SingleJarEnvType(Function jarFunction, String name) { this.jarFunction = jarFunction; + this.name = name; } public Function getJar() { return jarFunction; } + + public String getName() { + return name; + } } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/MappedMinecraftProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/MappedMinecraftProvider.java index 4ea323493..68a5cdc85 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/MappedMinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/MappedMinecraftProvider.java @@ -42,7 +42,7 @@ interface ProviderImpl extends MappedMinecraftProvider { } interface Merged extends ProviderImpl { - String MERGED = "merged"; + String MERGED = MinecraftJar.Merged.NAME; default MinecraftJar getMergedJar() { return new MinecraftJar.Merged(getJar(MERGED)); @@ -55,8 +55,8 @@ default List getMinecraftJars() { } interface Split extends ProviderImpl { - String COMMON = "common"; - String CLIENT_ONLY = "clientOnly"; + String COMMON = MinecraftJar.Common.NAME; + String CLIENT_ONLY = MinecraftJar.ClientOnly.NAME; default MinecraftJar getCommonJar() { return new MinecraftJar.Common(getJar(COMMON)); @@ -76,7 +76,7 @@ interface SingleJar extends ProviderImpl { SingleJarEnvType env(); default String envName() { - return "%sOnly".formatted(env()); + return env().getName(); } default MinecraftJar getEnvOnlyJar() {