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 22, 2024
1 parent 9791af5 commit 06ebd1d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 51 deletions.
1 change: 1 addition & 0 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ minecraft {
mainClass("net.minecraftforge.bootstrap.ForgeBootstrap")

// Configure resources
jvmArgs("-Dsponge.dev.root=" + project.rootDir)
jvmArgs("-Dsponge.dev.boot=" + bootLayerConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name })
jvmArgs("-Dsponge.dev.gameShaded=" + gameShadedLibrariesConfig.get().resolvedConfiguration.resolvedArtifacts.joinToString(";") { it.file.name })
}
Expand Down
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 @@ -28,6 +28,7 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -51,6 +52,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> bootLibs = Set.of(System.getProperty("sponge.dev.boot").split(";"));
final Set<String> gameShadedLibs = Set.of(System.getProperty("sponge.dev.gameShaded").split(";"));

Expand All @@ -67,46 +69,55 @@ public boolean process(final List<Path[]> classpath) {
return false;
}

final Path path = paths[0];
final Path path = paths[0].toAbsolutePath();
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 "modlauncher-transformers":
bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path);
break;
case "SpongeAPI":
switch (sourceSet.name()) {
case "ap":
// ignore
break;
case "main":
hasAPISourceSet.set(true);
// no break
default:
spongeImplUnion.add(path);
break;
}
break;
case "Sponge", "vanilla":
switch (sourceSet.name()) {
case "devlaunch":
// ignore
break;
case "applaunch":
bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path);
break;
default:
spongeImplUnion.add(path);
break;
}
break;
default:
unknownProjects.computeIfAbsent(sourceSet.project(), k -> new LinkedList<>()).add(path);
break;
final String projectName = spongeRoot.relativize(sourceSet.project()).toString();
switch (projectName) {
case "modlauncher-transformers":
bootSourceSets.computeIfAbsent("transformers", k -> new LinkedList<>()).add(path);
break;
case "SpongeAPI":
switch (sourceSet.name()) {
case "ap":
// ignore
break;
case "main":
hasAPISourceSet.set(true);
// no break
default:
spongeImplUnion.add(path);
break;
}
break;
case "", "vanilla":
switch (sourceSet.name()) {
case "devlaunch":
// ignore
break;
case "applaunch":
bootSourceSets.computeIfAbsent("applaunch", k -> new LinkedList<>()).add(path);
break;
default:
spongeImplUnion.add(path);
break;
}
break;
default:
unknownProjects.computeIfAbsent(projectName, k -> new LinkedList<>()).add(path);
break;
}
} else {
if (DEBUG) {
System.out.println("External SourceSet (" + sourceSet + "): " + path);
}

unknownProjects.computeIfAbsent(sourceSet.project().toString(), k -> new LinkedList<>()).add(path);
}
return true;
}
Expand Down

0 comments on commit 06ebd1d

Please sign in to comment.