-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
922 lines (830 loc) · 37.6 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
buildscript {
repositories {
mavenLocal()
maven { url = "http://cherrymc.net:15000/repository/maven-public/" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:3.+'
classpath 'org.ow2.asm:asm:7.1'
classpath 'org.ow2.asm:asm-tree:7.1'
classpath 'com.github.jponge:lzma-java:1.3' //Needed to compress deobf data
}
}
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
import java.nio.file.Files
import java.text.SimpleDateFormat
import java.util.Date
import java.util.LinkedHashMap
import java.util.TreeSet
import java.util.stream.Collectors
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream
import java.security.MessageDigest
import java.net.URL
import net.minecraftforge.gradle.common.task.ArchiveChecksum
import net.minecraftforge.gradle.common.task.DownloadMavenArtifact
import net.minecraftforge.gradle.common.task.ExtractInheritance
import net.minecraftforge.gradle.common.task.SignJar
import net.minecraftforge.gradle.common.util.HashStore
import net.minecraftforge.gradle.mcp.function.MCPFunction
import net.minecraftforge.gradle.mcp.util.MCPEnvironment
import net.minecraftforge.gradle.patcher.task.ApplyBinPatches
import net.minecraftforge.gradle.patcher.task.GenerateBinPatches
import net.minecraftforge.gradle.patcher.task.TaskReobfuscateJar
import net.minecraftforge.gradle.userdev.tasks.RenameJar
import org.apache.tools.ant.filters.ReplaceTokens
import de.undercouch.gradle.tasks.download.Download
import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.objectweb.asm.ClassReader
plugins {
id 'net.minecrell.licenser' version '0.4'
id 'org.ajoberstar.grgit' version '3.1.1'
id 'de.undercouch.download' version '3.3.0'
id 'com.github.ben-manes.versions' version '0.22.0'
}
apply plugin: 'idea'
def plugin_patcher = 'net.minecraftforge.gradle.patcher'
def ct = "cherry tool"
ext {
JAR_SIGNER = null
if (project.hasProperty('keystore')) {
JAR_SIGNER = [
storepass: project.properties.keystoreStorePass,
keypass: project.properties.keystoreKeyPass,
keystore: project.properties.keystore
]
}
MAPPING_CHANNEL = 'snapshot'
MAPPING_VERSION = '20171003-1.12'
MC_VERSION = '1.12.2'
MCP_VERSION = '20200226.224830'
POST_PROCESSOR = [
tool: 'net.minecraftforge:mcpcleanup:2.3.2:fatjar',
repo: 'https://files.minecraftforge.net/maven/',
args: ['--input', '{input}', '--output', '{output}']
]
}
project(':Base') {
apply plugin: 'net.minecraftforge.gradle.mcp'
if(!project.projectDir.exists())project.projectDir.mkdirs()
mcp {
config = MC_VERSION + '-' + MCP_VERSION
pipeline = 'joined'
}
}
project(':Clean'){
evaluationDependsOn(':Base')
apply plugin: 'idea'
apply plugin: plugin_patcher
compileJava.sourceCompatibility = compileJava.targetCompatibility = sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
repositories {
mavenCentral()
}
dependencies {
implementation 'net.minecraftforge:mergetool:0.2.3.3:forge'
implementation 'javax.vecmath:vecmath:1.5.2'
}
patcher {
parent = project(':Base')
mcVersion = MC_VERSION
patchedSrc = file('src/main/java')
mappings channel: MAPPING_CHANNEL, version: MAPPING_VERSION
processor = POST_PROCESSOR
runs {
clean_client {
taskName 'clean_client_test'
main 'net.minecraft.client.main.Main'
workingDirectory project.file('run')
args '--gameDir', '.'
args '--version', MC_VERSION
args '--assetsDir', downloadAssets.output
args '--assetIndex', '{asset_index}'
args '--accessToken', '0'
// jvmArgs '-Djava.library.path='+project.file('build/natives')//This is also available
jvmArgs '-Djava.library.path='+extractNatives.getOutput().getAbsolutePath()
}
clean_server {
taskName 'clean_server_test'
main 'net.minecraft.server.MinecraftServer'
workingDirectory project.file('run')
}
}
}
}
project(':Cherry') {
evaluationDependsOn(':Clean')
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: plugin_patcher
apply plugin: 'net.minecrell.licenser'
apply plugin: 'de.undercouch.download'
compileJava.sourceCompatibility = compileJava.targetCompatibility = sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
group = 'net.cherrymc'
sourceSets {
main {
java {
srcDirs = ["$rootDir/src/main/java"]
}
resources {
srcDirs = ["$rootDir/src/main/resources"]
}
}
test {
compileClasspath += sourceSets.main.runtimeClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath
java {
srcDirs = ["$rootDir/src/test/java"]
}
resources {
srcDirs = ["$rootDir/src/test/resources"]
}
}
}
//Eclipse adds the sourcesets twice, once where we tell it to, once in the projects folder. No idea why. So delete them
// eclipse.classpath.file.whenMerged { cls -> cls.entries.removeIf { e -> e instanceof SourceFolder && e.path.startsWith('src/') && !e.path.startsWith('src/main/') } }
repositories {
mavenLocal()
mavenCentral()
}
ext {
LEGACY_MAJOR = 14 //Legacy versions have a API change prefix
LEGACY_BUILD = 2856 //Base build number to not conflict with existing build numbers
BUILD_NUMBER = 0 // LEGACY_BUILD + commit offset, used to mimic unique build from old versions
SPEC_VERSION = '23.5' // This is overwritten by git tag, but here so dev time doesnt explode
MCP_ARTIFACT = project(':Base').mcp.config
SPECIAL_SOURCE = 'net.md-5:SpecialSource:1.8.5'
VERSION_JSON = project(':Base').file('build/mcp/downloadJson/version.json')
BINPATCH_TOOL = 'net.minecraftforge:binarypatcher:1.1.1:fatjar'
FORVGE_VERSION = '14.23.5.2855'
}
def time = {
return (new SimpleDateFormat("YYYYMMddHHmm")).format((Calendar.getInstance()).getTime())
}
def getVersion = {
// format: MCversion-CherryVersion-time
// mc version cherry version time
return "1.12.2-" + rootProject.cherry_version + "-" + time()
}
version = getVersion()
patcher {
exc = file("$rootDir/src/main/resources/forge.exc")
parent = project(':Clean')
patches = file("$rootDir/patches/minecraft")
patchedSrc = file('src/main/java')
srgPatches = true
notchObf = true
accessTransformer = file("$rootDir/src/main/resources/forge_at.cfg")
//sideAnnotationStripper = file("$rootDir/src/main/resources/forge.sas")
processor = POST_PROCESSOR
runs {
cherry_dev_client {
//group ct
taskName 'cherry_dev_client'
main 'net.cherrymc.dev.MainClient'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', downloadAssets.output
environment 'nativesDirectory', "${project.file('build/natives')}"
environment 'MC_VERSION', '${MC_VERSION}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', project.file("build/createSrgToMcp/output.srg")
environment 'FORGE_GROUP', "${project.group}"
environment 'FORGE_VERSION', FORVGE_VERSION
// Recommended logging data for a userdev environment
//property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
// Recommended logging level for the console
property 'cherry.logging.console.level', 'debug'
//args
args '--username', 'Acyco'
}
cherry_dev_server {
taskName 'cherry_dev_server'
main 'net.cherrymc.dev.MainServer'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLServerTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'MC_VERSION', '${MC_VERSION}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', project.file("build/createSrgToMcp/output.srg")
environment 'FORGE_GROUP', "${project.group}"
environment 'FORGE_VERSION', FORVGE_VERSION
}
}
}
ext {
MANIFESTS = [
'/': [
'Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'GitCommit': grgit.head().abbreviatedId,
'Git-Branch': grgit.branch.current().getName()
] as LinkedHashMap,
'net/cherrymc': [
'Specification-Title': 'Cherry',
'Specification-Vendor': 'Cherry Development LLC',
'Specification-Version': SPEC_VERSION,
'Implementation-Title': project.group,
'Implementation-Version': project.version.substring(MC_VERSION.length() + 1),
'Implementation-Vendor': 'Cherry Development LLC'
] as LinkedHashMap
]
}
applyPatches {
canonicalizeAccess true
canonicalizeWhitespace true
maxFuzz 3
originalPrefix = '../src-base/minecraft/'
modifiedPrefix = '../src-work/minecraft/'
}
genPatches {
group ct
originalPrefix = '../src-base/minecraft/'
modifiedPrefix = '../src-work/minecraft/'
}
configurations {
installer {
transitive = false //Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
}
api.extendsFrom(installer)
fmllauncherImplementation.extendsFrom(installer)
}
dependencies {
installer 'org.ow2.asm:asm-debug-all:5.2'
installer 'net.minecraft:launchwrapper:1.12'
installer 'org.jline:jline:3.5.1'
installer 'com.typesafe.akka:akka-actor_2.11:2.3.3'
installer 'com.typesafe:config:1.2.1'
installer 'org.scala-lang:scala-actors-migration_2.11:1.1.0'
installer 'org.scala-lang:scala-compiler:2.11.1'
installer 'org.scala-lang.plugins:scala-continuations-library_2.11:1.0.2_mc' //We change the version so old installs don't break, as our clone of the jar is different the maven central
installer 'org.scala-lang.plugins:scala-continuations-plugin_2.11.1:1.0.2_mc' // --^
installer 'org.scala-lang:scala-library:2.11.1'
installer 'org.scala-lang:scala-parser-combinators_2.11:1.0.1'
installer 'org.scala-lang:scala-reflect:2.11.1'
installer 'org.scala-lang:scala-swing_2.11:1.0.1'
installer 'org.scala-lang:scala-xml_2.11:1.0.2'
installer 'lzma:lzma:0.0.1'
installer 'com.github.jponge:lzma-java:1.3'
installer 'javax.vecmath:vecmath:1.5.2'
installer 'net.sf.trove4j:trove4j:3.0.3'
installer 'org.apache.maven:maven-artifact:3.5.3'
installer 'net.sf.jopt-simple:jopt-simple:5.0.3'
// installer 'net.minecraftforge:legacydev:0.2.3.+:fatjar'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.+'
testImplementation 'org.opentest4j:opentest4j:1.0.0' // needed for junit 5
testImplementation 'org.hamcrest:hamcrest-all:1.3' // needs advanced matching for list order
}
def extraTxts = [
rootProject.file('CREDITS.txt'),
rootProject.file('LICENSE.txt'),
rootProject.file('LICENSE-Paulscode IBXM Library.txt'),
rootProject.file('LICENSE-Paulscode SoundSystem CodecIBXM.txt')
]
def changelog = rootProject.file('build/changelog.txt')
if (changelog.exists())
extraTxts += changelog
// We apply the bin patches we just created to make a jar that is JUST our changes
genClientBinPatches.tool = BINPATCH_TOOL
task applyClientBinPatches(type: ApplyBinPatches, dependsOn: genClientBinPatches) {
clean = { genClientBinPatches.cleanJar }
input = genClientBinPatches.output
tool = BINPATCH_TOOL
}
genServerBinPatches.tool = BINPATCH_TOOL
genJoinedBinPatches.tool = BINPATCH_TOOL
task genRuntimeBinPatches(type: GenerateBinPatches, dependsOn: [genClientBinPatches, genServerBinPatches]) {
tool = BINPATCH_TOOL
}
afterEvaluate { p ->
genRuntimeBinPatches {
cleanJar = genClientBinPatches.cleanJar
dirtyJar = genClientBinPatches.dirtyJar
srg = genClientBinPatches.srg
patchSets = genClientBinPatches.patchSets
args = [
'--output', '{output}',
'--patches', '{patches}',
'--srg', '{srg}',
'--legacy',
'--clean', '{clean}',
'--dirty', '{dirty}',
'--prefix', 'binpatch/client',
'--clean', '{server}',
'--dirty', '{dirty}',
'--prefix', 'binpatch/server'
]
addExtra('server', genServerBinPatches.cleanJar)
}
}
//Create SrgToMcp as srg format file instead of tsrg format file
task createSrgToMcp(type: net.minecraftforge.gradle.mcp.task.GenerateSRG, dependsOn: ':Clean:extractSrg'){
group ct
reverse false
mappings MAPPING_CHANNEL+"_"+MAPPING_VERSION
srg project(":Clean").file("build/extractSrg/output.srg")
format (net.minecraftforge.gradle.common.util.MappingFile.Format.SRG)
//inputs.file project(':Base').mcp.config
output file('build/createSrgToMcp/output.srg')
}
compileJava <<{
//由于在开发环境,并没有打包成jar, 所以MC找assets默认是去clesses那个目录去找(个人认为的)
copy {
// group ct
//println project.file("build/classes/java/main/assets").mkdirs()
// from rootProject.file("src/main/resources/assets")
from project.file("build/resources/main/assets")
into project.file("build/classes/java/main/assets")
}
}
task downloadLibraries(dependsOn: ':Base:setupMCP') {
inputs.file VERSION_JSON
doLast {
def json = new JsonSlurper().parseText(VERSION_JSON.text)
json.libraries.each {lib ->
def artifacts = [lib.downloads.artifact] + lib.downloads.get('classifiers', [:]).values()
artifacts.each{ art ->
def target = file('build/libraries/' + art.path)
if (!target.exists()) {
download {
src art.url
dest target
}
}
}
}
}
}
task extractInheritance(type: ExtractInheritance, dependsOn: [genJoinedBinPatches, downloadLibraries]) {
input { genJoinedBinPatches.cleanJar }
doFirst {
def json = new JsonSlurper().parseText(VERSION_JSON.text)
json.libraries.each {lib ->
def artifacts = [lib.downloads.artifact] + lib.downloads.get('classifiers', [:]).values()
artifacts.each{ art ->
def target = file('build/libraries/' + art.path)
if (target.exists())
addLibrary(target)
}
}
}
}
task checkATs(dependsOn: genJoinedBinPatches) {
inputs.file { genJoinedBinPatches.cleanJar }
inputs.files patcher.accessTransformers
doLast {
def vanilla = [:]
def zip = new java.util.zip.ZipFile(genJoinedBinPatches.cleanJar)
zip.entries().findAll { !it.directory && it.name.endsWith('.class') }.each { entry ->
new ClassReader(zip.getInputStream(entry)).accept(new org.objectweb.asm.ClassVisitor(org.objectweb.asm.Opcodes.ASM7) {
String name
void visit(int version, int access, String name, String sig, String superName, String[] interfaces) {
this.name = name
vanilla[name] = access
}
org.objectweb.asm.FieldVisitor visitField(int access, String name, String desc, String sig, Object value) {
vanilla[this.name + ' ' + name] = access
return null
}
org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String desc, String sig, String[] excs) {
vanilla[this.name + ' ' + name + desc] = access
return null
}
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
}
patcher.accessTransformers.each { f ->
TreeMap lines = [:]
f.eachLine { line ->
def idx = line.indexOf('#')
if (idx == 0 || line.isEmpty()) return
def comment = idx == -1 ? null : line.substring(idx)
if (idx != -1) line = line.substring(0, idx - 1)
def (modifier, cls, desc) = (line.trim() + ' ').split(' ', -1)
def key = cls + (desc.isEmpty() ? '' : ' ' + desc)
def access = vanilla[key.replace('.', '/')]
if (access == null) {
if ((desc.equals('*') || desc.equals('*()')) && vanilla[cls.replace('.', '/')] != null)
println('Warning: ' + line)
else {
println('Invalid: ' + line)
return
}
}
//TODO: Check access actually changes, and expand inheretence?
lines[key] = [modifier: modifier, comment: comment]
}
f.text = lines.collect{ it.value.modifier + ' ' + it.key + (it.value.comment == null ? '' : ' ' + it.value.comment) }.join('\n')
}
}
}
task checkSAS(dependsOn: extractInheritance) {
inputs.file { extractInheritance.output }
inputs.files patcher.sideAnnotationStrippers
doLast {
def json = new JsonSlurper().parseText(extractInheritance.output.text)
patcher.sideAnnotationStrippers.each { f ->
def lines = []
f.eachLine { line ->
if (line[0] == '\t') return //Skip any tabed lines, those are ones we add
def idx = line.indexOf('#')
if (idx == 0 || line.isEmpty()) {
lines.add(line)
return
}
def comment = idx == -1 ? null : line.substring(idx)
if (idx != -1) line = line.substring(0, idx - 1)
def (cls, desc) = (line.trim() + ' ').split(' ', -1)
cls = cls.replaceAll('\\.', '/')
desc = desc.replace('(', ' (')
if (desc.isEmpty() || json[cls] == null || json[cls]['methods'] == null || json[cls]['methods'][desc] == null) {
println('Invalid: ' + line)
return
}
def mtd = json[cls]['methods'][desc]
lines.add(cls + ' ' + desc.replace(' ', '') + (comment == null ? '' : ' ' + comment))
def children = json.values().findAll{ it.methods != null && it.methods[desc] != null && it.methods[desc].override == cls}
.collect { it.name + ' ' + desc.replace(' ', '') } as TreeSet
children.each { lines.add('\t' + it) }
}
f.text = lines.join('\n')
}
}
}
task launcherJson(dependsOn: ['signUniversalJar']) {
inputs.file { universalJar.archivePath }
ext {
output = file('build/version.json')
vanilla = project(':Base').file('build/mcp/downloadJson/version.json')
timestamp = dateToIso8601(new Date())
comment = [
"Please do not automate the download and installation of Forge.",
"Our efforts are supported by ads from the download page.",
"If you MUST automate this, please consider supporting the project through https://www.patreon.com/LexManos/"
]
def idx = project.version.indexOf('-')
id = project.version.substring(0, idx) + "-${project.name}" + project.version.substring(idx)
}
inputs.file vanilla
outputs.file output
doLast {
def json_vanilla = new JsonSlurper().parseText(vanilla.text)
def json = [
_comment_: comment,
id: id,
time: timestamp,
releaseTime: timestamp,
type: 'release',
mainClass: 'net.minecraft.launchwrapper.Launch',
inheritsFrom: MC_VERSION,
logging: {},
minecraftArguments: [
'--username', '${auth_player_name}',
'--version', '${version_name}',
'--gameDir', '${game_directory}',
'--assetsDir', '${assets_root}',
'--assetIndex', '${assets_index_name}',
'--uuid', '${auth_uuid}',
'--accessToken', '${auth_access_token}',
'--userType', '${user_type}',
'--tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker',
'--versionType', 'Forge'
].join(' '),
libraries: [
[
//Package our universal jar as the 'main' jar Mojang's launcher loads. It will in turn load Forge's regular jars itself.
name: "${project.group}:${project.name}:${project.version}",
downloads: [
artifact: [
path: "${project.group.replace('.', '/')}/${project.name}/${project.version}/${project.name}-${project.version}.jar",
url: "", //Do not include the URL so that the installer/launcher won't grab it. This is also why we don't have the universal classifier
sha1: sha1(universalJar.archivePath),
size: universalJar.archivePath.length()
]
]
]
]
]
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
json.libraries.add(lib)
}
output.text = new JsonBuilder(json).toPrettyString()
}
}
task installerJson(dependsOn: [launcherJson, genClientBinPatches/*, createClientSRG, createServerSRG*/]) {
ext {
output = file('build/install_profile.json')
INSTALLER_TOOLS = 'net.minecraftforge:installertools:1.1.4'
}
inputs.file universalJar.archivePath
inputs.file genClientBinPatches.toolJar
inputs.file launcherJson.output
outputs.file output
doLast {
def libs = [
"${project.group}:${project.name}:${project.version}": [
name: "${project.group}:${project.name}:${project.version}",
downloads: [
artifact: [
path: "${project.group.replace('.', '/')}/${project.name}/${project.version}/${project.name}-${project.version}.jar",
url: "", //Do not include the URL so that the installer/launcher won't grab it. This is also why we don't have the universal classifier
sha1: sha1(universalJar.archivePath),
size: universalJar.archivePath.length()
]
]
]
]
def json = [
_comment_: launcherJson.comment,
spec: 0,
profile: project.name,
version: launcherJson.id,
icon: "data:image/png;base64," + new String(Base64.getEncoder().encode(Files.readAllBytes(rootProject.file("cherry.ico").toPath()))),
json: '/version.json',
path: "${project.group}:${project.name}:${project.version}",
logo: '/big_logo.png',
minecraft: MC_VERSION,
welcome: "Welcome to the simple ${project.name.capitalize()} installer.",
data: [
] as Map,
processors: [
]
]
getClasspath(project, libs, MCP_ARTIFACT.descriptor) //Tell it to download mcp_config
json.libraries = libs.values().sort{a,b -> a.name.compareTo(b.name)}
output.text = new JsonBuilder(json).toPrettyString()
}
}
task extractObf2Srg(type:net.minecraftforge.gradle.common.task.ExtractMCPData, dependsOn: [':Base:downloadConfig']) {
config = project(':Base').downloadConfig.output
}
task deobfDataLzma(dependsOn: [extractObf2Srg]) {
ext {
output_srg = file('build/deobfDataLzma/data.srg')
output = file('build/deobfDataLzma/data.lzma')
}
inputs.file extractObf2Srg.output
outputs.file output
doLast {
net.minecraftforge.gradle.common.util.MappingFile.load(extractObf2Srg.output)
.write(net.minecraftforge.gradle.common.util.MappingFile.Format.SRG, output_srg)
output_srg.withInputStream { ins ->
output.withOutputStream { outs ->
def lz = new lzma.streams.LzmaOutputStream.Builder(outs).useEndMarkerMode(true).build()
def i = -1
def buf = new byte[0x100]
while ((i = ins.read(buf)) != -1)
lz.write(buf, 0, i)
lz.close()
}
}
}
}
universalJar {
from(extraTxts)
dependsOn(deobfDataLzma)
from(deobfDataLzma.output){
rename{"deobfuscation_data-${MC_VERSION}.lzma"}
}
dependsOn(genRuntimeBinPatches)
from(genRuntimeBinPatches.output) {
rename{'binpatches.pack.lzma'}
}
doFirst {
def classpath = new StringBuilder()
def artifacts = getArtifacts(project, project.configurations.installer, false)
artifacts.each { key, lib ->
classpath.append("libraries/${lib.downloads.artifact.path} ")
}
classpath += "minecraft_server.${MC_VERSION}.jar"
MANIFESTS.each{ pkg, values ->
if (pkg == '/') {
manifest.attributes(values += [
'Main-Class': 'net.minecraftforge.fml.relauncher.ServerLaunchWrapper',
'Class-Path': classpath.toString(),
'Tweak-Class': 'net.minecraftforge.fml.common.launcher.FMLTweaker'
])
} else {
manifest.attributes(values, pkg)
}
}
}
}
task downloadInstaller(type: DownloadMavenArtifact) {
artifact = 'net.minecraftforge:installer:2.0.+:shrunk'
changing = true
}
task installerJar(type: Zip, dependsOn: [downloadInstaller, installerJson, launcherJson, genClientBinPatches, genServerBinPatches, 'signUniversalJar']) {
group ct
rootProject.file("/src/main/resources/version").setText(version)
classifier = 'installer'
extension = 'jar' //Needs to be Zip task to not override Manifest, so set extension
destinationDir = file('build/libs')
from(extraTxts)
from(rootProject.file('/src/main/resources/cherry_logo.png')) {
rename{'big_logo.png'}
}
from(rootProject.file('/src/main/resources/url.png'))
from(universalJar) {
into("/maven/${project.group.replace('.', '/')}/${project.name}/${project.version}/")
rename{"${project.name}-${project.version}.jar"}
}
from(installerJson.output)
from(launcherJson.output)
from(zipTree(downloadInstaller.output)) {
duplicatesStrategy = 'exclude'
}
}
[universalJar, installerJar].each { t ->
task "sign${t.name.capitalize()}"(type: SignJar, dependsOn: t) {
onlyIf {
JAR_SIGNER != null && t.state.failure == null
}
def jarsigner = JAR_SIGNER == null ? [:] : JAR_SIGNER
alias = 'forge'
storePass = jarsigner.storepass
keyPass = jarsigner.keypass
keyStore = jarsigner.keystore
inputFile = t.archivePath
outputFile = t.archivePath
doFirst {
project.logger.lifecycle('Signing: ' + inputFile)
}
}
t.finalizedBy(tasks.getByName("sign${t.name.capitalize()}"))
}
userdevConfig {
def artifacts = getArtifacts(project, project.configurations.installer, true)
artifacts.each { key, lib ->
addLibrary(lib.name)
}
addLibrary('net.minecraftforge:legacydev:0.2.3.+:fatjar')
addUniversalFilter('^(?!binpatches\\.pack\\.lzma$).*$')
runs {
client {
main 'net.cherrymc.dev.MainClient'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', '{assets_root}'
environment 'nativesDirectory', '{natives}'
environment 'MC_VERSION', '${MC_VERSION}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', '{mcp_to_srg}'
environment 'FORGE_GROUP', "${project.group}"
environment 'FORGE_VERSION', "${project.version.substring(MC_VERSION.length() + 1)}"
}
server {
main 'net.cherrymc.dev.MainServer'
environment 'tweakClass', 'net.minecraftforge.fml.common.launcher.FMLServerTweaker'
environment 'mainClass', 'net.minecraft.launchwrapper.Launch'
environment 'MC_VERSION', '${MC_VERSION}'
environment 'MCP_MAPPINGS', '{mcp_mappings}'
environment 'MCP_TO_SRG', '{mcp_to_srg}'
environment 'FORGE_GROUP', "${project.group}"
environment 'FORGE_VERSION', "${project.version.substring(MC_VERSION.length() + 1)}"
}
}
}
license {
header = file("$rootDir/LICENSE-header.txt")
include 'net/minecraftforge/'
/*
exclude 'net/minecraftforge/server/terminalconsole/'
exclude 'net/minecraftforge/api/' // exclude API here because it's validated in the SPI build
exclude 'net/minecraftforge/fml/common/versioning/ComparableVersion.java'
exclude 'net/minecraftforge/fml/common/versioning/InvalidVersionSpecificationException.java'
exclude 'net/minecraftforge/fml/common/versioning/Restriction.java'
exclude 'net/minecraftforge/fml/common/versioning/VersionRange.java'
*/
tasks {
main {
files = files("$rootDir/src/main/java")
}
test {
files = files("$rootDir/src/test/java")
}
}
}
/*
extractRangeMap {
addDependencies jar.archivePath
addSources sourceSets.userdev.java.srcDirs
}
applyRangeMap {
setSources sourceSets.userdev.java.srcDirs
}
*/
// tasks.eclipse.dependsOn('genEclipseRuns')
if (project.hasProperty('UPDATE_MAPPINGS')) {
extractRangeMap {
sources sourceSets.test.java.srcDirs
}
applyRangeMap {
sources sourceSets.test.java.srcDirs
}
sourceSets.test.java.srcDirs.each { extractMappedNew.addTarget it }
}
}
def dateToIso8601(date) {
def format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
def result = format.format(date)
return result[0..21] + ':' + result[22..-1]
}
def sha1(file) {
MessageDigest md = MessageDigest.getInstance('SHA-1')
file.eachByte 4096, {bytes, size ->
md.update(bytes, 0, size)
}
return md.digest().collect {String.format "%02x", it}.join()
}
def artifactTree(project, artifact) {
if (!project.ext.has('tree_resolver'))
project.ext.tree_resolver = 1
def cfg = project.configurations.create('tree_resolver_' + project.ext.tree_resolver++)
def dep = project.dependencies.create(artifact)
cfg.dependencies.add(dep)
def files = cfg.resolve()
return getArtifacts(project, cfg, true)
}
def getArtifacts(project, config, classifiers) {
def ret = [:]
config.resolvedConfiguration.resolvedArtifacts.each {
def art = [
group: it.moduleVersion.id.group,
name: it.moduleVersion.id.name,
version: it.moduleVersion.id.version,
classifier: it.classifier,
extension: it.extension,
file: it.file
]
def key = art.group + ':' + art.name
def folder = "${art.group.replace('.', '/')}/${art.name}/${art.version}/"
def filename = "${art.name}-${art.version}"
if (art.classifier != null)
filename += "-${art.classifier}"
filename += ".${art.extension}"
def path = "${folder}${filename}"
def url = "https://libraries.minecraft.net/${path}"
if (!checkExists(url)) {
url = "https://files.minecraftforge.net/maven/${path}"
}
//TODO remove when Mojang launcher is updated
if (!classifiers && art.classifier != null) { //Mojang launcher doesn't currently support classifiers, so... move it to part of the version, and force the extension to 'jar'
art.version = "${art.version}-${art.classifier}"
art.classifier = null
art.extension = 'jar'
path = "${art.group.replace('.', '/')}/${art.name}/${art.version}/${art.name}-${art.version}.jar"
}
ret[key] = [
name: "${art.group}:${art.name}:${art.version}" + (art.classifier == null ? '' : ":${art.classifier}") + (art.extension == 'jar' ? '' : "@${art.extension}"),
downloads: [
artifact: [
path: path,
url: url,
sha1: sha1(art.file),
size: art.file.length()
]
]
]
}
return ret
}
def checkExists(url) {
def code = new URL(url).openConnection().with {
requestMethod = 'HEAD'
connect()
responseCode
}
return code == 200
}
def getClasspath(project, libs, artifact) {
def ret = []
artifactTree(project, artifact).each { key, lib ->
libs[lib.name] = lib
if (lib.name != artifact)
ret.add(lib.name)
}
return ret
}
task ciWriteBuildNumber << {
def file = file('src/main/java/net/minecraftforge/common/ForgeVersion.java');
def outfile = '';
def ln = '\n'; //Linux line endings because we're on git!
file.eachLine{ String s ->
if (s.matches('^ public static final int buildVersion = [\\d]+;\$'))
s = " public static final int buildVersion = ${project(':Cherry').BUILD_NUMBER};"
if (s.matches('^ public static final String mcVersion = "[^\\"]+";'))
s = " public static final String mcVersion = \"${MC_VERSION}\";"
outfile += (s+ln);
}
file.write(outfile);
}
//evaluationDependsOnChildren()
task setup() {
dependsOn ':Clean:extractMapped'
dependsOn ':Cherry:extractMapped' //These must be strings so that we can do lazy resolution. Else we need evaluationDependsOnChildren above
dependsOn ':Cherry:createSrgToMcp'//Create SrtToMcp as srg format file , not tsrg, Because the development environment needs to use.
}