-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVersionDownload.java
More file actions
74 lines (59 loc) · 2.79 KB
/
VersionDownload.java
File metadata and controls
74 lines (59 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.parchmentmc.compass.tasks;
import de.undercouch.gradle.tasks.download.DownloadAction;
import org.gradle.api.DefaultTask;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.parchmentmc.compass.CompassPlugin;
import org.parchmentmc.feather.manifests.VersionManifest;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import static org.parchmentmc.compass.util.download.DownloadUtil.createAndExecuteAction;
import static org.parchmentmc.compass.util.download.DownloadUtil.verifyChecksum;
public abstract class VersionDownload extends DefaultTask {
private final RegularFileProperty output;
@Inject
public VersionDownload(final ObjectFactory objects) {
CompassPlugin plugin = getProject().getPlugins().getPlugin(CompassPlugin.class);
getManifest().convention(plugin.getManifestsDownloader().getVersionManifest());
getDownloadKey().convention("client");
getDestinationDirectory().convention(getProject().getLayout().getBuildDirectory().dir("downloads"));
getFileName().convention(getManifest().map(VersionManifest::getId).zip(getDownloadKey(), (ver, key) -> ver + '-' + key + ".jar"));
output = objects.fileProperty()
.convention(getDestinationDirectory().file(getFileName()));
}
@Input
public abstract Property<VersionManifest> getManifest();
@Input
public abstract Property<String> getDownloadKey();
@Internal("Represented as part of outputFile")
public abstract DirectoryProperty getDestinationDirectory();
@Internal("Represented as part of outputFile")
public abstract Property<String> getFileName();
@OutputFile
public Provider<RegularFile> getOutputFile() {
return output;
}
@TaskAction
public void download() throws IOException {
VersionManifest manifest = getManifest().get();
String key = getDownloadKey().get();
File output = getOutputFile().get().getAsFile();
VersionManifest.DownloadInfo info = manifest.getDownloads().get(key);
if (info == null) {
throw new InvalidUserDataException("No download info for key " + key);
}
DownloadAction action = createAndExecuteAction(getProject(), info.getUrl(), output, "download entry for key " + key);
verifyChecksum(output, info.getSHA1(), "download entry for key " + key);
setDidWork(!action.isUpToDate());
}
}