Skip to content

Commit

Permalink
Fix dev classpath when root directory is not "Sponge"
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Dec 23, 2024
1 parent 2321a69 commit 52c4d26
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -57,32 +57,34 @@ public static SourceSet identify(Path path) {
}

// from right to left
final List<String> parts = new ArrayList<>();
final List<String> names = new ArrayList<>();
final List<Path> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +50,7 @@ public String name() {
*/
@Override
public boolean process(final List<Path[]> classpath) {
final Path spongeRoot = Paths.get(System.getProperty("sponge.dev.root")).toAbsolutePath();
final Set<String> ignoredLibs = Set.of("bootstrap-dev.jar");
final Set<String> bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(File.pathSeparator));
final Set<String> gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(File.pathSeparator));
Expand All @@ -70,46 +72,55 @@ public boolean process(final List<Path[]> 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;
}
Expand Down
1 change: 1 addition & 0 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 52c4d26

Please sign in to comment.