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

Allow multiple copies of a class on the CP and pick the JAR containing the first. #169

Open
wants to merge 1 commit 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
18 changes: 15 additions & 3 deletions loader/src/main/java/net/neoforged/fml/util/DevEnvUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import net.neoforged.fml.ModLoadingException;
import net.neoforged.fml.ModLoadingIssue;
import org.jetbrains.annotations.ApiStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApiStatus.Internal
public final class DevEnvUtils {
private static final Logger LOG = LoggerFactory.getLogger(DevEnvUtils.class);

private DevEnvUtils() {}

public static List<Path> findFileSystemRootsOfFileOnClasspath(String relativePath) {
Expand All @@ -37,7 +43,8 @@ public static List<Path> findFileSystemRootsOfFileOnClasspath(String relativePat
throw new IllegalArgumentException("Failed to enumerate classpath locations of " + relativePath);
}

List<Path> result = new ArrayList<>();
// Remove duplicates, but maintain order!
Set<Path> result = new LinkedHashSet<>();
while (resourceIt.hasNext()) {
var resourceUrl = resourceIt.next();

Expand Down Expand Up @@ -66,7 +73,7 @@ public static List<Path> findFileSystemRootsOfFileOnClasspath(String relativePat
}
}

return result;
return new ArrayList<>(result);
}

public static Path findFileSystemRootOfFileOnClasspath(String relativePath) {
Expand All @@ -75,7 +82,12 @@ public static Path findFileSystemRootOfFileOnClasspath(String relativePath) {
if (paths.isEmpty()) {
throw new ModLoadingException(ModLoadingIssue.error("fml.modloadingissue.failed_to_find_on_classpath", relativePath));
} else if (paths.size() > 1) {
throw new ModLoadingException(ModLoadingIssue.error("fml.modloadingissue.multiple_copies_on_classpath", relativePath, paths));
// Warn for anything past the first. It's impossible to know if the user actually intended this setup,
// but to allow launching in uncommon configurations, we'll allow it.
for (int i = 1; i < paths.size(); i++) {
var path = paths.get(i);
LOG.warn("Found multiple copies of {} on classpath. Ignoring copy from {}, using {} instead.", relativePath, path, paths.getFirst());
}
}

return paths.getFirst();
Expand Down
1 change: 0 additions & 1 deletion loader/src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"fml.modloadingissue.maven_coordinate_not_found": "No mod with the Maven coordinate {0} could be found in {1}",
"fml.modloadingissue.failed_to_list_folder_content": "Failed to list content of folder {0}",
"fml.modloadingissue.failed_to_find_on_classpath": "Failed to find {0} on the classpath",
"fml.modloadingissue.multiple_copies_on_classpath": "Found multiple copies of {0} on the classpath: {1}",
"fml.messages.artifactversion.ornotinstalled": "{0,ornull,fml.messages.artifactversion.notinstalled}",
"fml.messages.artifactversion": "{0,ornull,fml.messages.artifactversion.none}",
"fml.messages.artifactversion.none": "none",
Expand Down
Loading