Skip to content

Commit

Permalink
cf-files: improve the logging of missing dependencies especially opti…
Browse files Browse the repository at this point in the history
…onal ones (#464)
  • Loading branch information
itzg authored Aug 17, 2024
1 parent 0ed6eb4 commit 4270ad1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import me.itzg.helpers.curseforge.model.CurseForgeFile;
import me.itzg.helpers.curseforge.model.CurseForgeMod;
import me.itzg.helpers.curseforge.model.FileDependency;
import me.itzg.helpers.curseforge.model.FileRelationType;
import me.itzg.helpers.curseforge.model.ModLoaderType;
import me.itzg.helpers.errors.GenericException;
import me.itzg.helpers.errors.InvalidParameterException;
Expand All @@ -34,6 +35,8 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

@Command(name = "curseforge-files", description = "Download and manage individual mod/plugin files from CurseForge")
@Slf4j
Expand Down Expand Up @@ -168,31 +171,70 @@ private Mono<List<FileEntry>> processModFileRefs(CategoryInfo categoryInfo,

return Flux.fromIterable(modFiles)
.flatMap(modFile -> {
for (final FileDependency dependency : modFile.getDependencies()) {
if (!requestedModIds.contains(dependency.getModId())) {
log.warn("The mod file {} depends on mod project ID {}, but that is not listed",
modFile.getDisplayName(), dependency.getModId()
);
}
}

final Mono<FileEntry> retrieval;
final ModFileIds modFileIds = idsFrom(modFile);
final FileEntry entry = previousFiles.get(modFileIds);
if (entry != null
&& Files.exists(outputDir.resolve(entry.getFilePath()))
) {
log.debug("Mod file {} already exists at {}", modFile.getFileName(), entry.getFilePath());
return Mono.just(entry);
retrieval = Mono.just(entry);
}
else {
return retrieveModFile(apiClient, categoryInfo, modFile)
retrieval = retrieveModFile(apiClient, categoryInfo, modFile)
.map(path -> new FileEntry(modFileIds, outputDir.relativize(path).toString()));
}

return reportMissingDependencies(apiClient, modFile, requestedModIds)
.then(retrieval);
});
}
)
.collectList();
}

/**
*
* @return flux of missing, required dependencies
*/
private static Flux<Tuple2<CurseForgeMod, FileDependency>> reportMissingDependencies(CurseForgeApiClient apiClient,
CurseForgeFile modFile, Set<Integer> requestedModIds
) {
return Flux.fromIterable(modFile.getDependencies())
.mapNotNull(dependency -> {
if (!requestedModIds.contains(dependency.getModId())) {
switch (dependency.getRelationType()) {
case RequiredDependency:
case OptionalDependency:
return dependency;
default:
return null;
}
}
else {
return null;
}
})
.flatMap(dependency ->
apiClient.getModInfo(dependency.getModId())
.map(curseForgeMod -> Tuples.of(curseForgeMod, dependency))
)
.doOnNext(missingDep -> {
if (missingDep.getT2().getRelationType() == FileRelationType.RequiredDependency) {
log.warn("The mod file '{}' depends on mod project '{}' at {}, but it is not listed",
modFile.getDisplayName(), missingDep.getT1().getName(), missingDep.getT1().getLinks().getWebsiteUrl()
);
}
else if (missingDep.getT2().getRelationType() == FileRelationType.OptionalDependency) {
log.debug("The mod file '{}' optionally depends on mod project '{}', but it is not listed",
modFile.getDisplayName(), missingDep.getT1().getName()
);
}
})
.filter(missingDep -> missingDep.getT2().getRelationType() == FileRelationType.RequiredDependency);
}

@NotNull
private static Map<ModFileIds, FileEntry> buildPreviousFilesFromManifest(CurseForgeFilesManifest oldManifest) {
return oldManifest != null ?
Expand Down
24 changes: 24 additions & 0 deletions src/test/resources/curseforge/mappings/v1_mods_31043.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name" : "v1_mods_31043",
"request" : {
"url" : "/v1/mods/31043",
"method" : "GET"
},
"response" : {
"status" : 200,
"jsonBody" : {
"data": {
"name": "WorldEdit for Bukkit",
"links": {
"websiteUrl": "https://www.curseforge.com/minecraft/bukkit-plugins/worldedit",
"wikiUrl": "https://worldedit.enginehub.org/en/latest/",
"issuesUrl": "https://github.com/EngineHub/WorldEdit/issues",
"sourceUrl": "https://github.com/EngineHub/WorldEdit"
}
}
},
"headers" : {
"Content-Type" : "application/json; charset=utf-8"
}
}
}

0 comments on commit 4270ad1

Please sign in to comment.