Check version ranges of optional dependencies when present (#7710)

If an optional dependency is present, but it does not conform to the version range,
it will now error out in the same fashion as missing required dependencies, instead
of a more cryptic error down the line due to a missing method/class/field/etc.

Implements and closes #7696
This commit is contained in:
sciwhiz12 authored and GitHub committed 2021-04-22 22:52:24 -07:00
1 parent b3f253df61
commit c4b1df1fc7
2 files changed
+11 -8

No files matched your search

@@ -247,25 +247,27 @@ public class ModSorter
.flatMap(Collection::stream)
.collect(Collectors.groupingBy(Function.identity(), Java9BackportUtils.flatMapping(e -> e.getDependencies().stream(), Collectors.toList())));
final Set<IModInfo.ModVersion> mandatoryModVersions = modVersionDependencies
final Set<IModInfo.ModVersion> modRequirements = modVersionDependencies
.values()
.stream()
.flatMap(Collection::stream)
.filter(mv -> mv.isMandatory() && mv.getSide().isCorrectSide())
.filter(mv -> mv.getSide().isCorrectSide())
.collect(Collectors.toSet());
LOGGER.debug(LOADING, "Found {} mandatory requirements", mandatoryModVersions.size());
final Set<IModInfo.ModVersion> missingVersions = mandatoryModVersions
final long mandatoryRequired = modRequirements.stream().filter(IModInfo.ModVersion::isMandatory).count();
LOGGER.debug(LOADING, "Found {} mod requirements ({} mandatory, {} optional)", modRequirements.size(), mandatoryRequired, modRequirements.size() - mandatoryRequired);
final Set<IModInfo.ModVersion> missingVersions = modRequirements
.stream()
.filter(mv->this.modVersionNotContained(mv, modVersions))
.filter(mv -> (mv.isMandatory() || modVersions.containsKey(mv.getModId())) && this.modVersionNotContained(mv, modVersions))
.collect(Collectors.toSet());
LOGGER.debug(LOADING, "Found {} mandatory mod requirements missing", missingVersions.size());
final long mandatoryMissing = missingVersions.stream().filter(IModInfo.ModVersion::isMandatory).count();
LOGGER.debug(LOADING, "Found {} mod requirements missing ({} mandatory, {} optional)", missingVersions.size(), mandatoryMissing, missingVersions.size() - mandatoryMissing);
if (!missingVersions.isEmpty()) {
return missingVersions
.stream()
.map(mv -> new ExceptionData("fml.modloading.missingdependency", mv.getOwner(),
mv.getModId(), mv.getOwner().getModId(), mv.getVersionRange(),
.map(mv -> new ExceptionData(mv.isMandatory() ? "fml.modloading.missingdependency" : "fml.modloading.missingdependency.optional",
mv.getOwner(), mv.getModId(), mv.getOwner().getModId(), mv.getVersionRange(),
modVersions.getOrDefault(mv.getModId(), new DefaultArtifactVersion("null"))))
.collect(Collectors.toList());
}
@@ -54,6 +54,7 @@
"fml.modloading.errorduringevent":"{0,modinfo,name} ({0,modinfo,id}) encountered an error during the {1,lower} event phase\n\u00a77{2,exc,msg}",
"fml.modloading.failedtoloadforge": "Failed to load Forge",
"fml.modloading.missingdependency": "Mod \u00a7e{4}\u00a7r requires \u00a76{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a76{3}\u00a7r\u00a77 is \u00a7o{6,i18n,fml.messages.artifactversion.ornotinstalled}",
"fml.modloading.missingdependency.optional": "Mod \u00a7e{4}\u00a7r only supports \u00a73{3}\u00a7r \u00a7o{5,vr}\u00a7r\n\u00a77Currently, \u00a73{3}\u00a7r\u00a77 is \u00a7o{6}",
"fml.modloading.cycle": "Detected a mod dependency cycle: {0}",
"fml.modloading.failedtoprocesswork":"{0,modinfo,name} ({0,modinfo,id}) encountered an error processing deferred work\n\u00a77{2,exc,msg}",
"fml.modloading.brokenfile": "File {2} is not a valid mod file",