diff options
author | nea <nea@nea.moe> | 2023-11-01 18:50:11 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-11-01 18:50:11 +0100 |
commit | 297cb01f220a617dd08096467978b2fccbc27695 (patch) | |
tree | d467f358313ce3648063da41b66361a840fa7864 /src/main/java/moe/nea/modernjava/launch/util | |
parent | d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4 (diff) | |
download | ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.tar.gz ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.tar.bz2 ModernJavaLauncher-297cb01f220a617dd08096467978b2fccbc27695.zip |
Add documentation
Diffstat (limited to 'src/main/java/moe/nea/modernjava/launch/util')
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java | 10 | ||||
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/ObjectHolderRefCompanion.java (renamed from src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java) | 13 | ||||
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/PropertyNames.java | 16 | ||||
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/TextIoUtils.java | 22 | ||||
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/WellKnownBlackboard.java | 27 |
5 files changed, 86 insertions, 2 deletions
diff --git a/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java index 09f2368..6cc21e9 100644 --- a/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java +++ b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java @@ -1,6 +1,7 @@ package moe.nea.modernjava.launch.util; import net.minecraft.launchwrapper.Launch; +import net.minecraft.launchwrapper.LaunchClassLoader; import java.io.File; import java.lang.reflect.Method; @@ -8,7 +9,10 @@ import java.net.MalformedURLException; import java.net.URL; public class ClassLoaderManipulations { - + /** + * Adds a File to the parent class loader of the launch class loader. Necessary if you want to/have to use + * {@link LaunchClassLoader#addClassLoaderExclusion(String)}. + */ public static void addToParentClassLoader(File file) { try { addToParentClassLoader(file.toURI().toURL()); @@ -17,6 +21,10 @@ public class ClassLoaderManipulations { } } + /** + * Adds a URL to the parent class loader of the launch class loader. Necessary if you want to/have to use + * {@link LaunchClassLoader#addClassLoaderExclusion(String)}. + */ public static void addToParentClassLoader(URL file) { try { Launch.classLoader.addURL(file); diff --git a/src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java b/src/main/java/moe/nea/modernjava/launch/util/ObjectHolderRefCompanion.java index abc2364..15f9450 100644 --- a/src/main/java/moe/nea/modernjava/launch/util/ReflectionUtils.java +++ b/src/main/java/moe/nea/modernjava/launch/util/ObjectHolderRefCompanion.java @@ -1,10 +1,15 @@ package moe.nea.modernjava.launch.util; +import moe.nea.modernjava.launch.transform.TransObjectHolderRef; import sun.misc.Unsafe; import java.lang.reflect.Field; -public class ReflectionUtils { +/** + * A companion to my transformations from {@link TransObjectHolderRef} to avoid + * having to write all of this out in bytecode. + */ +public class ObjectHolderRefCompanion { private static Unsafe unsafe; static { @@ -17,10 +22,16 @@ public class ReflectionUtils { } } + /** + * A noop to have a jump target for the reflection factories. + */ public static void makeFieldWritable(Field f) { String s = "Doing nothing. We will use unsafe to set the value instead, if possible"; } + /** + * Write a value to a static final field. + */ public static void doFieldWrite(Field field, Object object) throws IllegalAccessException { if (unsafe == null) { field.set(null, object); diff --git a/src/main/java/moe/nea/modernjava/launch/util/PropertyNames.java b/src/main/java/moe/nea/modernjava/launch/util/PropertyNames.java new file mode 100644 index 0000000..8540dde --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/PropertyNames.java @@ -0,0 +1,16 @@ +package moe.nea.modernjava.launch.util; + +public class PropertyNames { + /** + * Property set to indicate whether the java process was launched on the new java version. + */ + public static final String HAS_RELAUNCHED = "modernjava.hasrelaunched"; + /** + * Classpath to load after reloading. + */ + public static final String RELAUNCH_CLASSPATH = "modernjava.relaunchclasspath"; + /** + * Starts a debugger on the given port if present. + */ + public static final String DEBUG_PORT = "modernjava.debugport"; +} diff --git a/src/main/java/moe/nea/modernjava/launch/util/TextIoUtils.java b/src/main/java/moe/nea/modernjava/launch/util/TextIoUtils.java new file mode 100644 index 0000000..b7f82c0 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/TextIoUtils.java @@ -0,0 +1,22 @@ +package moe.nea.modernjava.launch.util; + +import java.io.FileDescriptor; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +public class TextIoUtils { + /** + * Flush out the standard IO, without closing it. Works even after {@link System#setOut(PrintStream)} or similar has been called + */ + public static void flushStdIO() { + try { + // These streams should not be closed. We just want to flush them out + //noinspection resource + new FileOutputStream(FileDescriptor.out).flush(); + //noinspection resource + new FileOutputStream(FileDescriptor.err).flush(); + } catch (IOException ignored) { + } + } +} diff --git a/src/main/java/moe/nea/modernjava/launch/util/WellKnownBlackboard.java b/src/main/java/moe/nea/modernjava/launch/util/WellKnownBlackboard.java new file mode 100644 index 0000000..967f531 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/WellKnownBlackboard.java @@ -0,0 +1,27 @@ +package moe.nea.modernjava.launch.util; + +import net.minecraft.launchwrapper.Launch; + +import java.util.List; +import java.util.Map; + +/** + * Contains references to the {@link Launch#blackboard black board} in one central spot to avoid misspelling. + */ +@SuppressWarnings("unchecked") +public class WellKnownBlackboard { + /** + * A list of tweaker class names yet to be executed. This does not include tweaker class names present in the current + * round of tweaking. + */ + public static List<String> tweakerNames() { + return (List<String>) Launch.blackboard.get("TweakClasses"); + } + + /** + * A map of arguments in the form of --prefixedKey to value. + */ + public static Map<String, String> launchArgs() { + return (Map<String, String>) Launch.blackboard.get("launchArgs"); + } +} |