Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some stuff, made a few small changes, removed Java 16 code #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/xyz/spruceloader/trunk/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static void main(String[] args) {
argMap.putIfAbsent("accessToken", "None");
argMap.putIfAbsent("version", "Unknown");
argMap.putIfAbsent("gameDir", Paths.get(".").normalize().toString());
new Trunk().initialize(argMap, EnvSide.CLIENT);

Trunk trunk = new Trunk();
trunk.initialize(argMap, EnvSide.CLIENT);
trunk.getClassLoader().addDefaultLoadingFilters();
}
}
5 changes: 4 additions & 1 deletion src/main/java/xyz/spruceloader/trunk/MainServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public static void main(String[] args) {
argMap.remove("version");
argMap.remove("gameDir");
argMap.remove("assetsDir");
new Trunk().initialize(argMap, EnvSide.SERVER);

Trunk trunk = new Trunk();
trunk.initialize(argMap, EnvSide.SERVER);
trunk.getClassLoader().addDefaultLoadingFilters();
}
}
4 changes: 3 additions & 1 deletion src/main/java/xyz/spruceloader/trunk/Trunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -35,11 +36,12 @@ public Trunk() {
} catch (Throwable t) {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList()).toArray(URL[]::new), getClass().getClassLoader());
}).filter(Objects::nonNull).collect(Collectors.toList()).toArray(new URL[0]), getClass().getClassLoader());
transformerManager = new TransformerManager();
Thread.currentThread().setContextClassLoader(classLoader);
GLOBAL_PROPERTIES.put("trunk.development", DEVELOPMENT);
}


public void initialize(ArgumentMap argMap, EnvSide env) {
LOGGER.info("Launching Minecraft with Spruce Trunk");
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/xyz/spruceloader/trunk/TrunkClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ public void addPath(Path path) {
}
}

/**
* Adds the default loading filters. This is subject to change!
*/
public void addDefaultLoadingFilters() {
addPackageLoadingFilter("java");
addPackageLoadingFilter("jdk");
addPackageLoadingFilter("javax");
addPackageLoadingFilter("sun");
addPackageLoadingFilter("com.sun");
addPackageLoadingFilter("org.apache.logging.log4j");
addPackageLoadingFilter("org.slf4j");
}

/**
* Adds a loading filter - returns true to filter the class.
*
Expand Down Expand Up @@ -130,7 +143,7 @@ private byte[] transformClassBytes(String name, byte[] bytes) {
}

private byte[] getClassBytes(String name) throws IOException {
try (InputStream in = getResourceAsStream(name)) {
try (InputStream in = getResourceAsStream(name.replace(".", "/").concat(".class"))) {
if (in == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class TransformerManager implements Iterable<Transformer> {

Expand Down Expand Up @@ -44,8 +45,9 @@ private void handleFromNamespaces(ArgumentMap argMap, String argName, String pro
argValues.forEach(name -> transformers.add(fromName(name)));

String prop = System.getProperty(propName);

if (prop != null) {
List<String> propValues = Arrays.stream(prop.split("/")).toList();
List<String> propValues = Arrays.stream(prop.split("/")).collect(Collectors.toList());
if (!propValues.isEmpty())
propValues.forEach(name -> transformers.add(fromName(name)));
}
Expand Down