From 73dd214ae66bab483ee8b4f0ed03881466da92e8 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 12 Jul 2022 22:37:59 +0100 Subject: Improve/fix game thread dumper --- .../me/lucko/spark/bukkit/BukkitSparkPlugin.java | 7 +++-- .../spark/bukkit/BukkitWorldInfoProvider.java | 1 - .../lucko/spark/common/sampler/ThreadDumper.java | 10 ++++--- .../fabric/mixin/MinecraftClientAccessor.java | 34 ++++++++++++++++++++++ .../fabric/plugin/FabricClientSparkPlugin.java | 10 ++++++- .../fabric/plugin/FabricServerSparkPlugin.java | 9 +++++- .../spark/fabric/plugin/FabricSparkPlugin.java | 7 ----- spark-fabric/src/main/resources/spark.mixins.json | 3 +- .../spark/forge/plugin/ForgeClientSparkPlugin.java | 9 +++++- .../spark/forge/plugin/ForgeServerSparkPlugin.java | 9 +++++- .../lucko/spark/forge/plugin/ForgeSparkPlugin.java | 7 ----- .../main/resources/META-INF/accesstransformer.cfg | 1 + .../me/lucko/spark/sponge/Sponge7SparkPlugin.java | 7 +++-- .../me/lucko/spark/sponge/Sponge8SparkPlugin.java | 7 +++-- 14 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java index fddd66b..5737d3d 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java @@ -50,14 +50,16 @@ import java.util.stream.Stream; public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin { private BukkitAudiences audienceFactory; + private ThreadDumper gameThreadDumper; + private SparkPlatform platform; private CommandExecutor tpsCommand = null; - private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); @Override public void onEnable() { this.audienceFactory = BukkitAudiences.create(this); + this.gameThreadDumper = new ThreadDumper.Specific(Thread.currentThread()); this.platform = new SparkPlatform(this); this.platform.enable(); @@ -102,7 +104,6 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - this.threadDumper.ensureSetup(); this.platform.executeCommand(new BukkitCommandSender(sender, this.audienceFactory), args); return true; } @@ -152,7 +153,7 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin { @Override public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); + return this.gameThreadDumper; } @Override diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java index f34899b..5d50eeb 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java @@ -31,7 +31,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class BukkitWorldInfoProvider implements WorldInfoProvider { diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index 9d54f50..fe3a6a7 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -83,10 +83,8 @@ public interface ThreadDumper { return Objects.requireNonNull(this.dumper, "dumper"); } - public void ensureSetup() { - if (this.dumper == null) { - this.dumper = new Specific(new long[]{Thread.currentThread().getId()}); - } + public void setThread(Thread thread) { + this.dumper = new Specific(new long[]{thread.getId()}); } } @@ -98,6 +96,10 @@ public interface ThreadDumper { private Set threads; private Set threadNamesLowerCase; + public Specific(Thread thread) { + this.ids = new long[]{thread.getId()}; + } + public Specific(long[] ids) { this.ids = ids; } diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java new file mode 100644 index 0000000..7a4fb78 --- /dev/null +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/mixin/MinecraftClientAccessor.java @@ -0,0 +1,34 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * Copyright (c) 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 me.lucko.spark.fabric.mixin; + +import net.minecraft.client.MinecraftClient; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(MinecraftClient.class) +public interface MinecraftClientAccessor { + + @Accessor + Thread getThread(); + +} diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java index 1876658..19d0707 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java @@ -30,6 +30,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder; import me.lucko.spark.common.platform.PlatformInfo; import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; import me.lucko.spark.fabric.FabricCommandSender; @@ -38,6 +39,7 @@ import me.lucko.spark.fabric.FabricSparkMod; import me.lucko.spark.fabric.FabricTickHook; import me.lucko.spark.fabric.FabricTickReporter; import me.lucko.spark.fabric.FabricWorldInfoProvider; +import me.lucko.spark.fabric.mixin.MinecraftClientAccessor; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -57,10 +59,12 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman } private final MinecraftClient minecraft; + private final ThreadDumper gameThreadDumper; public FabricClientSparkPlugin(FabricSparkMod mod, MinecraftClient minecraft) { super(mod); this.minecraft = minecraft; + this.gameThreadDumper = new ThreadDumper.Specific(((MinecraftClientAccessor) minecraft).getThread()); } @Override @@ -89,7 +93,6 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman return 0; } - this.threadDumper.ensureSetup(); this.platform.executeCommand(new FabricCommandSender(context.getSource().getEntity(), this), args); return Command.SINGLE_SUCCESS; } @@ -119,6 +122,11 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman this.minecraft.executeSync(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new FabricTickHook.Client(); diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java index bb1d68c..f840f5e 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java @@ -33,6 +33,7 @@ import me.lucko.spark.common.monitor.ping.PlayerPingProvider; import me.lucko.spark.common.platform.PlatformInfo; import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider; import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; import me.lucko.spark.fabric.FabricCommandSender; @@ -63,10 +64,12 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman } private final MinecraftServer server; + private final ThreadDumper gameThreadDumper; public FabricServerSparkPlugin(FabricSparkMod mod, MinecraftServer server) { super(mod); this.server = server; + this.gameThreadDumper = new ThreadDumper.Specific(server.getThread()); } @Override @@ -97,7 +100,6 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman return 0; } - this.threadDumper.ensureSetup(); CommandOutput source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer(); this.platform.executeCommand(new FabricCommandSender(source, this), args); return Command.SINGLE_SUCCESS; @@ -135,6 +137,11 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman this.server.executeSync(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new FabricTickHook.Server(); diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java index b1392d4..3126f28 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java @@ -34,7 +34,6 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; import me.lucko.spark.common.command.sender.CommandSender; -import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.util.ClassSourceLookup; import me.lucko.spark.common.util.SparkThreadFactory; import me.lucko.spark.fabric.FabricClassSourceLookup; @@ -59,7 +58,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin { protected final ScheduledExecutorService scheduler; protected SparkPlatform platform; - protected final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); protected FabricSparkPlugin(FabricSparkMod mod) { this.mod = mod; @@ -107,11 +105,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin { } } - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - @Override public ClassSourceLookup createClassSourceLookup() { return new FabricClassSourceLookup(); diff --git a/spark-fabric/src/main/resources/spark.mixins.json b/spark-fabric/src/main/resources/spark.mixins.json index 09587fe..e75b34f 100644 --- a/spark-fabric/src/main/resources/spark.mixins.json +++ b/spark-fabric/src/main/resources/spark.mixins.json @@ -5,7 +5,8 @@ "mixins": [], "client": [ "ClientEntityManagerAccessor", - "ClientWorldAccessor" + "ClientWorldAccessor", + "MinecraftClientAccessor" ], "server": [ "ServerEntityManagerAccessor", diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 04c8785..a4c6bd1 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -29,6 +29,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder; import me.lucko.spark.common.platform.PlatformInfo; import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; import me.lucko.spark.forge.ForgeCommandSender; @@ -58,10 +59,12 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< } private final Minecraft minecraft; + private final ThreadDumper gameThreadDumper; public ForgeClientSparkPlugin(ForgeSparkMod mod, Minecraft minecraft) { super(mod); this.minecraft = minecraft; + this.gameThreadDumper = new ThreadDumper.Specific(minecraft.gameThread); } @Override @@ -84,7 +87,6 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< return 0; } - this.threadDumper.ensureSetup(); this.platform.executeCommand(new ForgeCommandSender(context.getSource().getEntity(), this), args); return Command.SINGLE_SUCCESS; } @@ -114,6 +116,11 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Command< this.minecraft.executeIfPossible(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new ForgeTickHook(TickEvent.Type.CLIENT); diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index f4a51e0..1aeb2b1 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -33,6 +33,7 @@ import me.lucko.spark.common.monitor.ping.PlayerPingProvider; import me.lucko.spark.common.platform.PlatformInfo; import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider; import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.tick.TickHook; import me.lucko.spark.common.tick.TickReporter; import me.lucko.spark.forge.ForgeCommandSender; @@ -75,11 +76,13 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< } private final MinecraftServer server; + private final ThreadDumper gameThreadDumper; private Map> registeredPermissions = Collections.emptyMap(); public ForgeServerSparkPlugin(ForgeSparkMod mod, MinecraftServer server) { super(mod); this.server = server; + this.gameThreadDumper = new ThreadDumper.Specific(server.getRunningThread()); } @Override @@ -146,7 +149,6 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< return 0; } - this.threadDumper.ensureSetup(); CommandSource source = context.getSource().getEntity() != null ? context.getSource().getEntity() : context.getSource().getServer(); this.platform.executeCommand(new ForgeCommandSender(source, this), args); return Command.SINGLE_SUCCESS; @@ -192,6 +194,11 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< this.server.executeIfPossible(task); } + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.gameThreadDumper; + } + @Override public TickHook createTickHook() { return new ForgeTickHook(TickEvent.Type.SERVER); diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index f257e34..36a7ce8 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java @@ -34,7 +34,6 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; import me.lucko.spark.common.command.sender.CommandSender; -import me.lucko.spark.common.sampler.ThreadDumper; import me.lucko.spark.common.util.ClassSourceLookup; import me.lucko.spark.common.util.SparkThreadFactory; import me.lucko.spark.forge.ForgeClassSourceLookup; @@ -59,7 +58,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { protected final ScheduledExecutorService scheduler; protected SparkPlatform platform; - protected final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); protected ForgeSparkPlugin(ForgeSparkMod mod) { this.mod = mod; @@ -107,11 +105,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { } } - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - @Override public ClassSourceLookup createClassSourceLookup() { return new ForgeClassSourceLookup(); diff --git a/spark-forge/src/main/resources/META-INF/accesstransformer.cfg b/spark-forge/src/main/resources/META-INF/accesstransformer.cfg index 1e418b8..39e9c1a 100644 --- a/spark-forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/spark-forge/src/main/resources/META-INF/accesstransformer.cfg @@ -2,3 +2,4 @@ public net.minecraft.server.level.ServerLevel f_143244_ # entityManager public net.minecraft.world.level.entity.PersistentEntitySectionManager f_157495_ # sectionStorage public net.minecraft.client.multiplayer.ClientLevel f_171631_ # entityStorage public net.minecraft.world.level.entity.TransientEntitySectionManager f_157638_ # sectionStorage +public net.minecraft.client.Minecraft f_91018_ # gameThread \ No newline at end of file diff --git a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java index 324e242..e6c9a04 100644 --- a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java +++ b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java @@ -73,9 +73,9 @@ public class Sponge7SparkPlugin implements SparkPlugin { private final Path configDirectory; private final SpongeExecutorService asyncExecutor; private final SpongeExecutorService syncExecutor; + private final ThreadDumper.GameThread gameThreadDumper = new ThreadDumper.GameThread(); private SparkPlatform platform; - private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); @Inject public Sponge7SparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor, @SynchronousExecutor SpongeExecutorService syncExecutor) { @@ -85,6 +85,8 @@ public class Sponge7SparkPlugin implements SparkPlugin { this.configDirectory = configDirectory; this.asyncExecutor = asyncExecutor; this.syncExecutor = syncExecutor; + + this.syncExecutor.execute(() -> this.gameThreadDumper.setThread(Thread.currentThread())); } @Listener @@ -151,7 +153,7 @@ public class Sponge7SparkPlugin implements SparkPlugin { @Override public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); + return this.gameThreadDumper.get(); } @Override @@ -201,7 +203,6 @@ public class Sponge7SparkPlugin implements SparkPlugin { @Override public CommandResult process(CommandSource source, String arguments) { - this.plugin.threadDumper.ensureSetup(); this.plugin.platform.executeCommand(new Sponge7CommandSender(source), arguments.split(" ")); return CommandResult.empty(); } diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java index 68e47e3..70e73b9 100644 --- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java +++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java @@ -69,9 +69,9 @@ public class Sponge8SparkPlugin implements SparkPlugin { private final Path configDirectory; private final ExecutorService asyncExecutor; private final ExecutorService syncExecutor; + private final ThreadDumper.GameThread gameThreadDumper = new ThreadDumper.GameThread(); private SparkPlatform platform; - private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); @Inject public Sponge8SparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory) { @@ -88,6 +88,8 @@ public class Sponge8SparkPlugin implements SparkPlugin { } else { throw new IllegalStateException("Server and client both unavailable"); } + + this.syncExecutor.execute(() -> this.gameThreadDumper.setThread(Thread.currentThread())); } @@ -159,7 +161,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); + return this.gameThreadDumper.get(); } @Override @@ -204,7 +206,6 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) { - this.plugin.threadDumper.ensureSetup(); this.plugin.platform.executeCommand(new Sponge8CommandSender(cause), arguments.input().split(" ")); return CommandResult.success(); } -- cgit From 06de991f44f3f0f33eed21fb92224a395a2a92ff Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 13 Jul 2022 21:10:28 +0100 Subject: Support linux x64 musl --- spark-common/build.gradle | 9 +------- .../common/sampler/async/AsyncProfilerAccess.java | 24 +++++++++++++++++++++ .../spark/linux/aarch64/libasyncProfiler.so | Bin 328432 -> 333864 bytes .../spark/linux/amd64-musl/libasyncProfiler.so | Bin 0 -> 304568 bytes .../spark/linux/amd64/libasyncProfiler.so | Bin 342239 -> 347712 bytes .../main/resources/spark/macos/libasyncProfiler.so | Bin 688400 -> 690128 bytes 6 files changed, 25 insertions(+), 8 deletions(-) create mode 100755 spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so diff --git a/spark-common/build.gradle b/spark-common/build.gradle index bc493f3..fbd0db2 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -8,7 +8,7 @@ license { dependencies { api project(':spark-api') - implementation 'com.github.jvm-profiling-tools:async-profiler:v2.7' + implementation 'com.github.jvm-profiling-tools:async-profiler:v2.8.1' implementation 'org.ow2.asm:asm:9.1' implementation 'com.google.protobuf:protobuf-javalite:3.15.6' implementation 'com.squareup.okhttp3:okhttp:3.14.1' @@ -37,13 +37,6 @@ dependencies { compileOnly 'org.checkerframework:checker-qual:3.8.0' } -processResources { - from(sourceSets.main.resources.srcDirs) { - include 'spark/linux/libasyncProfiler.so' - include 'spark/macosx/libasyncProfiler.so' - } -} - protobuf { protoc { if (System.getProperty("os.name") == "Mac OS X" && System.getProperty("os.arch") == "aarch64") { diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java index d642a53..ef2c035 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncProfilerAccess.java @@ -29,13 +29,16 @@ import me.lucko.spark.common.util.TemporaryFiles; import one.profiler.AsyncProfiler; import one.profiler.Events; +import java.io.BufferedReader; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.Locale; import java.util.logging.Level; +import java.util.stream.Collectors; /** * Provides a bridge between spark and async-profiler. @@ -108,8 +111,13 @@ public enum AsyncProfilerAccess { String os = System.getProperty("os.name").toLowerCase(Locale.ROOT).replace(" ", ""); String arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT); + if (os.equals("linux") && arch.equals("amd64") && isLinuxMusl()) { + arch = "amd64-musl"; + } + Table supported = ImmutableTable.builder() .put("linux", "amd64", "linux/amd64") + .put("linux", "amd64-musl", "linux/amd64-musl") .put("linux", "aarch64", "linux/aarch64") .put("macosx", "amd64", "macos") .put("macosx", "aarch64", "macos") @@ -190,4 +198,20 @@ public enum AsyncProfilerAccess { super("A runtime error occurred whilst loading the native library", cause); } } + + // Checks if the system is using musl instead of glibc + private static boolean isLinuxMusl() { + try { + InputStream stream = new ProcessBuilder("sh", "-c", "ldd `which ls`") + .start() + .getInputStream(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String output = reader.lines().collect(Collectors.joining()); + return output.contains("musl"); // shrug + } catch (Throwable e) { + // ignore + return false; + } + } } diff --git a/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so index 35f83b2..c3c2eb2 100755 Binary files a/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so and b/spark-common/src/main/resources/spark/linux/aarch64/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so new file mode 100755 index 0000000..4c69ab8 Binary files /dev/null and b/spark-common/src/main/resources/spark/linux/amd64-musl/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so b/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so index edbf103..5612ad9 100755 Binary files a/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so and b/spark-common/src/main/resources/spark/linux/amd64/libasyncProfiler.so differ diff --git a/spark-common/src/main/resources/spark/macos/libasyncProfiler.so b/spark-common/src/main/resources/spark/macos/libasyncProfiler.so index ab818e9..1fc6ba3 100755 Binary files a/spark-common/src/main/resources/spark/macos/libasyncProfiler.so and b/spark-common/src/main/resources/spark/macos/libasyncProfiler.so differ -- cgit From 319aae27ad290338a5558ac53517e144254a86ce Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 17 Jul 2022 12:19:03 +0100 Subject: Fix fabric client startup error --- .../java/me/lucko/spark/common/sampler/ThreadDumper.java | 14 ++++++++++++++ .../lucko/spark/fabric/plugin/FabricClientSparkPlugin.java | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index fe3a6a7..fd0c413 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -76,10 +76,24 @@ public interface ThreadDumper { * the game (server/client) thread. */ final class GameThread implements Supplier { + private Supplier threadSupplier; private Specific dumper = null; + public GameThread() { + + } + + public GameThread(Supplier threadSupplier) { + this.threadSupplier = threadSupplier; + } + @Override public ThreadDumper get() { + if (this.dumper == null) { + setThread(this.threadSupplier.get()); + this.threadSupplier = null; + } + return Objects.requireNonNull(this.dumper, "dumper"); } diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java index 19d0707..0ef6620 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java @@ -59,12 +59,12 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman } private final MinecraftClient minecraft; - private final ThreadDumper gameThreadDumper; + private final ThreadDumper.GameThread gameThreadDumper; public FabricClientSparkPlugin(FabricSparkMod mod, MinecraftClient minecraft) { super(mod); this.minecraft = minecraft; - this.gameThreadDumper = new ThreadDumper.Specific(((MinecraftClientAccessor) minecraft).getThread()); + this.gameThreadDumper = new ThreadDumper.GameThread(() -> ((MinecraftClientAccessor) minecraft).getThread()); } @Override @@ -124,7 +124,7 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman @Override public ThreadDumper getDefaultThreadDumper() { - return this.gameThreadDumper; + return this.gameThreadDumper.get(); } @Override -- cgit From 36ac0700f6eaab4404b7dbca8537af8a6ac681a7 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 17 Jul 2022 12:27:04 +0100 Subject: Fix sponge8 enable --- .../me/lucko/spark/sponge/Sponge8SparkPlugin.java | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java index 70e73b9..83b2ec2 100644 --- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java +++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java @@ -20,6 +20,7 @@ package me.lucko.spark.sponge; +import com.google.common.base.Suppliers; import com.google.inject.Inject; import me.lucko.spark.common.SparkPlatform; @@ -56,6 +57,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -68,7 +70,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { private final Game game; private final Path configDirectory; private final ExecutorService asyncExecutor; - private final ExecutorService syncExecutor; + private final Supplier syncExecutor; private final ThreadDumper.GameThread gameThreadDumper = new ThreadDumper.GameThread(); private SparkPlatform platform; @@ -80,16 +82,15 @@ public class Sponge8SparkPlugin implements SparkPlugin { this.game = game; this.configDirectory = configDirectory; this.asyncExecutor = game.asyncScheduler().executor(pluginContainer); - - if (game.isServerAvailable()) { - this.syncExecutor = game.server().scheduler().executor(pluginContainer); - } else if (game.isClientAvailable()) { - this.syncExecutor = game.client().scheduler().executor(pluginContainer); - } else { - throw new IllegalStateException("Server and client both unavailable"); - } - - this.syncExecutor.execute(() -> this.gameThreadDumper.setThread(Thread.currentThread())); + this.syncExecutor = Suppliers.memoize(() -> { + if (this.game.isServerAvailable()) { + return this.game.server().scheduler().executor(this.pluginContainer); + } else if (this.game.isClientAvailable()) { + return this.game.client().scheduler().executor(this.pluginContainer); + } else { + throw new IllegalStateException("Server and client both unavailable"); + } + }); } @@ -100,6 +101,8 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Listener public void onEnable(StartedEngineEvent event) { + executeSync(() -> this.gameThreadDumper.setThread(Thread.currentThread())); + this.platform = new SparkPlatform(this); this.platform.enable(); } @@ -143,7 +146,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public void executeSync(Runnable task) { - this.syncExecutor.execute(task); + this.syncExecutor.get().execute(task); } @Override -- cgit From 814ac81af5c879a669b345a007a2ffbb1256aeb0 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 17 Jul 2022 12:29:43 +0100 Subject: Additional config exclusions on Bukkit --- .../src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java index 4c587fb..d095bed 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java @@ -152,6 +152,8 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider { .add("level-seed") .add("world-settings.*.feature-seeds") .add("world-settings.*.seed-*") + .add("feature-seeds") + .add("seed-*") .addAll(getTimingsHiddenConfigs()) .addAll(getSystemPropertyList("spark.serverconfigs.hiddenpaths")); -- cgit From 768bf7a338da8e5daaebc9580ff3b289092c28ee Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 17 Jul 2022 14:05:06 +0100 Subject: Remove some unnecessary dependencies --- spark-bukkit/build.gradle | 3 - spark-bungeecord/build.gradle | 3 - spark-common/build.gradle | 3 - .../java/me/lucko/spark/common/SparkPlatform.java | 12 +--- .../common/command/modules/HeapAnalysisModule.java | 4 +- .../common/command/modules/SamplerModule.java | 4 +- .../spark/common/util/AbstractHttpClient.java | 46 ------------- .../me/lucko/spark/common/util/BytebinClient.java | 75 ++++++++++------------ .../me/lucko/spark/common/util/Compression.java | 60 ++++++++--------- spark-fabric/build.gradle | 3 - spark-forge/build.gradle | 3 - spark-minestom/build.gradle | 3 - spark-nukkit/build.gradle | 3 - spark-sponge7/build.gradle | 3 - spark-sponge8/build.gradle | 3 - spark-velocity/build.gradle | 3 - spark-velocity4/build.gradle | 3 - spark-waterdog/build.gradle | 3 - 18 files changed, 65 insertions(+), 172 deletions(-) delete mode 100644 spark-common/src/main/java/me/lucko/spark/common/util/AbstractHttpClient.java diff --git a/spark-bukkit/build.gradle b/spark-bukkit/build.gradle index 7144291..917fb55 100644 --- a/spark-bukkit/build.gradle +++ b/spark-bukkit/build.gradle @@ -31,12 +31,9 @@ processResources { shadowJar { archiveName = "spark-${project.pluginVersion}-bukkit.jar" - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-bungeecord/build.gradle b/spark-bungeecord/build.gradle index 1e92621..d96d589 100644 --- a/spark-bungeecord/build.gradle +++ b/spark-bungeecord/build.gradle @@ -21,12 +21,9 @@ processResources { shadowJar { archiveName = "spark-${project.pluginVersion}-bungeecord.jar" - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-common/build.gradle b/spark-common/build.gradle index fbd0db2..ce09d51 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -11,10 +11,7 @@ dependencies { implementation 'com.github.jvm-profiling-tools:async-profiler:v2.8.1' implementation 'org.ow2.asm:asm:9.1' implementation 'com.google.protobuf:protobuf-javalite:3.15.6' - implementation 'com.squareup.okhttp3:okhttp:3.14.1' - implementation 'com.squareup.okio:okio:1.17.3' implementation 'net.bytebuddy:byte-buddy-agent:1.11.0' - implementation 'org.tukaani:xz:1.8' api('net.kyori:adventure-api:4.11.0') { exclude(module: 'adventure-bom') exclude(module: 'checker-qual') diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index 0ef4556..f92abf3 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -54,8 +54,6 @@ import me.lucko.spark.common.util.TemporaryFiles; import net.kyori.adventure.text.event.ClickEvent; -import okhttp3.OkHttpClient; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -93,7 +91,6 @@ public class SparkPlatform { private final SparkPlugin plugin; private final Configuration configuration; private final String viewerUrl; - private final OkHttpClient httpClient; private final BytebinClient bytebinClient; private final boolean disableResponseBroadcast; private final List commandModules; @@ -116,9 +113,7 @@ public class SparkPlatform { this.viewerUrl = this.configuration.getString("viewerUrl", "https://spark.lucko.me/"); String bytebinUrl = this.configuration.getString("bytebinUrl", "https://bytebin.lucko.me/"); - - this.httpClient = new OkHttpClient(); - this.bytebinClient = new BytebinClient(this.httpClient, bytebinUrl, "spark-plugin"); + this.bytebinClient = new BytebinClient(bytebinUrl, "spark-plugin"); this.disableResponseBroadcast = this.configuration.getBoolean("disableResponseBroadcast", false); @@ -198,11 +193,6 @@ public class SparkPlatform { SparkApi.unregister(); TemporaryFiles.deleteTemporaryFiles(); - - // shutdown okhttp - // see: https://github.com/square/okhttp/issues/4029 - this.httpClient.dispatcher().executorService().shutdown(); - this.httpClient.connectionPool().evictAll(); } public SparkPlugin getPlugin() { diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java index 1030f35..5bd62a8 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java @@ -36,8 +36,6 @@ import me.lucko.spark.proto.SparkHeapProtos; import net.kyori.adventure.text.event.ClickEvent; -import okhttp3.MediaType; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -54,7 +52,7 @@ import static net.kyori.adventure.text.format.NamedTextColor.GREEN; import static net.kyori.adventure.text.format.NamedTextColor.RED; public class HeapAnalysisModule implements CommandModule { - private static final MediaType SPARK_HEAP_MEDIA_TYPE = MediaType.parse("application/x-spark-heap"); + private static final String SPARK_HEAP_MEDIA_TYPE = "application/x-spark-heap"; @Override public void registerCommands(Consumer consumer) { diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java index fd5cd67..0a80c31 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java @@ -44,8 +44,6 @@ import me.lucko.spark.proto.SparkSamplerProtos; import net.kyori.adventure.text.event.ClickEvent; -import okhttp3.MediaType; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -66,7 +64,7 @@ import static net.kyori.adventure.text.format.NamedTextColor.GRAY; import static net.kyori.adventure.text.format.NamedTextColor.RED; public class SamplerModule implements CommandModule { - private static final MediaType SPARK_SAMPLER_MEDIA_TYPE = MediaType.parse("application/x-spark-sampler"); + private static final String SPARK_SAMPLER_MEDIA_TYPE = "application/x-spark-sampler"; /** The sampler instance currently running, if any */ private Sampler activeSampler = null; diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/AbstractHttpClient.java b/spark-common/src/main/java/me/lucko/spark/common/util/AbstractHttpClient.java deleted file mode 100644 index 8ece3d4..0000000 --- a/spark-common/src/main/java/me/lucko/spark/common/util/AbstractHttpClient.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * Copyright (c) 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 me.lucko.spark.common.util; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -import java.io.IOException; - -public class AbstractHttpClient { - - /** The http client */ - protected final OkHttpClient okHttp; - - public AbstractHttpClient(OkHttpClient okHttp) { - this.okHttp = okHttp; - } - - protected Response makeHttpRequest(Request request) throws IOException { - Response response = this.okHttp.newCall(request).execute(); - if (!response.isSuccessful()) { - response.close(); - throw new RuntimeException("Request was unsuccessful: " + response.code() + " - " + response.message()); - } - return response; - } -} diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java index c2ca1b1..e69b94e 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java +++ b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java @@ -22,73 +22,66 @@ package me.lucko.spark.common.util; import com.google.protobuf.AbstractMessageLite; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; - -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import java.util.zip.GZIPOutputStream; /** * Utility for posting content to bytebin. */ -public class BytebinClient extends AbstractHttpClient { +public class BytebinClient { /** The bytebin URL */ private final String url; /** The client user agent */ private final String userAgent; - /** - * Creates a new bytebin instance - * - * @param url the bytebin url - * @param userAgent the client user agent string - */ - public BytebinClient(OkHttpClient okHttpClient, String url, String userAgent) { - super(okHttpClient); + public BytebinClient(String url, String userAgent) { this.url = url + (url.endsWith("/") ? "" : "/"); this.userAgent = userAgent; } - /** - * POSTs GZIP compressed content to bytebin. - * - * @param buf the compressed content - * @param contentType the type of the content - * @return the key of the resultant content - * @throws IOException if an error occurs - */ - public Content postContent(byte[] buf, MediaType contentType) throws IOException { - RequestBody body = RequestBody.create(contentType, buf); + private Content postContent(String contentType, Consumer consumer) throws IOException { + URL url = new URL(this.url + "post"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + try { + connection.setConnectTimeout((int) TimeUnit.SECONDS.toMillis(10)); + connection.setReadTimeout((int) TimeUnit.SECONDS.toMillis(10)); + + connection.setDoOutput(true); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", contentType); + connection.setRequestProperty("User-Agent", this.userAgent); + connection.setRequestProperty("Content-Encoding", "gzip"); - Request.Builder requestBuilder = new Request.Builder() - .url(this.url + "post") - .header("User-Agent", this.userAgent) - .header("Content-Encoding", "gzip"); + connection.connect(); + try (OutputStream output = connection.getOutputStream()) { + consumer.accept(output); + } - Request request = requestBuilder.post(body).build(); - try (Response response = makeHttpRequest(request)) { - String key = response.header("Location"); + String key = connection.getHeaderField("Location"); if (key == null) { throw new IllegalStateException("Key not returned"); } return new Content(key); + } finally { + connection.getInputStream().close(); + connection.disconnect(); } } - public Content postContent(AbstractMessageLite proto, MediaType contentType) throws IOException { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - try (OutputStream out = new GZIPOutputStream(byteOut)) { - proto.writeTo(out); - } catch (IOException e) { - throw new RuntimeException(e); - } - return postContent(byteOut.toByteArray(), contentType); + public Content postContent(AbstractMessageLite proto, String contentType) throws IOException { + return postContent(contentType, outputStream -> { + try (OutputStream out = new GZIPOutputStream(outputStream)) { + proto.writeTo(out); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); } public static final class Content { diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/Compression.java b/spark-common/src/main/java/me/lucko/spark/common/util/Compression.java index 9295c25..c8100e1 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/util/Compression.java +++ b/spark-common/src/main/java/me/lucko/spark/common/util/Compression.java @@ -20,10 +20,6 @@ package me.lucko.spark.common.util; -import org.tukaani.xz.LZMA2Options; -import org.tukaani.xz.LZMAOutputStream; -import org.tukaani.xz.XZOutputStream; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -46,35 +42,35 @@ public enum Compression { } return compressedFile; } - }, - XZ { - @Override - public Path compress(Path file, LongConsumer progressHandler) throws IOException { - Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".xz"); - try (InputStream in = Files.newInputStream(file)) { - try (OutputStream out = Files.newOutputStream(compressedFile)) { - try (XZOutputStream compressionOut = new XZOutputStream(out, new LZMA2Options())) { - copy(in, compressionOut, progressHandler); - } - } - } - return compressedFile; - } - }, - LZMA { - @Override - public Path compress(Path file, LongConsumer progressHandler) throws IOException { - Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".lzma"); - try (InputStream in = Files.newInputStream(file)) { - try (OutputStream out = Files.newOutputStream(compressedFile)) { - try (LZMAOutputStream compressionOut = new LZMAOutputStream(out, new LZMA2Options(), true)) { - copy(in, compressionOut, progressHandler); - } - } - } - return compressedFile; - } }; + // XZ { + // @Override + // public Path compress(Path file, LongConsumer progressHandler) throws IOException { + // Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".xz"); + // try (InputStream in = Files.newInputStream(file)) { + // try (OutputStream out = Files.newOutputStream(compressedFile)) { + // try (XZOutputStream compressionOut = new XZOutputStream(out, new LZMA2Options())) { + // copy(in, compressionOut, progressHandler); + // } + // } + // } + // return compressedFile; + // } + // }, + // LZMA { + // @Override + // public Path compress(Path file, LongConsumer progressHandler) throws IOException { + // Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".lzma"); + // try (InputStream in = Files.newInputStream(file)) { + // try (OutputStream out = Files.newOutputStream(compressedFile)) { + // try (LZMAOutputStream compressionOut = new LZMAOutputStream(out, new LZMA2Options(), true)) { + // copy(in, compressionOut, progressHandler); + // } + // } + // } + // return compressedFile; + // } + // }; public abstract Path compress(Path file, LongConsumer progressHandler) throws IOException; diff --git a/spark-fabric/build.gradle b/spark-fabric/build.gradle index 31008bb..35b7a86 100644 --- a/spark-fabric/build.gradle +++ b/spark-fabric/build.gradle @@ -70,12 +70,9 @@ shadowJar { archiveFileName = "spark-fabric-${project.pluginVersion}-dev.jar" configurations = [project.configurations.shade] - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-forge/build.gradle b/spark-forge/build.gradle index 3f46b95..46ac08c 100644 --- a/spark-forge/build.gradle +++ b/spark-forge/build.gradle @@ -52,12 +52,9 @@ shadowJar { archiveName = "spark-${project.pluginVersion}-forge.jar" configurations = [project.configurations.shade] - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-minestom/build.gradle b/spark-minestom/build.gradle index 26cdc2c..04e5f25 100644 --- a/spark-minestom/build.gradle +++ b/spark-minestom/build.gradle @@ -30,11 +30,8 @@ shadowJar { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) } - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-nukkit/build.gradle b/spark-nukkit/build.gradle index 2e1ad55..b15009a 100644 --- a/spark-nukkit/build.gradle +++ b/spark-nukkit/build.gradle @@ -25,11 +25,8 @@ processResources { shadowJar { archiveName = "spark-${project.pluginVersion}-nukkit.jar" - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' diff --git a/spark-sponge7/build.gradle b/spark-sponge7/build.gradle index b6f8273..b06d3bd 100644 --- a/spark-sponge7/build.gradle +++ b/spark-sponge7/build.gradle @@ -22,12 +22,9 @@ blossom { shadowJar { archiveFileName = "spark-${project.pluginVersion}-sponge7.jar" - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-sponge8/build.gradle b/spark-sponge8/build.gradle index 314ab18..202c308 100644 --- a/spark-sponge8/build.gradle +++ b/spark-sponge8/build.gradle @@ -28,11 +28,8 @@ shadowJar { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) } - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-velocity/build.gradle b/spark-velocity/build.gradle index b2e938b..275d3df 100644 --- a/spark-velocity/build.gradle +++ b/spark-velocity/build.gradle @@ -26,11 +26,8 @@ shadowJar { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) } - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-velocity4/build.gradle b/spark-velocity4/build.gradle index 5bef80b..1f8e8ee 100644 --- a/spark-velocity4/build.gradle +++ b/spark-velocity4/build.gradle @@ -31,11 +31,8 @@ shadowJar { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) } - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' diff --git a/spark-waterdog/build.gradle b/spark-waterdog/build.gradle index c11e3fb..d0c7de7 100644 --- a/spark-waterdog/build.gradle +++ b/spark-waterdog/build.gradle @@ -30,11 +30,8 @@ processResources { shadowJar { archiveName = "spark-${project.pluginVersion}-waterdog.jar" - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' -- cgit