forked from FabricMC/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
1035 lines (861 loc) · 28.4 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
buildscript {
repositories {
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
mavenCentral()
}
dependencies {
classpath "cuchaz:enigma-cli:${project.enigma_version}"
classpath "net.fabricmc:stitch:${project.stitch_version}"
classpath "commons-io:commons-io:2.8.0"
classpath 'de.undercouch:gradle-download-task:4.1.1'
classpath 'net.fabricmc:tiny-remapper:0.3.2'
classpath "net.fabricmc.unpick:unpick:${project.unpick_version}"
classpath "net.fabricmc.unpick:unpick-format-utils:${project.unpick_version}"
}
}
plugins {
id 'de.undercouch.download' version '4.1.1'
id 'base'
id 'maven-publish'
id 'java' // for jd gen
id 'org.cadixdev.licenser' version '0.5.1'
id 'net.fabricmc.filament' version '0.3.0'
}
def minecraft_version = "1.17.1-pre1"
def ENV = System.getenv()
// Fetch build number from Github Actions
def build_number = ENV.BUILD_NUMBER ?: "local"
def yarnVersion = "${minecraft_version}+build.$build_number"
version = yarnVersion
if (ENV.BRANCH_NAME) {
def branch = ENV.BRANCH_NAME.substring(ENV.BRANCH_NAME.lastIndexOf('/') + 1)
if (minecraft_version != branch) {
throw new IllegalStateException("Branch name (${branch}) does not match the mc version (${minecraft_version})")
}
}
repositories {
mavenCentral()
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
maven {
name "Mojang"
url 'https://libraries.minecraft.net/'
}
mavenLocal()
}
configurations {
enigmaRuntime {
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}
javadocClasspath
decompileClasspath
mappingPoetJar {
transitive = false
}
mappingPoet {
extendsFrom mappingPoetJar
transitive = true
}
unpick
}
def unpickMetaFile = file("unpick-definitions/unpick.json")
dependencies {
enigmaRuntime "cuchaz:enigma-swing:${project.enigma_version}"
enigmaRuntime "net.fabricmc:stitch:${project.stitch_version}"
javadocClasspath "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
javadocClasspath "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
javadocClasspath "com.google.code.findbugs:jsr305:3.0.2" // for some other jsr annotations
decompileClasspath "net.fabricmc:cfr:${project.cfr_version}"
mappingPoetJar "net.fabricmc:mappingpoet:${project.mappingpoet_version}"
unpick "net.fabricmc.unpick:unpick-cli:${project.unpick_version}"
}
def setupGroup = "jar setup"
def yarnGroup = "yarn"
def buildMappingGroup = "mapping build"
def mapJarGroup = "jar mapping"
def mappingsDir = file("mappings")
def cacheFilesMinecraft = file(".gradle/minecraft")
def tempDir = file(".gradle/temp")
def mergedFile = file("${minecraft_version}-merged.jar")
def intermediaryJar = file("${minecraft_version}-intermediary.jar")
def unpickedJar = file("${minecraft_version}-intermediary-unpicked.jar")
def namedJar = file("${minecraft_version}-named.jar")
def versionFile = new File(cacheFilesMinecraft, "${minecraft_version}.json")
def clientJar = new File(cacheFilesMinecraft, "${minecraft_version}-client.jar")
def serverJar = new File(cacheFilesMinecraft, "${minecraft_version}-server.jar")
def libraries = new File(cacheFilesMinecraft, "libraries")
def libs = new File("build/libs/")
import com.google.common.hash.Hashing
import cuchaz.enigma.command.CheckMappingsCommand
import cuchaz.enigma.command.ComposeMappingsCommand
import cuchaz.enigma.command.ConvertMappingsCommand
import cuchaz.enigma.command.MapSpecializedMethodsCommand
import groovy.io.FileType
import groovy.json.JsonSlurper
import net.fabricmc.stitch.commands.CommandMergeTiny
import net.fabricmc.stitch.commands.CommandProposeFieldNames
import net.fabricmc.stitch.commands.CommandReorderTiny
import net.fabricmc.stitch.commands.CommandRewriteIntermediary
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2
import net.fabricmc.stitch.commands.tinyv2.CommandProposeV2FieldNames
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2
import net.fabricmc.stitch.merge.JarMerger
import net.fabricmc.tinyremapper.OutputConsumerPath
import net.fabricmc.tinyremapper.TinyRemapper
import net.fabricmc.tinyremapper.TinyUtils
import org.apache.commons.io.FileUtils
import java.nio.charset.StandardCharsets
import java.util.zip.GZIPOutputStream
boolean validateChecksum(File file, String checksum) {
if (file != null) {
def hash = com.google.common.io.Files.asByteSource(file).hash(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 downloadVersionsManifest {
group = setupGroup
//inputs.property "mc_ver", minecraft_version
inputs.property "currenttime", new Date()
def manifestFile = new File(cacheFilesMinecraft, "version_manifest.json")
outputs.file(manifestFile)
doLast {
logger.lifecycle(":downloading minecraft versions manifest")
FileUtils.copyURLToFile(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifestFile)
}
}
def getManifestVersion(File manifestFile, String minecraft_version) {
def manifest = manifestFile.exists() ? new JsonSlurper().parseText(FileUtils.readFileToString(manifestFile)) : null
return manifest != null ? manifest.versions.stream().filter({
it.id.equals(minecraft_version)
}).findFirst() : java.util.Optional.empty()
}
task downloadWantedVersionManifest(dependsOn: downloadVersionsManifest) {
group = setupGroup
def manifestFile = downloadVersionsManifest.outputs.files.singleFile
def manifestVersion = getManifestVersion(manifestFile, minecraft_version)
//have to grab the release time as there's a current timestamp on each element?!
inputs.property "releaseTime", manifestVersion.isPresent() ? manifestVersion.get().releaseTime : -1
outputs.file versionFile
doLast {
manifestVersion = getManifestVersion(manifestFile, minecraft_version)
//nb need to re-read here in case it didn't exist before
if (manifestVersion.isPresent() || versionFile.exists()) {
if (manifestVersion.isPresent()) {
FileUtils.copyURLToFile(new URL(manifestVersion.get().url), versionFile)
}
} else {
throw new RuntimeException("No version data for Minecraft version ${minecraft_version}")
}
}
}
task downloadMcJars(dependsOn: downloadWantedVersionManifest) {
group = setupGroup
inputs.files versionFile
outputs.files(clientJar, serverJar)
outputs.upToDateWhen {
def version = new JsonSlurper().parseText(FileUtils.readFileToString(versionFile))
return clientJar.exists() && serverJar.exists() && validateChecksum(clientJar, version.downloads.client.sha1) && validateChecksum(serverJar, version.downloads.server.sha1)
}
doLast {
if (!versionFile.exists()) {
throw new RuntimeException("Can't download the jars without the ${versionFile.name} file!")
}
//reload in case it changed
def version = new JsonSlurper().parseText(FileUtils.readFileToString(versionFile))
logger.lifecycle(":downloading minecraft jars")
download {
src new URL(version.downloads.client.url)
dest clientJar
overwrite false
}
download {
src new URL(version.downloads.server.url)
dest serverJar
overwrite false
}
}
}
task downloadIntermediary(type: Download) {
group = buildMappingGroup
def url = "https://github.com/FabricMC/intermediary/raw/master/mappings/${minecraft_version}.tiny"
src com.google.common.net.UrlEscapers.urlFragmentEscaper().escape(url)
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary.tiny")
}
task downloadIntermediaryV2(type: Download) {
group = buildMappingGroup
def url = "https://maven.fabricmc.net/net/fabricmc/intermediary/${minecraft_version}/intermediary-${minecraft_version}-v2.jar"
src com.google.common.net.UrlEscapers.urlFragmentEscaper().escape(url)
dest new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-v2.jar")
}
task extractIntermediaryV2(dependsOn: downloadIntermediaryV2, type: Copy) {
def output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-v2.tiny")
from({ zipTree(downloadIntermediaryV2.dest) }) {
include 'mappings/mappings.tiny'
rename 'mappings.tiny', "../${output.name}"
}
into output.parentFile
}
task mergeJars(dependsOn: downloadMcJars) {
group = setupGroup
inputs.files downloadMcJars.outputs.files.files
outputs.file(mergedFile)
doLast {
logger.lifecycle(":merging jars")
def client = inputs.files.files.find { it.name.endsWith("-client.jar") }
def server = inputs.files.files.find { it.name.endsWith("-server.jar") }
def merged = mergedFile
if (merged.exists()) {
return
}
def jarMerger = new JarMerger(client, server, merged)
jarMerger.merge()
jarMerger.close()
}
}
task downloadMcLibs(dependsOn: downloadWantedVersionManifest) {
group = setupGroup
inputs.files versionFile
outputs.dir(libraries)
outputs.upToDateWhen { false }
doLast {
if (!versionFile.exists()) {
throw new RuntimeException("Can't download the jars without the ${versionFile.name} file!")
}
def version = new JsonSlurper().parseText(FileUtils.readFileToString(versionFile, StandardCharsets.UTF_8))
logger.lifecycle(":downloading minecraft libraries")
if (!libraries.exists()) {
libraries.mkdirs()
}
version.libraries.each {
def downloadUrl = it.downloads.artifact.url
download {
src downloadUrl
dest new File(libraries, downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1))
overwrite false
}
project.dependencies.add("decompileClasspath", it.name)
}
}
}
task invertIntermediary(dependsOn: downloadIntermediary, type: FileOutput) {
group = buildMappingGroup
def v1Input = downloadIntermediary.dest
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":building inverted intermediary")
String[] v1Args = [
v1Input.getAbsolutePath(),
output.getAbsolutePath(),
"intermediary", "official"
]
new CommandReorderTiny().run(v1Args)
}
}
task invertIntermediaryv2(dependsOn: extractIntermediaryV2, type: FileOutput) {
group = buildMappingGroup
def v2Input = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-v2.tiny")
output = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-inverted-v2.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":building inverted intermediary v2")
String[] v2Args = [
v2Input.getAbsolutePath(),
output.getAbsolutePath(),
"intermediary", "official"
]
new CommandReorderTinyV2().run(v2Args)
}
}
task patchIntermediary(dependsOn: [mergeJars, downloadIntermediary]) {
group = buildMappingGroup
def intermediaryTinyInput = downloadIntermediary.outputs.files.singleFile
def outputFile = new File(cacheFilesMinecraft, "${minecraft_version}-intermediary-full.tiny")
outputs.file(outputFile)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":patching intermediary")
String[] args = [
mergedFile.getAbsolutePath(),
intermediaryTinyInput.getAbsolutePath(),
outputFile.getAbsolutePath(),
"--writeAll"
]
new CommandRewriteIntermediary().run(args)
}
}
task mapIntermediaryJar(dependsOn: [downloadMcLibs, downloadIntermediary, mergeJars]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
outputs.file(intermediaryJar)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":mapping minecraft to intermediary")
def tinyInput = downloadIntermediary.dest
mapJar(intermediaryJar, mergedFile, tinyInput, libraries, "official", "intermediary")
}
}
task yarnUnpicked(dependsOn: "unpickIntermediaryJar") {
group = yarnGroup
doLast {
ant.setLifecycleLogLevel "WARN"
ant.java(
classname: 'cuchaz.enigma.gui.Main',
classpath: configurations.enigmaRuntime.asPath,
fork: true,
spawn: true
) {
jvmarg(value: "-Xmx2048m")
arg(value: '-jar')
arg(value: unpickedJar.getAbsolutePath())
arg(value: '-mappings')
arg(value: mappingsDir.getAbsolutePath())
arg(value: '-profile')
arg(value: 'enigma_profile.json')
}
}
}
task yarn(dependsOn: mapIntermediaryJar) {
group = yarnGroup
doLast {
ant.setLifecycleLogLevel "WARN"
ant.java(
classname: 'cuchaz.enigma.gui.Main',
classpath: configurations.enigmaRuntime.asPath,
fork: true,
spawn: true
) {
jvmarg(value: "-Xmx2048m")
arg(value: '-jar')
arg(value: intermediaryJar.getAbsolutePath())
arg(value: '-mappings')
arg(value: mappingsDir.getAbsolutePath())
arg(value: '-profile')
arg(value: 'enigma_profile.json')
}
}
}
task checkMappings(dependsOn: mapIntermediaryJar) {
group = buildMappingGroup
inputs.dir mappingsDir
doLast {
logger.lifecycle(":checking mappings")
String[] args = [
intermediaryJar.getAbsolutePath(),
mappingsDir.getAbsolutePath()
]
try {
new CheckMappingsCommand().run(args)
} catch (IllegalStateException ignored) {
// just print, don't fail the task
}
}
}
task buildYarnTiny(dependsOn: mapIntermediaryJar, type: WithV2FileOutput) {
group = buildMappingGroup
inputs.dir mappingsDir
if (!libs.exists()) {
libs.mkdirs()
}
v1Output = new File(tempDir, "yarn-mappings.tiny")
v2Output = new File(tempDir, "yarn-mappings-v2.tiny")
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":generating tiny mappings")
new MapSpecializedMethodsCommand().run(
intermediaryJar.getAbsolutePath(),
"enigma",
mappingsDir.getAbsolutePath(),
"tinyv2:intermediary:named",
v2Output.getAbsolutePath()
)
new ConvertMappingsCommand().run(
"tinyv2",
v2Output.getAbsolutePath(),
"tiny:intermediary:named",
v1Output.getAbsolutePath())
}
}
task mergeTiny(dependsOn: ["buildYarnTiny", "invertIntermediary"], type: FileOutput) {
group = buildMappingGroup
def yarnTinyInput = buildYarnTiny.v1Output
def intermediaryTinyInput = invertIntermediary.output
def unorderedResultMappings = new File(tempDir, "mappings-unordered.tiny")
output = new File(tempDir, "mappings.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":merging yarn and intermediary")
String[] args = [
intermediaryTinyInput.getAbsolutePath(),
yarnTinyInput.getAbsolutePath(),
unorderedResultMappings.getAbsolutePath(),
"intermediary",
"official"
]
new CommandMergeTiny().run(args)
logger.lifecycle(":reordering merged intermediary")
String[] args2 = [
unorderedResultMappings.getAbsolutePath(),
output.getAbsolutePath(),
"official", "intermediary", "named"
]
new CommandReorderTiny().run(args2)
}
}
task tinyJar(type: Jar, dependsOn: mergeTiny) {
group = buildMappingGroup
outputs.upToDateWhen { false }
archiveFileName = "yarn-${yarnVersion}.jar"
destinationDirectory.set(file("build/libs"))
classifier = ""
from(mergeTiny.output) {
rename { "mappings/mappings.tiny" }
}
}
task compressTiny(dependsOn: [tinyJar, mergeTiny], type: FileOutput) {
group = buildMappingGroup
def outputFile = new File(libs, "yarn-tiny-${yarnVersion}.gz")
outputs.file(outputFile)
output = outputFile
def inputFile = mergeTiny.output
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":compressing tiny mappings")
def buffer = new byte[1024]
def fileOutputStream = new FileOutputStream(outputFile)
def outputStream = new GZIPOutputStream(fileOutputStream)
def fileInputStream = new FileInputStream(inputFile)
def length
while ((length = fileInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length)
}
fileInputStream.close()
outputStream.finish()
outputStream.close()
}
}
clean.doFirst {
delete tempDir, cacheFilesMinecraft
}
tasks.build.dependsOn "compressTiny","tinyJar","v2UnmergedYarnJar", "v2MergedYarnJar"
task exportMappingsOfficial(dependsOn: downloadIntermediary) {
def composeInput = downloadIntermediary.dest
doLast {
logger.lifecycle(":exporting mappings")
String[] args = [
"tiny",
composeInput.getAbsolutePath(),
"enigma",
file("mappings/").getAbsolutePath(),
"enigma",
file("mappings_official/").getAbsolutePath(),
"right"
]
new ComposeMappingsCommand().run(args)
}
}
task importMappingsOfficial(dependsOn: invertIntermediary) {
def composeInput = invertIntermediary.output
doLast {
logger.lifecycle(":importing mappings")
String[] args = [
"tiny",
composeInput.getAbsolutePath(),
"enigma",
file("mappings_official/").getAbsolutePath(),
"enigma",
file("mappings/").getAbsolutePath(),
"right"
]
new ComposeMappingsCommand().run(args)
}
}
task buildTinyWithEnum(dependsOn: "mergeTiny", type: FileOutput) {
group = buildMappingGroup
def noEnum = mergeTiny.output
output = new File(tempDir, "named-with-enum.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":seeking auto-mappable fields")
String[] argsPropose = [
mergedFile.getAbsolutePath(), // must use official jar
noEnum.getAbsolutePath(),
output.getAbsolutePath()
]
new CommandProposeFieldNames().run(argsPropose)
}
}
task mapNamedJar(dependsOn: ["mergeV2", "unpickIntermediaryJar"]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
outputs.file(namedJar)
//Force the task to always run
outputs.upToDateWhen { false }
def jsrToJetbrains = [
"javax/annotation/Nullable": "org/jetbrains/annotations/Nullable",
"javax/annotation/Nonnull": "org/jetbrains/annotations/NotNull",
"javax/annotation/concurrent/Immutable": "org/jetbrains/annotations/Unmodifiable"
]
doLast {
logger.lifecycle(":mapping minecraft to named")
mapJar(namedJar, unpickedJar, mergeV2.output, libraries, "intermediary", "named") {
it.withMappings { out ->
jsrToJetbrains.each { e ->
out.acceptClass e.key, e.value
}
}
}
}
}
combineUnpickDefinitions {
group = 'unpick'
input = file('unpick-definitions')
output = new File(tempDir, 'definitions.unpick')
}
remapUnpickDefinitionsIntermediary {
dependsOn buildYarnTiny
group = 'unpick'
output = new File(tempDir, 'intermediary-definitions.unpick')
mappings = buildYarnTiny.v2Output
}
task unpickIntermediaryJar(type: JavaExec, dependsOn: [mapIntermediaryJar, "constantsJar", remapUnpickDefinitionsIntermediary]) {
outputs.upToDateWhen { false }
group "unpick"
main "daomephsta.unpick.cli.Main"
systemProperty "java.util.logging.config.file", file('unpick-logging.properties')
classpath configurations.unpick
doFirst {
args intermediaryJar.absolutePath, unpickedJar.absolutePath, remapUnpickDefinitionsIntermediary.output.get().asFile.absolutePath, constantsJar.archiveFile.get().asFile.absolutePath
configurations.decompileClasspath.files.each {
args it.absolutePath
}
}
}
// Setup the build for the unpicked constants
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = 8
}
}
sourceSets {
constants
packageDocs // package info files
}
license {
header file("HEADER")
sourceSets = [sourceSets.constants, sourceSets.packageDocs]
include '**/*.java'
}
task constantsJar(type: Jar) {
from sourceSets.constants.output
archiveClassifier = "constants"
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = "sources"
from sourceSets.constants.allSource
}
compilePackageDocsJava {
it.options.encoding = "UTF-8"
it.options.release = 16
}
// Only build jars for package infos if we need to actually expose stuff like annotation in the future.
// Also need to downgrade java in that case!
build.dependsOn constantsJar
task insertAutoGeneratedEnumMappings(dependsOn : [buildYarnTiny,mapIntermediaryJar], type : FileOutput){
group = buildMappingGroup
def noEnumV2 = buildYarnTiny.v2Output
output = new File(tempDir, "unmerged-named-v2-with-enum.tiny")
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":seeking auto-mappable fields for unmerged mappings")
String[] argsProposeV2 = [
intermediaryJar.getAbsolutePath(), // must use intermediary jar
noEnumV2.getAbsolutePath(),
output.getAbsolutePath(),
"false" // don't replace existing names right now
]
new CommandProposeV2FieldNames().run(argsProposeV2)
}
}
task mergeV2(dependsOn: ["v2UnmergedYarnJar", "invertIntermediaryv2"], type: FileOutput) {
def mergedV2 = new File(tempDir, "merged-v2.tiny");
output = new File(tempDir, "merged-reordered-v2.tiny")
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":merging yarn and intermediary v2")
String[] args = [
invertIntermediaryv2.output.getAbsolutePath(),
insertAutoGeneratedEnumMappings.output.getAbsolutePath(),
mergedV2.getAbsolutePath(),
"intermediary",
"official"
]
new CommandMergeTinyV2().run(args)
//Reorder the mappings to match the output of loom
args = [
mergedV2.getAbsolutePath(),
output.getAbsolutePath(),
"official",
"intermediary",
"named"
]
new CommandReorderTinyV2().run(args)
}
}
task v2UnmergedYarnJar(dependsOn: [insertAutoGeneratedEnumMappings, combineUnpickDefinitions], type: Jar) {
def mappings = insertAutoGeneratedEnumMappings.output
group = "mapping build"
outputs.upToDateWhen { false }
archiveFileName = "yarn-${yarnVersion}-v2.jar"
from(file(mappings)) {
rename mappings.name, "mappings/mappings.tiny"
}
from(combineUnpickDefinitions.output) {
rename combineUnpickDefinitions.output.get().asFile.name, "extras/definitions.unpick"
}
from (file(unpickMetaFile)) {
expand version: project.unpick_version
rename unpickMetaFile.name, "extras/unpick.json"
}
destinationDirectory.set(file("build/libs"))
}
task v2MergedYarnJar(dependsOn: ["mergeV2"], type: Jar) {
def mappings = mergeV2.output
group = "mapping build"
outputs.upToDateWhen { false }
archiveFileName = "yarn-${yarnVersion}-mergedv2.jar"
from(file(mappings)) {
rename mappings.name, "mappings/mappings.tiny"
}
from(combineUnpickDefinitions.output) {
rename combineUnpickDefinitions.output.get().asFile.name, "extras/definitions.unpick"
}
from (file(unpickMetaFile)) {
expand version: project.unpick_version
rename unpickMetaFile.name, "extras/unpick.json"
}
destinationDirectory.set(file("build/libs"))
}
def fakeSourceDir = file(".gradle/temp/fakeSource")
task genFakeSource(type: JavaExec, dependsOn: ["mergeV2", "mapNamedJar"]) {
group = "javadoc generation"
outputs.upToDateWhen { false }
main "net.fabricmc.mappingpoet.Main"
classpath configurations.mappingPoet
// use merged v2 so we have all namespaces in jd
args mergeV2.output.getAbsolutePath(), namedJar.getAbsolutePath(), fakeSourceDir.getAbsolutePath(), libraries.getAbsolutePath()
doLast {
logger.lifecycle ":Fake source generated"
}
}
task decompileCFR(type: JavaExec, dependsOn: [mapNamedJar]) {
doFirst {
classpath = configurations.decompileClasspath
}
main = "org.benf.cfr.reader.Main"
args namedJar.getAbsolutePath(), "--outputdir", file("namedSrc").absolutePath
doFirst {
file("namedSrc").deleteDir()
}
}
javadoc {
dependsOn genFakeSource
dependsOn downloadMcLibs
group = "javadoc generation"
outputs.upToDateWhen { false }
if (ENV.CI) {
// Java 17 is provided on CI to build the javadocs with, see https://github.com/FabricMC/yarn/issues/2429
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
def mappingPoetJar = project.provider { zipTree configurations.mappingPoetJar.singleFile }
failOnError = false
// verbose = true // enable to debug
options {
// verbose() // enable to debug
source = "16"
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PRIVATE
splitIndex true
tags(
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
taglets "net.fabricmc.mappingpoet.jd.MappingTaglet"
// taglet path, header, extra stylesheet settings deferred
it.use()
addBooleanOption "-allow-script-in-comments", true
links(
'https://guava.dev/releases/21.0/api/docs/',
'https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.0/',
'https://logging.apache.org/log4j/2.x/log4j-api/apidocs/',
"https://javadoc.io/doc/org.jetbrains/annotations/${project.jetbrains_annotations_version}/",
'https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/',
'https://javadoc.lwjgl.org/',
'https://fastutil.di.unimi.it/docs/',
'https://netty.io/4.1/api/',
'https://commons.apache.org/proper/commons-logging/javadocs/api-1.1.3/',
'https://commons.apache.org/proper/commons-lang/javadocs/api-3.5',
'https://commons.apache.org/proper/commons-io/javadocs/api-2.5',
'https://commons.apache.org/proper/commons-codec/archives/1.10/apidocs',
'https://commons.apache.org/proper/commons-compress/javadocs/api-1.8.1/',
"https://maven.fabricmc.net/docs/fabric-loader-${project.fabric_loader_version}/",
"https://docs.oracle.com/en/java/javase/16/docs/api/"
// Need to add loader jd publication for env annotations!
)
// https://docs.oracle.com/en/java/javase/15/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet
addBooleanOption 'Xdoclint:html', true
addBooleanOption 'Xdoclint:syntax', true
addBooleanOption 'Xdoclint:reference', true
addBooleanOption 'Xdoclint:accessibility', true
}
source fileTree(fakeSourceDir) + sourceSets.constants.allJava + sourceSets.packageDocs.allJava
classpath = configurations.javadocClasspath.plus downloadMcLibs.outputs.files.asFileTree
finalizedBy {
task copyCopyOnClickScript(type: Copy) {
from mappingPoetJar
include "copy_on_click.js"
into javadoc.outputDirectory
}
}
doFirst {
// lazy setting
options {
tagletPath configurations.mappingPoet.files.toList()
header mappingPoetJar.get().filter { it.name == 'javadoc_header.txt' }.singleFile.readLines()[0] // cannot include line breaks
addFileOption "-add-stylesheet", mappingPoetJar.get().filter { it.name == 'forms.css' }.singleFile
}
}
}
task javadocJar(type: Jar, dependsOn: ["javadoc"]) {
group = "javadoc generation"
from javadoc.destinationDir
archiveVersion.set yarnVersion
archiveClassifier = 'javadoc'
}
generatePackageInfoMappings {
dependsOn mapIntermediaryJar
inputJar = intermediaryJar
packageName = "net/minecraft/unused/packageinfo/"
outputDir = file("mappings/net/minecraft/unused/packageinfo")
}
javadocLint {
group = "javadoc generation"
mappingDirectory = file("mappings")
}
check.dependsOn javadocLint
publishing {
publications {
maven(MavenPublication) {
groupId 'net.fabricmc'
artifactId "yarn"
version yarnVersion
artifact(compressTiny.output) {
classifier "tiny"
builtBy compressTiny
}
artifact(tinyJar)
artifact(v2UnmergedYarnJar) {
classifier "v2"
}
artifact(v2MergedYarnJar) {
classifier "mergedv2"
}
artifact(constantsJar) {
classifier "constants"
}
artifact sourcesJar
artifact javadocJar
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/yarn/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
publish.mustRunAfter checkVersion
void mapJar(File output, File input, File mappings, File libraries, String from, String to,
Action<TinyRemapper.Builder> action = { }) {
if (output.exists()) {
output.delete()
}
def remapperBuilder = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings.toPath(), from, to))
.renameInvalidLocals(true)
.rebuildSourceFilenames(true)
action.execute(remapperBuilder)
def remapper = remapperBuilder
.build()
try {