Skip to content

Commit

Permalink
Add an option to warn about misses in the artifact manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed May 31, 2024
1 parent 9a10577 commit 6379ec6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.neoforged.neoform.runtime.manifests.LauncherManifest;
import net.neoforged.neoform.runtime.manifests.MinecraftLibrary;
import net.neoforged.neoform.runtime.manifests.MinecraftVersionManifest;
import net.neoforged.neoform.runtime.utils.AnsiColor;
import net.neoforged.neoform.runtime.utils.FilenameUtil;
import net.neoforged.neoform.runtime.utils.Logger;
import net.neoforged.neoform.runtime.utils.MavenCoordinate;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class ArtifactManager {
private final URI launcherManifestUrl;
private final Path artifactsCache;
private final Map<MavenCoordinate, Artifact> externallyProvided = new HashMap<>();
private boolean warnOnArtifactManifestMiss;

public ArtifactManager(List<URI> repositoryBaseUrls,
CacheManager cacheManager,
Expand All @@ -62,6 +64,8 @@ public Artifact get(MinecraftLibrary library) throws IOException {
var artifactCoordinate = MavenCoordinate.parse(library.artifactId());
if (externallyProvided.containsKey(artifactCoordinate)) {
return externallyProvided.get(artifactCoordinate);
} else if (warnOnArtifactManifestMiss && !externallyProvided.isEmpty()) {
LOG.println(" " + AnsiColor.YELLOW + "WARNING: " + AnsiColor.RESET + library.artifactId() + " is not present in the artifact manifest");
}

var finalLocation = artifactsCache.resolve(artifactCoordinate.toRelativeRepositoryPath());
Expand Down Expand Up @@ -255,4 +259,12 @@ private Artifact download(Path finalLocation, URI uri) throws IOException {
private Artifact download(Path finalLocation, DownloadSpec spec) throws IOException {
return download(finalLocation, () -> downloadManager.download(spec, finalLocation));
}

public boolean isWarnOnArtifactManifestMiss() {
return warnOnArtifactManifestMiss;
}

public void setWarnOnArtifactManifestMiss(boolean warnOnArtifactManifestMiss) {
this.warnOnArtifactManifestMiss = warnOnArtifactManifestMiss;
}
}
5 changes: 4 additions & 1 deletion src/main/java/net/neoforged/neoform/runtime/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public class Main {
@Option(names = "--artifact-manifest", scope = ScopeType.INHERIT)
Path artifactManifest;

@CommandLine.Option(names = "--launcher-meta-uri", scope = CommandLine.ScopeType.INHERIT)
@Option(names = "--warn-on-artifact-manifest-miss", scope = ScopeType.INHERIT, description = "Warns when an artifact manifest is given, but a file is being downloaded that is not in the manifest.")
boolean warnOnArtifactManifestMiss;

@Option(names = "--launcher-meta-uri", scope = ScopeType.INHERIT)
URI launcherManifestUrl = URI.create("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json");

@Option(names = "--verbose", description = "Enable verbose output", scope = ScopeType.INHERIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public final Integer call() throws Exception {

lockManager.setVerbose(commonOptions.verbose);
var artifactManager = new ArtifactManager(commonOptions.getEffectiveRepositories(), cacheManager, downloadManager, lockManager, commonOptions.launcherManifestUrl);
artifactManager.setWarnOnArtifactManifestMiss(commonOptions.warnOnArtifactManifestMiss);

if (commonOptions.artifactManifest != null) {
artifactManager.loadArtifactManifest(commonOptions.artifactManifest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public enum AnsiColor {
//Color end string, color reset
RESET("0"),

YELLOW("33"),

BOLD("1"),
ITALIC("3"),
UNDERLINE("4"),
Expand Down

0 comments on commit 6379ec6

Please sign in to comment.