Skip to content

Commit

Permalink
Add support for loading the legacy classpath from a file. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Jul 26, 2021
1 parent e179c12 commit 2d2081a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/cpw/mods/bootstraplauncher/BootstrapLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import cpw.mods.jarhandling.SecureJar;

import java.io.File;
import java.io.IOException;
import java.lang.module.ModuleFinder;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -19,12 +22,14 @@
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class BootstrapLauncher {
private static final boolean DEBUG = System.getProperties().containsKey("bsl.debug");
@SuppressWarnings("unchecked")
public static void main(String[] args) {
var legacyCP = Objects.requireNonNull(System.getProperty("legacyClassPath", System.getProperty("java.class.path")), "Missing legacyClassPath, cannot bootstrap");
var legacyCP = loadLegacyClassPath();
System.setProperty("legacyClassPath", String.join(File.pathSeparator, legacyCP)); //Ensure backwards compatibility if somebody reads this value later on.
var ignoreList = System.getProperty("ignoreList", "/org/ow2/asm/,securejarhandler"); //TODO: find existing modules automatically instead of taking in an ignore list.
var ignores = ignoreList.split(",");

Expand All @@ -34,7 +39,7 @@ public static void main(String[] args) {
var mergeMap = new HashMap<Integer, List<Path>>();

outer:
for (var legacy : legacyCP.split(File.pathSeparator)) {
for (var legacy : legacyCP) {
for (var filter : ignores) {
if (legacy.contains(filter)) {
if (DEBUG)
Expand Down Expand Up @@ -116,4 +121,23 @@ public boolean test(final String path, final String basePath) {
!packages.contains(path.substring(0, idx).replace('/', '.'));
}
}

private static List<String> loadLegacyClassPath() {
var legacyCpPath = System.getProperty("legacyClassPath.file");

if (legacyCpPath != null) {
var legacyCPFileCandidatePath = Paths.get(legacyCpPath);
if (Files.exists(legacyCPFileCandidatePath) && Files.isRegularFile(legacyCPFileCandidatePath)) {
try {
return Files.readAllLines(legacyCPFileCandidatePath);
}
catch (IOException e) {
throw new IllegalStateException("Failed to load the legacy class path from the specified file: " + legacyCpPath, e);
}
}
}

return Arrays.asList(Objects.requireNonNull(System.getProperty("legacyClassPath", System.getProperty("java.class.path")), "Missing legacyClassPath, cannot bootstrap")
.split(File.pathSeparator));
}
}

0 comments on commit 2d2081a

Please sign in to comment.