diff --git a/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SourceSet.java b/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SourceSet.java index 540c752afcc..badeb5407dc 100644 --- a/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SourceSet.java +++ b/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SourceSet.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.List; -public record SourceSet(String project, String name, String format) { +public record SourceSet(Path project, String name, String format) { @Override public String toString() { @@ -57,32 +57,34 @@ public static SourceSet identify(Path path) { } // from right to left - final List parts = new ArrayList<>(); + final List names = new ArrayList<>(); + final List paths = new ArrayList<>(); while (path != null) { - parts.add(path.getFileName().toString()); - if (parts.size() >= 5) { + names.add(path.getFileName().toString()); + paths.add(path); + if (names.size() >= 5) { break; } path = path.getParent(); } - if (parts.size() >= 4 && (parts.get(0).equals("classes") || parts.get(0).equals("resources"))) { - final String name = parts.get(1); - return new SourceSet(parts.get(3), name.equals("production") ? "main" : name, "IntelliJ"); + if (names.size() >= 4 && (names.get(0).equals("classes") || names.get(0).equals("resources"))) { + final String name = names.get(1); + return new SourceSet(paths.get(3), name.equals("production") ? "main" : name, "IntelliJ"); } - if (parts.size() >= 4 && (parts.get(1).equals("resources") || parts.get(1).equals("generated"))) { - return new SourceSet(parts.get(3), parts.get(0), "Gradle"); + if (names.size() >= 4 && (names.get(1).equals("resources") || names.get(1).equals("generated"))) { + return new SourceSet(paths.get(3), names.get(0), "Gradle"); } - if (parts.size() >= 5 && parts.get(2).equals("classes")) { - return new SourceSet(parts.get(4), parts.get(0), "Gradle"); + if (names.size() >= 5 && names.get(2).equals("classes")) { + return new SourceSet(paths.get(4), names.get(0), "Gradle"); } - if (parts.size() >= 3 && parts.get(1).equals("bin")) { - return new SourceSet(parts.get(2), parts.get(0), "Eclipse"); + if (names.size() >= 3 && names.get(1).equals("bin")) { + return new SourceSet(paths.get(2), names.get(0), "Eclipse"); } - return new SourceSet("", parts.get(0), "Unknown"); + return new SourceSet(paths.get(0), "?", "Unknown"); } } diff --git a/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SpongeDevClasspathFixer.java b/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SpongeDevClasspathFixer.java index 1fc983100b0..ab566c5f915 100644 --- a/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SpongeDevClasspathFixer.java +++ b/bootstrap-dev/src/main/java/org/spongepowered/bootstrap/dev/SpongeDevClasspathFixer.java @@ -29,6 +29,7 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -49,6 +50,7 @@ public String name() { */ @Override public boolean process(final List classpath) { + final Path spongeRoot = Paths.get(System.getProperty("sponge.dev.root")).toAbsolutePath(); final Set ignoredLibs = Set.of("bootstrap-dev.jar"); final Set bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(File.pathSeparator)); final Set gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(File.pathSeparator)); @@ -70,46 +72,55 @@ public boolean process(final List classpath) { final Path path = paths[0]; final SourceSet sourceSet = SourceSet.identify(path); if (sourceSet != null) { - if (DEBUG) { - System.out.println("SourceSet (" + sourceSet + "): " + path); - } + if (sourceSet.project().startsWith(spongeRoot)) { + if (DEBUG) { + System.out.println("Sponge SourceSet (" + sourceSet + "): " + path); + } - switch (sourceSet.project()) { - case "bootstrap-dev": - // ignore - break; - case "modlauncher-transformers", "library-manager": - bootUnions.add(sourceSet.project(), path); - break; - case "SpongeAPI": - switch (sourceSet.name()) { - case "ap": - // ignore - break; - case "main": - hasAPISourceSet.set(true); - // no break - default: - unions.add("sponge", path); - break; - } - break; - case "Sponge", "vanilla", "forge": - switch (sourceSet.name()) { - case "applaunch": - bootUnions.add("applaunch", path); - break; - case "lang": - unions.add("lang", path); - break; - default: - unions.add("sponge", path); - break; - } - break; - default: - unions.add(sourceSet.project(), path); - break; + final String projectName = spongeRoot.relativize(sourceSet.project()).toString(); + switch (projectName) { + case "bootstrap-dev": + // ignore + break; + case "modlauncher-transformers", "library-manager": + bootUnions.add(projectName, path); + break; + case "SpongeAPI": + switch (sourceSet.name()) { + case "ap": + // ignore + break; + case "main": + hasAPISourceSet.set(true); + // no break + default: + unions.add("sponge", path); + break; + } + break; + case "", "vanilla", "forge": + switch (sourceSet.name()) { + case "applaunch": + bootUnions.add("applaunch", path); + break; + case "lang": + unions.add("lang", path); + break; + default: + unions.add("sponge", path); + break; + } + break; + default: + unions.add(projectName, path); + break; + } + } else { + if (DEBUG) { + System.out.println("External SourceSet (" + sourceSet + "): " + path); + } + + unions.add(sourceSet.project().toString(), path); } return true; } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index b3a90619a7b..c973f13168e 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -247,6 +247,7 @@ afterEvaluate { val bootFileNames = spongeImpl.buildRuntimeFileNames(serviceLayerConfig.get()) // service in boot during dev val gameShadedFileNames = spongeImpl.buildRuntimeFileNames(gameShadedLibrariesConfig.get()) runs.configureEach { + jvmArgs("-Dsponge.dev.root=" + project.rootDir) jvmArgs("-Dsponge.dev.boot=$bootFileNames") jvmArgs("-Dsponge.dev.gameShaded=$gameShadedFileNames") } diff --git a/vanilla/build.gradle.kts b/vanilla/build.gradle.kts index 90595bb3a29..27fc697f86c 100644 --- a/vanilla/build.gradle.kts +++ b/vanilla/build.gradle.kts @@ -301,6 +301,7 @@ minecraft { // jvmArgs("-Dbsl.debug=true") // Uncomment to debug bootstrap classpath mainClass("net.minecraftforge.bootstrap.ForgeBootstrap") + jvmArgs("-Dsponge.dev.root=" + project.rootDir) jvmArgs("-Dsponge.dev.boot=$bootFileNames") jvmArgs("-Dsponge.dev.gameShaded=$gameShadedFileNames") }