aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-11-01 21:11:09 +0100
committernea <nea@nea.moe>2023-11-01 21:11:09 +0100
commit21ca764e26fdbb903ce380874cc2798f17de9034 (patch)
tree52931b66e52120a22d20354d0fe1adb26876cded /src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java
parent297cb01f220a617dd08096467978b2fccbc27695 (diff)
downloadModernJavaLauncher-21ca764e26fdbb903ce380874cc2798f17de9034.tar.gz
ModernJavaLauncher-21ca764e26fdbb903ce380874cc2798f17de9034.tar.bz2
ModernJavaLauncher-21ca764e26fdbb903ce380874cc2798f17de9034.zip
Make MJL package the agent
Diffstat (limited to 'src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java')
-rw-r--r--src/main/java/moe/nea/modernjava/launch/relaunch/FCPRelauncher.java33
1 files changed, 25 insertions, 8 deletions
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<String> 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);