forked from FabricMC/yarn
-
Notifications
You must be signed in to change notification settings - Fork 119
/
build.gradle
200 lines (156 loc) · 6.24 KB
/
build.gradle
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
buildscript {
repositories {
jcenter()
maven {
name = "Fabric"
url = "http://maven.fabricmc.net/"
}
}
dependencies {
classpath "net.fabricmc:blending-jar:0.1.1.6"
classpath "commons-io:commons-io:1.4"
classpath "com.google.guava:guava:19.0"
}
}
def minecraft_version = "16w38a"
def pomfVersion = "${minecraft_version}"
def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
pomfVersion = pomfVersion + "." + "${System.getenv().BUILD_NUMBER}"
}
import groovy.json.JsonSlurper
import org.apache.commons.io.FileUtils
import com.google.common.hash.HashCode
import com.google.common.hash.Hashing
import com.google.common.io.Files
import net.fabricmc.blendingjar.JarMerger
import groovy.util.XmlSlurper
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import java.io.File;
boolean validateChecksum(File file, String checksum) {
if (file != null) {
def hash = Files.hash(file, Hashing.sha1())
def builder = new StringBuilder()
hash.asBytes().each {
builder.append(Integer.toString((it & 0xFF) + 0x100, 16).substring(1))
}
return builder.toString().equals(checksum)
}
return false
}
task download << {
def cacheFiles = new File(".gradle/minecraft")
if (!cacheFiles.exists()) cacheFiles.mkdirs()
def manifestFile = new File(cacheFiles, "version_manifest.json")
logger.lifecycle(":downloading minecraft json")
FileUtils.copyURLToFile(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifestFile)
def manifest = new JsonSlurper().parseText(FileUtils.readFileToString(manifestFile))
def manifestVersion = manifest.versions.stream().filter({ it.id.equals(minecraft_version) }).findFirst()
if (manifestVersion.isPresent()) {
def versionFile = new File(cacheFiles, "${minecraft_version}.json")
FileUtils.copyURLToFile(new URL(manifestVersion.get().url), versionFile)
def version = new JsonSlurper().parseText(FileUtils.readFileToString(versionFile))
def clientJar = new File(cacheFiles, "${minecraft_version}-client.jar")
def serverJar = new File(cacheFiles, "${minecraft_version}-server.jar")
if (!clientJar.exists() || !validateChecksum(clientJar, version.downloads.client.sha1)) {
logger.lifecycle(":downloading minecraft client")
FileUtils.copyURLToFile(new URL(version.downloads.client.url), clientJar)
}
if (!serverJar.exists() || !validateChecksum(serverJar, version.downloads.server.sha1)) {
logger.lifecycle(":downloading minecraft server")
FileUtils.copyURLToFile(new URL(version.downloads.server.url), serverJar)
}
} else {
throw new RuntimeException("No version data for Minecraft version ${minecraft_version}")
}
}
task mergeJars << {
def mergedFile = new File("${minecraft_version}-merged.jar")
if (!mergedFile.exists()) {
def cacheFiles = new File(".gradle/minecraft")
def client = new FileInputStream(new File(cacheFiles, "${minecraft_version}-client.jar"))
def server = new FileInputStream(new File(cacheFiles, "${minecraft_version}-server.jar"))
def merged = new FileOutputStream(mergedFile)
def jarMerger = new JarMerger(client, server, merged)
jarMerger.merge()
jarMerger.close()
client.close()
server.close()
merged.close()
}
}
tasks.mergeJars.dependsOn "download"
task setupPomf << {
}
tasks.setupPomf.dependsOn "mergeJars"
task pomf << {
def cacheFiles = new File(".gradle/enigma")
if (!cacheFiles.exists()) cacheFiles.mkdirs()
def mavenMetadata = new File(cacheFiles, "maven-metadata.xml")
logger.lifecycle(":downloading enigma metadata")
FileUtils.copyURLToFile(new URL("http://maven.fabricmc.net/cuchaz/enigma/maven-metadata.xml"), mavenMetadata)
def metadata = new XmlSlurper().parseText(FileUtils.readFileToString(mavenMetadata))
def enigmaVersion = metadata.versioning.release
def enigma = new File(cacheFiles, "${enigmaVersion}.jar")
logger.lifecycle(":downloading enigma")
FileUtils.copyURLToFile(new URL("http://maven.fabricmc.net/cuchaz/enigma/${enigmaVersion}/enigma-${enigmaVersion}-all.jar"), enigma)
logger.lifecycle(":launching enigma")
ant.java(jar: enigma.getAbsolutePath(), fork: true, spawn: true) {
arg(value: new File("${minecraft_version}-merged.jar").getAbsolutePath())
arg(value: new File("mappings/").getAbsolutePath())
}
}
tasks.pomf.dependsOn "setupPomf"
task build(type: Zip) {
from "mappings/"
include "**/*"
archiveName "pomf-enigma-${pomfVersion}.zip"
destinationDir(file("build/libs"))
}
task buildTiny << {
def cacheFiles = new File(".gradle/weave")
if (!cacheFiles.exists()) cacheFiles.mkdirs()
def mavenMetadata = new File(cacheFiles, "maven-metadata.xml")
logger.lifecycle(":downloading weave metadata")
FileUtils.copyURLToFile(new URL("http://maven.fabricmc.net/net/fabricmc/weave/maven-metadata.xml"), mavenMetadata)
def metadata = new XmlSlurper().parseText(FileUtils.readFileToString(mavenMetadata))
def weaveVersion = metadata.versioning.release
def weave = new File(cacheFiles, "${weaveVersion}.jar")
if(!weave.exists()){
logger.lifecycle(":downloading weave")
FileUtils.copyURLToFile(new URL("http://maven.fabricmc.net/net/fabricmc/weave/${weaveVersion}/weave-${weaveVersion}-fat.jar"), weave)
}
logger.lifecycle(":generating tiny mappings")
ant.java(jar: weave.getAbsolutePath(), fork: true, spawn: false) {
arg(value : "tinyify")
arg(value: new File("${minecraft_version}-merged.jar").getAbsolutePath())
arg(value: new File("mappings").getAbsolutePath())
arg(value : "mappings.tiny")
arg(value : "mojang")
arg(value : "pomf")
}
logger.lifecycle(":compressing tiny mappings")
def libs = new File("build/libs/")
if(!libs.exists()){
libs.mkdirs()
}
def buffer = new byte[1024]
def outputFile = new File(libs, "pomf-tiny-${pomfVersion}.gz")
def fileOutputStream = new FileOutputStream(outputFile)
def outputStream = new GZIPOutputStream(fileOutputStream)
def inputFile = new File("mappings.tiny")
def fileInputStream = new FileInputStream(inputFile)
def length;
while ((length = fileInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
fileInputStream.close()
outputStream.finish()
outputStream.close()
inputFile.delete()
}
tasks.buildTiny.dependsOn "mergeJars"
tasks.build.dependsOn "buildTiny"