Skip to content

Commit 8f03873

Browse files
committed
switch to Ornithe manifests
1 parent 28bf761 commit 8f03873

File tree

4 files changed

+44
-34
lines changed

4 files changed

+44
-34
lines changed

src/main/java/net/ornithemc/keratin/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class Constants {
55
public static final String ORNITHE_GLOBAL_CACHE_DIR = "ornithe-keratin";
66
public static final String ORNITHE_LOCAL_CACHE_DIR = "ornithe-keratin";
77

8-
public static final String VERSIONS_MANIFEST_URL = "https://ornithemc.net/mc-versions/version_manifest.json";
8+
public static final String VERSIONS_MANIFEST_URL = "https://ornithemc.net/mc-versions/gen%d/version_manifest.json";
99

1010
public static final String MAVEN_NAME = "Ornithe";
1111
public static final String MAVEN_URL = "https://maven.ornithemc.net/releases";

src/main/java/net/ornithemc/keratin/KeratinGradleExtension.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.io.IOException;
5-
import java.net.URI;
65
import java.nio.charset.Charset;
76
import java.nio.file.Files;
87
import java.nio.file.Path;
@@ -50,6 +49,7 @@
5049
import net.ornithemc.keratin.api.maven.SingleBuildMavenArtifacts;
5150
import net.ornithemc.keratin.api.settings.BuildNumbers;
5251
import net.ornithemc.keratin.api.settings.ProcessorSettings;
52+
import net.ornithemc.keratin.api.task.Downloader;
5353
import net.ornithemc.keratin.api.task.MinecraftTask;
5454
import net.ornithemc.keratin.api.task.build.BuildMappingsJarTask;
5555
import net.ornithemc.keratin.api.task.build.BuildMappingsTask;
@@ -197,18 +197,16 @@ public KeratinGradleExtension(Project project) {
197197
this.versionInfos = new Versioned<>(minecraftVersion -> {
198198
File file = this.files.getGlobalCache().getMetadataCache().getVersionInfoJson(minecraftVersion);
199199

200-
if (project.getGradle().getStartParameter().isRefreshDependencies() || !file.exists()) {
201-
VersionsManifest manifest = versionsManifest;
202-
VersionsManifest.Entry entry = manifest.findOrThrow(minecraftVersion);
200+
VersionsManifest manifest = versionsManifest;
201+
VersionsManifest.Entry entry = manifest.findOrThrow(minecraftVersion);
203202

204-
try {
205-
FileUtils.copyURLToFile(new URI(entry.url()).toURL(), file);
206-
} catch (IOException e) {
207-
// if the file already exits, just use it despite the download failing
208-
// it is likely still valid anyway
209-
if (!file.exists()) {
210-
throw new Exception("failed to download version info for " + minecraftVersion, e);
211-
}
203+
try {
204+
Downloader.download(project, entry.url(), entry.sha1(), file);
205+
} catch (Exception e) {
206+
// if the file already exits, just use it despite the download failing
207+
// it is likely still valid anyway
208+
if (!file.exists()) {
209+
throw new Exception("failed to download version info for " + minecraftVersion, e);
212210
}
213211
}
214212

@@ -220,18 +218,16 @@ public KeratinGradleExtension(Project project) {
220218
this.versionDetails = new Versioned<>(minecraftVersion -> {
221219
File file = this.files.getGlobalCache().getMetadataCache().getVersionDetailJson(minecraftVersion);
222220

223-
if (project.getGradle().getStartParameter().isRefreshDependencies() || !file.exists()) {
224-
VersionsManifest manifest = versionsManifest;
225-
VersionsManifest.Entry entry = manifest.findOrThrow(minecraftVersion);
221+
VersionsManifest manifest = versionsManifest;
222+
VersionsManifest.Entry entry = manifest.findOrThrow(minecraftVersion);
226223

227-
try {
228-
FileUtils.copyURLToFile(new URI(entry.details()).toURL(), file);
229-
} catch (IOException e) {
230-
// if the file already exits, just use it despite the download failing
231-
// it is likely still valid anyway
232-
if (!file.exists()) {
233-
throw new Exception("failed to download version details for " + minecraftVersion, e);
234-
}
224+
try {
225+
Downloader.download(project, entry.details(), entry.detailsSha1(), file);
226+
} catch (Exception e) {
227+
// if the file already exits, just use it despite the download failing
228+
// it is likely still valid anyway
229+
if (!file.exists()) {
230+
throw new Exception("failed to download version details for " + minecraftVersion, e);
235231
}
236232
}
237233

@@ -355,15 +351,13 @@ private Set<MinecraftVersion> configure(TaskSelection selection) throws Exceptio
355351

356352
File manifestFile = files.getGlobalCache().getVersionsManifestJson();
357353

358-
if (project.getGradle().getStartParameter().isRefreshDependencies() || !manifestFile.exists()) {
359-
try {
360-
FileUtils.copyURLToFile(new URI(versionsManifestUrl.get()).toURL(), manifestFile);
361-
} catch (IOException e) {
362-
// if the file already exits, just use it despite the download failing
363-
// it is likely still valid anyway
364-
if (!manifestFile.exists()) {
365-
throw new Exception("failed to download versions manifest!", e);
366-
}
354+
try {
355+
Downloader.download(project, String.format(versionsManifestUrl.get(), intermediaryGen.get()), null, manifestFile, true);
356+
} catch (Exception e) {
357+
// if the file already exits, just use it despite the download failing
358+
// it is likely still valid anyway
359+
if (!manifestFile.exists()) {
360+
throw new Exception("failed to download versions manifest!", e);
367361
}
368362
}
369363

src/main/java/net/ornithemc/keratin/api/manifest/VersionsManifest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public record VersionsManifest(List<Entry> versions) {
77

8-
public record Entry(String id, String url, String details) {
8+
public record Entry(String id, String url, String sha1, String details, String detailsSha1) {
99
}
1010

1111
public Optional<Entry> find(String version) {

src/main/java/net/ornithemc/keratin/api/task/Downloader.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,20 @@ private static boolean validateChecksum(File file, String sha1) throws IOExcepti
7575

7676
return sb.toString().equals(sha1);
7777
}
78+
79+
public static void download(Project project, String url, String sha1, File output) throws Exception {
80+
download(project, url, sha1, output, false);
81+
}
82+
83+
public static void download(Project project, String url, String sha1, File output, boolean overwrite) throws Exception {
84+
if (overwrite || !output.exists() || project.getGradle().getStartParameter().isRefreshDependencies() || !validateChecksum(output, sha1)) {
85+
DownloadAction downloader = new DownloadAction(project);
86+
87+
downloader.src(new URI(url));
88+
downloader.dest(output);
89+
downloader.overwrite(true);
90+
91+
downloader.execute().join();
92+
}
93+
}
7894
}

0 commit comments

Comments
 (0)