22
33import java .io .File ;
44import java .io .IOException ;
5- import java .net .URI ;
65import java .nio .charset .Charset ;
76import java .nio .file .Files ;
87import java .nio .file .Path ;
5049import net .ornithemc .keratin .api .maven .SingleBuildMavenArtifacts ;
5150import net .ornithemc .keratin .api .settings .BuildNumbers ;
5251import net .ornithemc .keratin .api .settings .ProcessorSettings ;
52+ import net .ornithemc .keratin .api .task .Downloader ;
5353import net .ornithemc .keratin .api .task .MinecraftTask ;
5454import net .ornithemc .keratin .api .task .build .BuildMappingsJarTask ;
5555import 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
0 commit comments