From 21ca764e26fdbb903ce380874cc2798f17de9034 Mon Sep 17 00:00:00 2001 From: nea Date: Wed, 1 Nov 2023 21:11:09 +0100 Subject: Make MJL package the agent --- agent/build.gradle.kts | 11 +- build.gradle.kts | 11 + examplemod.ipr | 104 ----- examplemod.iws | 427 --------------------- install.sh | 6 +- .../nea/modernjava/launch/live/FCPFixTweaker.java | 2 + .../modernjava/launch/relaunch/FCPRelauncher.java | 33 +- 7 files changed, 48 insertions(+), 546 deletions(-) delete mode 100644 examplemod.ipr delete mode 100644 examplemod.iws diff --git a/agent/build.gradle.kts b/agent/build.gradle.kts index 983f917..c85be22 100644 --- a/agent/build.gradle.kts +++ b/agent/build.gradle.kts @@ -9,15 +9,13 @@ java { val shadowOnly: Configuration by configurations.creating { - attributes { - this.attribute(org.gradle.api.attributes.java.TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11) - } } dependencies { shadowOnly(implementation("org.ow2.asm:asm:9.4")!!) shadowOnly(implementation("org.ow2.asm:asm-commons:9.4")!!) shadowOnly("dev.architectury:architectury-pack200:0.1.3") + shadowOnly("org.apache.commons:commons-lang3:3.13.0") } tasks.withType(Jar::class) { manifest { @@ -36,4 +34,9 @@ tasks.shadowJar { tasks.jar { archiveClassifier.set("thin") } -tasks.assemble.get().dependsOn(tasks.shadowJar) \ No newline at end of file +tasks.assemble.get().dependsOn(tasks.shadowJar) + +configurations.create("agentShadow") +artifacts { + add("agentShadow", tasks.shadowJar) +} diff --git a/build.gradle.kts b/build.gradle.kts index 154215c..46deb21 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,6 +47,8 @@ val shadowImpl: Configuration by configurations.creating { configurations.implementation.get().extendsFrom(this) } +val agentDeps: Configuration by configurations.creating + val shadowOnly: Configuration by configurations.creating { attributes { this.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16) @@ -63,10 +65,18 @@ dependencies { shadowImpl("com.github.Skytils:AsmHelper:91ecc2bd9c") shadowImpl(enforcedPlatform(kotlin("bom"))) shadowImpl(kotlin("stdlib")) + agentDeps(project(":agent",configuration = "agentShadow")) } // Tasks: +val doubleWrappedJar by tasks.creating(Zip::class) { + archiveFileName.set("agent.jar") + destinationDirectory.set(project.layout.buildDirectory.dir("wrapper")) + from(agentDeps) + into("agent") +} + tasks.withType(JavaCompile::class) { options.encoding = "UTF-8" } @@ -97,6 +107,7 @@ tasks.shadowJar { archiveClassifier.set("all-dev") relocate("dev.falsehonesty.asmhelper", "moe.nea.modernjava.dep.asmhelper") configurations = listOf(shadowImpl, shadowOnly) + from(doubleWrappedJar) } tasks.assemble.get().dependsOn(tasks.remapJar) diff --git a/examplemod.ipr b/examplemod.ipr deleted file mode 100644 index 4ec7ca2..0000000 --- a/examplemod.ipr +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1.6 - - - - - - - - - - - - - diff --git a/examplemod.iws b/examplemod.iws deleted file mode 100644 index 0819613..0000000 --- a/examplemod.iws +++ /dev/null @@ -1,427 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - - 5050 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/install.sh b/install.sh index 89a94d8..4415fcc 100755 --- a/install.sh +++ b/install.sh @@ -2,9 +2,9 @@ set -euo pipefail -rm -f ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods/examplemod-* -./gradlew :build :target:build -cp ./build/libs/examplemod-1.0.0.jar ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods +rm -f ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods/ModernJavaLauncher-* +./gradlew :agent:build :build +cp ./build/libs/ModernJavaLauncher-1.0.0.jar ~/.local/share/PrismLauncher/instances/1.8.9/.minecraft/mods diff --git a/src/main/java/moe/nea/modernjava/launch/live/FCPFixTweaker.java b/src/main/java/moe/nea/modernjava/launch/live/FCPFixTweaker.java index a5bf648..0fe2285 100644 --- a/src/main/java/moe/nea/modernjava/launch/live/FCPFixTweaker.java +++ b/src/main/java/moe/nea/modernjava/launch/live/FCPFixTweaker.java @@ -17,6 +17,8 @@ public class FCPFixTweaker implements ITweaker { @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { + classLoader.addClassLoaderExclusion("moe.nea.modernjava."); + classLoader.addClassLoaderExclusion("kotlin."); classLoader.registerTransformer("moe.nea.modernjava.launch.transform.TransObjectHolderRef"); } diff --git a/src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java b/src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java index 04fb0ea..fe74c42 100644 --- a/src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java +++ b/src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java @@ -5,10 +5,14 @@ import moe.nea.modernjava.launch.util.TextIoUtils; import moe.nea.modernjava.launch.util.WellKnownBlackboard; import net.minecraftforge.fml.common.launcher.FMLTweaker; import net.minecraftforge.fml.nea.moe.modernjava.IAMFML; +import org.apache.commons.io.IOUtils; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.management.ManagementFactory; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -42,7 +46,21 @@ public class FCPRelauncher { } public static File findJavaLauncher() { - return new File("/home/nea/.sdkman/candidates/java/16.0.2-tem/bin/java") + return new File("/home/nea/.sdkman/candidates/java/16.0.2-tem/bin/java"); + } + + public static File findAgentJar() { + try { + File file = File.createTempFile("mjr-agent", ".jar"); + try (InputStream is = FCPRelauncher.class.getResourceAsStream("/agent/agent.jar"); + OutputStream os = Files.newOutputStream(file.toPath())) { + assert is != null; + IOUtils.copy(is, os); + } + return file; + } catch (IOException e) { + throw new RuntimeException(e); + } } public static void relaunch() { @@ -50,12 +68,11 @@ public class FCPRelauncher { List originalArgs = getOriginalArguments(); File modernJavaPath = findJavaLauncher(); + System.out.println("Located modern minecraft at: " + modernJavaPath); + File agentFile = findAgentJar(); + System.out.println("Located agent jar at: " + agentFile); - File agentFile; - agentFile = new File("/home/nea/src/ModernJavaLauncher/target/build/libs/target.jar"); - - System.out.println("Located modern minecraft at: " + modernJavaPath); ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.inheritIO(); @@ -80,10 +97,10 @@ public class FCPRelauncher { } if (System.getProperty(PropertyNames.DEBUG_PORT) != null) fullCommandLine.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:" + System.getProperty(PropertyNames.DEBUG_PORT)); - fullCommandLine.add("-javaagent:" + agentFile); + fullCommandLine.add("-javaagent:" + agentFile.getAbsolutePath()); fullCommandLine.add("--add-modules=ALL-MODULE-PATH,ALL-SYSTEM,ALL-DEFAULT,java.sql"); - fullCommandLine.add("-Xbootclasspath/a:" + agentFile); - fullCommandLine.add("moe.nea.modernjava.target.RelaunchEntryPoint"); + fullCommandLine.add("-Xbootclasspath/a:" + agentFile.getAbsolutePath()); + fullCommandLine.add("moe.nea.modernjava.agent.RelaunchEntryPoint"); fullCommandLine.addAll(originalArgs); System.out.println("Full relaunch commandline: " + fullCommandLine); -- cgit