forked from OrnitheMC/feather-mappings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
1442 lines (1203 loc) · 41.3 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
import com.google.common.hash.Hashing
import com.google.common.io.Files
import com.google.common.net.UrlEscapers
import com.strobel.assembler.metadata.JarTypeLoader
import com.strobel.decompiler.Decompiler
import com.strobel.decompiler.DecompilerSettings
import com.strobel.decompiler.PlainTextOutput
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 groovy.xml.XmlSlurper
import net.fabricmc.stitch.commands.CommandMergeTiny
import net.fabricmc.stitch.commands.CommandProposeFieldNames
import net.fabricmc.stitch.commands.CommandReorderTiny
import net.fabricmc.stitch.commands.CommandRewriteCalamus
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 net.ornithemc.nester.Nester
import net.ornithemc.nester.nest.NesterIo
import net.ornithemc.nester.nest.Nests
import net.ornithemc.mappingutils.MappingUtils;
import net.ornithemc.mappingutils.PropagationDirection;
import net.ornithemc.mappingutils.PropagationOptions;
import net.ornithemc.mappingutils.io.Format;
import net.ornithemc.mappingutils.io.Mappings;
import net.ornithemc.mappingutils.io.Mappings.ClassMapping;
import net.ornithemc.mappingutils.io.Mappings.FieldMapping;
import net.ornithemc.mappingutils.io.Mappings.MethodMapping;
import net.ornithemc.mappingutils.io.Mappings.ParameterMapping;
import net.ornithemc.mappingutils.io.MappingTarget;
import net.ornithemc.mappingutils.io.MappingValidator;
import net.ornithemc.mappingutils.io.diff.DiffSide;
import net.ornithemc.mappingutils.io.diff.MappingsDiff;
import net.ornithemc.mappingutils.io.diff.MappingsDiff.ClassDiff;
import net.ornithemc.mappingutils.io.diff.MappingsDiff.Diff;
import net.ornithemc.mappingutils.io.diff.MappingsDiff.FieldDiff;
import net.ornithemc.mappingutils.io.diff.MappingsDiff.MethodDiff;
import net.ornithemc.mappingutils.io.diff.MappingsDiff.ParameterDiff;
import net.ornithemc.mappingutils.io.diff.MappingsDiffValidator;
import net.ornithemc.mappingutils.io.diff.graph.VersionGraph;
import org.apache.commons.io.FileUtils
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.jar.JarFile
import java.util.zip.GZIPOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
buildscript {
repositories {
maven {
name "Ornithe"
url "https://maven.ornithemc.net/releases"
}
maven {
name 'Quilt Repository'
url 'https://maven.quiltmc.org/repository/release/'
}
maven {
name 'Quilt Snapshot Repository'
url 'https://maven.quiltmc.org/repository/snapshot/'
}
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
maven {
name "Vineflower Snapshots"
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
mavenCentral()
}
dependencies {
classpath "net.ornithemc:enigma-cli:${project.enigma_version}"
classpath "net.ornithemc:stitch:${project.stitch_version}"
classpath "net.ornithemc:tiny-remapper:0.8.4"
classpath "net.ornithemc:nester:${project.nester_version}"
classpath "net.ornithemc:mapping-utils:${project.mapping_utils_version}"
classpath "commons-io:commons-io:2.8.0"
classpath 'de.undercouch:gradle-download-task:4.1.1'
classpath "org.quiltmc:quilt-enigma-plugin:${project.quilt_enigma_plugin_version}"
classpath "net.fabricmc.unpick:unpick:${project.unpick_version}"
classpath "net.fabricmc.unpick:unpick-format-utils:${project.unpick_version}"
classpath "org.codehaus.groovy:groovy-json:3.0.9"
classpath "org.codehaus.groovy:groovy-xml:3.0.9"
}
}
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.6.1'
id 'net.fabricmc.filament' version '0.3.0'
}
def ENV = System.getenv()
def version_id = ENV.MC_VERSION ?: {
project.logger.error("MC_VERSION environment variable not set, defaulting to 1.3-pre-07261249")
return "1.3-pre-07261249"
}()
def environment = parseEnvironment(version_id)
def minecraft_version = parseVersion(version_id, environment)
def featherVersion = nextFeatherVersion(ENV, version_id)
enum Environment {
MERGED, CLIENT, SERVER
public boolean isMerged() {
return this == MERGED
}
public boolean isClient() {
return this == MERGED || this == CLIENT
}
public boolean isServer() {
return this == MERGED || this == SERVER
}
}
static Environment parseEnvironment(String id) {
if (id.endsWith("-client")) {
return Environment.CLIENT
}
if (id.endsWith("-server")) {
return Environment.SERVER
}
return Environment.MERGED
}
static String parseVersion(String id, Environment environment) {
switch (environment) {
case Environment.CLIENT:
return id.substring(0, id.length() - "-client".length())
case Environment.SERVER:
return id.substring(0, id.length() - "-server".length())
case Environment.MERGED:
return id
}
}
static def nextFeatherVersion(ENV, version_id) {
if (ENV.MAVEN_URL) {
def build_number = 0
try {
def xml = new URL("https://maven.ornithemc.net/releases/net/ornithemc/feather/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def version_build = "${version_id}+build."
def i = version_build.length()
metadata.versioning.versions.version.each {
def version = it.text()
if (version.startsWith(version_build)) {
def number_text = version.substring(i)
try {
def number = Integer.parseInt(number_text)
if (number > build_number) {
build_number = number
}
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
}
}
} catch (FileNotFoundException e) {
// Note: we consider it a hard failure if the maven-metadata.xml file does
// not exist. However if you don't have this file yet, you can comment out
// the line below to start at build number 1.
throw new RuntimeException(e);
}
// is 0 if no version is found in the above
def next_build_number = build_number + 1;
return "${version_id}+build.${next_build_number}"
} else {
return "${version_id}+build.local"
}
}
repositories {
mavenCentral()
maven {
name "Ornithe"
url "https://maven.ornithemc.net/releases"
}
maven {
name "Mojang"
url 'https://libraries.minecraft.net/'
}
maven {
name 'Quilt Repository'
url 'https://maven.quiltmc.org/repository/release/'
}
maven {
name 'Quilt Snapshot Repository'
url 'https://maven.quiltmc.org/repository/snapshot/'
}
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
maven {
name "Procyon Repository"
url 'https://oss.sonatype.org'
}
maven {
name "Vineflower Snapshots"
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}
configurations {
enigmaRuntime
javadocClasspath
decompileClasspath
mappingPoetJar {
transitive = false
}
mappingPoet {
extendsFrom mappingPoetJar
transitive = true
}
}
dependencies {
enigmaRuntime "net.ornithemc:enigma-swing:${project.enigma_version}"
enigmaRuntime "org.quiltmc:quilt-enigma-plugin:${project.quilt_enigma_plugin_version}"
javadocClasspath "org.quiltmc:quilt-loader:${project.quilt_loader_version}"
javadocClasspath "com.google.code.findbugs:jsr305:3.0.2"
decompileClasspath "net.fabricmc:cfr:${project.cfr_version}"
decompileClasspath "org.quiltmc:quiltflower:${project.quiltflower_version}"
implementation "net.fabricmc:procyon-fabric-compilertools:${project.procyon_version}"
mappingPoetJar "net.fabricmc:mappingpoet:${project.mapping_poet_version}"
}
def setupGroup = "jar setup"
def featherGroup = "feather"
def buildMappingGroup = "mapping build"
def mapJarGroup = "jar mapping"
def mappingsDir = file("mappings/")
def workingDir = file("run/")
def workingMappings = new File(workingDir, "${version_id}")
def cacheFilesMinecraft = new File(project.gradle.gradleUserHomeDir, "caches/feather-build-cache/")
def tempDir = file(".gradle/temp")
def mergedJar = new File(cacheFilesMinecraft, "merged/${version_id}-merged.jar")
def namedJarsDir = new File(cacheFilesMinecraft, "named-jars/")
def calamusJar = new File(namedJarsDir, "${version_id}-calamus.jar")
def nestedJar = new File(namedJarsDir, "${version_id}-calamus-nested.jar")
def namedJar = new File(namedJarsDir, "${version_id}-named.jar")
def versionDetails = null
def versionJsons = new File(cacheFilesMinecraft, "version-jsons/")
def versionFile = new File(versionJsons, "${minecraft_version}.json")
def versionDetailsFile = new File(versionJsons, "${minecraft_version}-details.json")
def gameJars = new File(cacheFilesMinecraft, "game-jars/")
def clientJar = new File(gameJars, "${minecraft_version}-client.jar")
def serverJar = new File(gameJars, "${minecraft_version}-server.jar")
def mappingsCacheDir = new File(cacheFilesMinecraft, "mappings/")
def calamusV1File = new File(mappingsCacheDir, "${version_id}-calamus.tiny")
def calamusV2File = new File(mappingsCacheDir, "${version_id}-calamus-v2.tiny")
def nestsFile = new File(mappingsCacheDir, "${version_id}.nest")
def calamusNestsFile = new File(mappingsCacheDir, "${version_id}-calamus.nest")
def mainJar = null
def libraries = new File(cacheFilesMinecraft, "libraries/")
def libs = new File("build/libs/")
def namespace = "intermediary"
def REMOVE_DUMMY = new MappingValidator() {
@Override
public boolean validate(ClassMapping c) {
if (!MappingsDiff.safeIsDiff(ClassMapping.getSimplified(c.src()), c.get()) && (c.get().startsWith("C_") || c.get().startsWith("net/minecraft/unmapped/C_"))) {
c.set("");
return !c.getJavadoc().isEmpty() || c.hasChildren();
}
return true;
}
@Override
public boolean validate(FieldMapping f) {
if (!MappingsDiff.safeIsDiff(f.src(), f.get()) && f.get().startsWith("f_")) {
f.set("");
return !f.getJavadoc().isEmpty();
}
return true;
}
@Override
public boolean validate(MethodMapping m) {
if (!MappingsDiff.safeIsDiff(m.src(), m.get()) && (m.get().startsWith("m_") || m.get().equals("<init>") || m.get().equals("<clinit>"))) {
m.set("");
return !m.getJavadoc().isEmpty() || m.hasChildren();
}
return true;
}
@Override
public boolean validate(ParameterMapping p) {
if (p.get().startsWith("p_")) {
p.set("");
return !p.getJavadoc().isEmpty();
}
return true;
}
};
def INSERT_DUMMY = new MappingsDiffValidator() {
@Override
public boolean validate(ClassDiff c) {
return check(c);
}
@Override
public boolean validate(FieldDiff f) {
return check(f);
}
@Override
public boolean validate(MethodDiff m) {
return check(m);
}
@Override
public boolean validate(ParameterDiff p) {
return check(p);
}
private boolean check(Diff d) {
if (d.isDiff()) {
if (d.get(DiffSide.A).isEmpty()) {
// new mappings should be ignored, as any un-mapped members
// should already be present as dummy mappings
System.out.println("ignoring illegal change " + d);
return false;
}
if (d.get(DiffSide.B).isEmpty()) {
// removing a mapping is changed into a dummy mapping
if (d.target() == MappingTarget.CLASS) {
d.set(DiffSide.B, ClassMapping.getSimplified(d.src()));
} else if (d.target() == MappingTarget.PARAMETER) {
d.set(DiffSide.B, "p_" + ((ParameterDiff)d).getIndex());
} else {
d.set(DiffSide.B, d.src());
}
}
}
return true;
}
};
static boolean validateChecksum(File file, String checksum) {
if (file != null) {
//noinspection GrDeprecatedAPIUsage
def hash = 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() == 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_v2.json")
outputs.file(manifestFile)
doLast {
logger.lifecycle(":downloading minecraft versions manifest")
FileUtils.copyURLToFile(new URL("https://skyrising.github.io/mc-versions/version_manifest.json"), manifestFile)
}
}
static def getManifestVersion(File manifestFile, String minecraft_version) {
def manifest = manifestFile.exists() ? new JsonSlurper().parseText(FileUtils.readFileToString(manifestFile, Charset.defaultCharset())) : null
return manifest != null ? manifest.versions.stream().filter({
(it.id == 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
outputs.upToDateWhen {
return false
}
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} (Did you forget to set the MC_VERSION environment variable?)")
}
}
}
task downloadVersionDetails(dependsOn: downloadVersionsManifest) {
group = setupGroup
def manifestFile = downloadVersionsManifest.outputs.files.singleFile
def manifestVersion = getManifestVersion(manifestFile, minecraft_version)
inputs.property "manifestUrl", manifestVersion.isPresent() ? manifestVersion.get().url : -1
outputs.file versionDetailsFile
outputs.upToDateWhen {
return false
}
doLast {
manifestVersion = getManifestVersion(manifestFile, minecraft_version)
//nb need to re-read here in case it didn't exist before
if (manifestVersion.isPresent() || versionDetailsFile.exists()) {
if (manifestVersion.isPresent()) {
FileUtils.copyURLToFile(new URL(manifestVersion.get().details), versionDetailsFile)
}
} else {
throw new RuntimeException("No version details for Minecraft version ${minecraft_version} (Did you forget to set the MC_VERSION environment variable?)")
}
versionDetails = new JsonSlurper().parseText(FileUtils.readFileToString(versionDetailsFile, Charset.defaultCharset()))
if (versionDetails.sharedMappings) {
if (!environment.isMerged()) {
throw new RuntimeException("Minecraft version ${minecraft_version} is only available as merged but was requested for ${environment}!")
}
} else {
if (environment.isMerged()) {
throw new RuntimeException("Minecraft version ${minecraft_version} cannot be merged - please select either the client or server environment!")
}
if (environment.isClient() && !versionDetails.client) {
throw new RuntimeException("Minecraft version ${minecraft_version} does not have a client jar!")
}
if (environment.isServer() && !versionDetails.server) {
throw new RuntimeException("Minecraft version ${minecraft_version} does not have a server jar!")
}
}
switch (environment) {
case Environment.CLIENT:
mainJar = clientJar
break
case Environment.SERVER:
mainJar = serverJar
break
case Environment.MERGED:
mainJar = mergedJar
break
}
}
}
task downloadMcJars(dependsOn: downloadVersionDetails) {
group = setupGroup
inputs.files versionDetailsFile
outputs.files(clientJar, serverJar)
outputs.upToDateWhen {
def validClient = (!environment.isClient() || (clientJar.exists() && validateChecksum(clientJar, versionDetails.downloads.client.sha1)))
def validServer = (!environment.isServer() || (serverJar.exists() && validateChecksum(serverJar, versionDetails.downloads.server.sha1)))
return validClient && validServer
}
doLast {
if (!versionDetailsFile.exists() || versionDetails == null) {
throw new RuntimeException("Can't download the jars without the ${versionDetailsFile.name} file!")
}
logger.lifecycle(":downloading minecraft jar(s) for ${version_id}")
if (environment.isClient()) {
download {
src new URL(versionDetails.downloads.client.url)
dest clientJar
overwrite false
}
}
if (environment.isServer()) {
download {
src new URL(versionDetails.downloads.server.url)
dest serverJar
overwrite false
}
}
}
}
task downloadCalamus(type: Download) {
group = buildMappingGroup
def url = "https://github.com/OrnitheMC/calamus/raw/main/mappings/${version_id}.tiny"
src UrlEscapers.urlFragmentEscaper().escape(url)
dest calamusV1File
}
task downloadCalamusV2(type: Download) {
group = buildMappingGroup
def url = "https://maven.ornithemc.net/releases/net/ornithemc/calamus-${namespace}/${version_id}/calamus-${namespace}-${version_id}-v2.jar"
src UrlEscapers.urlFragmentEscaper().escape(url)
dest new File(mappingsCacheDir, "${version_id}-calamus-v2.jar")
outputs.file(calamusV2File)
doLast {
copy {
from({ zipTree(downloadCalamusV2.dest) }) {
from 'mappings/mappings.tiny'
rename 'mappings.tiny', "../${calamusV2File.name}"
}
into calamusV2File.parentFile
}
}
}
task downloadNests() {
outputs.file(nestsFile)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
try {
download {
src new URL("https://github.com/OrnitheMC/nests/raw/main/nests/${version_id}.nest")
dest nestsFile
overwrite true
}
} catch (Exception ignored) {
// not all versions have/need nests
}
}
}
task mergeJars(dependsOn: downloadMcJars) {
group = setupGroup
inputs.files downloadMcJars.outputs.files.files
outputs.file(mergedJar)
outputs.upToDateWhen {
return false
}
doLast {
if (environment.isMerged() && !mergedJar.exists()) {
logger.lifecycle(":merging jars")
def jarMerger = new JarMerger(clientJar, serverJar, mergedJar)
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 {
if (it.downloads == null) {
return;
}
def artifact = it.downloads.artifact
if (artifact == null) return
def downloadUrl = artifact.url
download {
src downloadUrl
dest new File(libraries, downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1))
overwrite false
}
project.dependencies.add("decompileClasspath", it.name)
}
}
}
task invertCalamus(dependsOn: downloadCalamus, type: FileOutput) {
group = buildMappingGroup
def v1Input = downloadCalamus.dest
output = new File(mappingsCacheDir, "${version_id}-calamus-inverted.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":building inverted calamus")
String[] v1Args = [
v1Input.getAbsolutePath(),
output.getAbsolutePath(),
namespace, "official"
]
new CommandReorderTiny().run(v1Args)
}
}
task invertCalamusV2(dependsOn: downloadCalamusV2, type: FileOutput) {
group = buildMappingGroup
def v2Input = new File(mappingsCacheDir, "${version_id}-calamus-v2.tiny")
output = new File(mappingsCacheDir, "${version_id}-calamus-inverted-v2.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":building inverted calamus v2")
String[] v2Args = [
v2Input.getAbsolutePath(),
output.getAbsolutePath(),
namespace, "official"
]
new CommandReorderTinyV2().run(v2Args)
}
}
task patchCalamus(dependsOn: [mergeJars, downloadCalamus]) {
group = buildMappingGroup
def calamusTinyInput = downloadCalamus.dest
def outputFile = new File(mappingsCacheDir, "${version_id}-calamus-full.tiny")
outputs.file(outputFile)
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":patching calamus")
String[] args = [
mainJar.getAbsolutePath(),
calamusTinyInput.getAbsolutePath(),
outputFile.getAbsolutePath(),
"--writeAll"
]
new CommandRewriteCalamus().run(args)
}
}
task mapCalamusJar(dependsOn: [downloadMcLibs, downloadCalamus, mergeJars]) {
group = mapJarGroup
inputs.files downloadMcLibs.outputs.files.files
outputs.file(calamusJar)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":mapping minecraft to calamus")
mapJar(calamusJar, mainJar, downloadCalamus.dest, libraries, "official", namespace)
}
}
task patchNests(dependsOn: [downloadNests, downloadCalamus]) {
outputs.file(calamusNestsFile)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
if (nestsFile.exists()) {
logger.lifecycle(":mapping nests to calamus")
MappingUtils.mapNests(nestsFile.toPath(), calamusNestsFile.toPath(), Format.TINY_V1, calamusV1File.toPath())
}
}
}
task nestJar(dependsOn: [mapCalamusJar, patchNests]) {
group = setupGroup
outputs.file(nestedJar)
outputs.upToDateWhen {
return false
}
doLast {
logger.lifecycle(":nesting jar")
if (calamusNestsFile.exists()) {
Nester.nestJar(new Nester.Options().silent(true), Paths.get(calamusJar.getAbsolutePath()), Paths.get(nestedJar.getAbsolutePath()), Paths.get(calamusNestsFile.getAbsolutePath()))
}
}
}
task separateMappings(dependsOn: patchNests) {
group = featherGroup
inputs.dir mappingsDir
outputs.dirs(workingMappings)
//Force the task to always run
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":separating mappings for ${version_id}")
VersionGraph graph = VersionGraph.of(Format.TINY_V2, mappingsDir.toPath())
Mappings mappings = MappingUtils.separateMappings(graph, version_id);
if (calamusNestsFile.exists()) {
Nests nests = Nests.empty()
NesterIo.read(nests, calamusNestsFile.toPath())
mappings = MappingUtils.applyNests(mappings, nests)
}
mappings.setValidator(REMOVE_DUMMY)
Format.ENIGMA_DIR.writeMappings(workingMappings.toPath(), mappings)
}
}
static def separateMappings(File mappingsDir, File workingMappings, String version_id, File calamusNestsFile, MappingValidator validator) {
VersionGraph graph = VersionGraph.of(Format.TINY_V2, mappingsDir.toPath())
Mappings mappings = MappingUtils.separateMappings(graph, version_id);
if (calamusNestsFile.exists()) {
Nests nests = Nests.empty()
NesterIo.read(nests, calamusNestsFile.toPath())
mappings = MappingUtils.applyNests(mappings, nests)
}
mappings.setValidator(validator)
Format.ENIGMA_DIR.writeMappings(workingMappings.toPath(), mappings)
}
static def insertMappings(version_id, mappingsDir, workingMappingsPath, nestsPath, dir, validator) {
VersionGraph graph = VersionGraph.of(Format.TINY_V2, mappingsDir);
Mappings separatedMappings = MappingUtils.separateMappings(graph, version_id);
Mappings workingMappings = Format.ENIGMA_DIR.readMappings(workingMappingsPath);
// enigma format does not have namespace info...
workingMappings.setSrcNamespace(separatedMappings.getSrcNamespace())
workingMappings.setDstNamespace(separatedMappings.getDstNamespace())
if (nestsPath.toFile().exists()) {
Nests nests = Nests.empty()
NesterIo.read(nests, nestsPath)
workingMappings = MappingUtils.undoNests(workingMappings, nests)
}
MappingsDiff changes = MappingUtils.diffMappings(separatedMappings, workingMappings);
changes.setValidator(validator);
PropagationOptions options = new PropagationOptions.Builder().setPropagationDirection(dir).lenient().build();
MappingUtils.insertMappings(options, graph, changes, version_id);
net.ornithemc.mappingutils.FileUtils.delete(workingMappingsPath.toFile())
}
task insertMappings(dependsOn: patchNests) {
group = featherGroup
doLast {
logger.lifecycle(":saving mappings for ${version_id}")
insertMappings(version_id, mappingsDir.toPath(), workingMappings.toPath(), calamusNestsFile.toPath(), PropagationDirection.NONE, INSERT_DUMMY)
separateMappings(mappingsDir, workingMappings, version_id, calamusNestsFile, REMOVE_DUMMY)
}
}
task propagateMappingsDown(dependsOn: patchNests) {
group = featherGroup
doLast {
logger.lifecycle(":saving mappings for ${version_id}")
insertMappings(version_id, mappingsDir.toPath(), workingMappings.toPath(), calamusNestsFile.toPath(), PropagationDirection.DOWN, INSERT_DUMMY)
separateMappings(mappingsDir, workingMappings, version_id, calamusNestsFile, REMOVE_DUMMY)
}
}
task propagateMappingsUp(dependsOn: patchNests) {
group = featherGroup
doLast {
logger.lifecycle(":saving mappings for ${version_id}")
insertMappings(version_id, mappingsDir.toPath(), workingMappings.toPath(), calamusNestsFile.toPath(), PropagationDirection.UP, INSERT_DUMMY)
separateMappings(mappingsDir, workingMappings, version_id, calamusNestsFile, REMOVE_DUMMY)
}
}
task propagateMappings(dependsOn: patchNests) {
group = featherGroup
doLast {
logger.lifecycle(":saving mappings for ${version_id}")
insertMappings(version_id, mappingsDir.toPath(), workingMappings.toPath(), calamusNestsFile.toPath(), PropagationDirection.BOTH, INSERT_DUMMY)
separateMappings(mappingsDir, workingMappings, version_id, calamusNestsFile, REMOVE_DUMMY)
}
}
task feather(dependsOn: [nestJar, separateMappings]) {
group = featherGroup
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: (calamusNestsFile.exists() ? nestedJar : calamusJar).getAbsolutePath())
arg(value: '-mappings')
arg(value: workingMappings.getAbsolutePath())
arg(value: '-profile')
arg(value: 'enigma_profile.json')
}
}
}
task separateMappingsForBuild(type: FileOutput) {
inputs.dir mappingsDir
output = new File(tempDir, "separated-mappings-v2.tiny")
outputs.file(output)
outputs.upToDateWhen { false }
doLast {
VersionGraph graph = VersionGraph.of(Format.TINY_V2, mappingsDir.toPath())
Mappings mappings = MappingUtils.separateMappings(graph, version_id);
mappings.setValidator(REMOVE_DUMMY)
Format.TINY_V2.writeMappings(output.toPath(), mappings)
}
}
task checkMappings(dependsOn: [mapCalamusJar, separateMappingsForBuild]) {
group = buildMappingGroup
inputs.file separateMappingsForBuild.output
doLast {
logger.lifecycle(":checking mappings")
String[] args = [
mainJar.getAbsolutePath(),
separateMappingsForBuild.output.getAbsolutePath()
]
try {
new CheckMappingsCommand().run(args)
} catch (IllegalStateException ignored) {
// just print, don't fail the task
}
}
}
task buildFeatherTiny(dependsOn: [mapCalamusJar, separateMappingsForBuild], type: WithV2FileOutput) {
group = buildMappingGroup
inputs.file separateMappingsForBuild.output
if (!libs.exists()) {
libs.mkdirs()
}
v1Output = new File(tempDir, "feather-mappings.tiny")
v2Output = new File(tempDir, "feather-mappings-v2.tiny")
outputs.upToDateWhen { false }
doLast {
logger.lifecycle(":generating tiny mappings")
new MapSpecializedMethodsCommand().run(
calamusJar.getAbsolutePath(),
"tinyv2",
separateMappingsForBuild.output.getAbsolutePath(),
"tinyv2:${namespace}:named",
v2Output.getAbsolutePath()
)
new ConvertMappingsCommand().run(
"tinyv2",
v2Output.getAbsolutePath(),
"tiny:${namespace}:named",
v1Output.getAbsolutePath())
}
}
task mergeTiny(dependsOn: ["buildFeatherTiny", "invertCalamus"], type: FileOutput) {
group = buildMappingGroup
def featherTinyInput = buildFeatherTiny.v1Output
def calamusTinyInput = invertCalamus.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 feather and calamus")
String[] args = [
calamusTinyInput.getAbsolutePath(),
featherTinyInput.getAbsolutePath(),
unorderedResultMappings.getAbsolutePath(),
namespace,
"official"
]
new CommandMergeTiny().run(args)
logger.lifecycle(":reordering merged calamus")
String[] args2 = [
unorderedResultMappings.getAbsolutePath(),
output.getAbsolutePath(),
"official", namespace, "named"
]
new CommandReorderTiny().run(args2)
}
}
task tinyJar(type: Jar, dependsOn: mergeTiny) {
group = buildMappingGroup
outputs.upToDateWhen { false }
archiveFileName = "feather-${featherVersion}.jar"
destinationDirectory.set(file("build/libs"))
archiveClassifier.set("")
from(mergeTiny.output) {
rename { "mappings/mappings.tiny" }
}
}
task compressTiny(dependsOn: [tinyJar, mergeTiny], type: FileOutput) {
group = buildMappingGroup
def outputFile = new File(libs, "feather-tiny-${featherVersion}.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