-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
464 lines (407 loc) · 16.2 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
// ======================
// JAR MOD BUILDSCRIPT
// ======================
// ===== HEADER =====
// Use the ForgeGradle plugin (must go absolutely first! (before imports!) :( )
buildscript
{
ext.prometheus_version = "0.1.0"
repositories
{
mavenCentral()
maven { url 'https://masa.dy.fi/maven/' }
maven { url 'https://files.minecraftforge.net/maven' }
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies
{
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-7764e3e'
classpath 'de.undercouch:gradle-download-task:3.4.3'
classpath 'commons-io:commons-io:2.6'
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.3" // For debug purposes
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'
def patcher_plugin = plugins.apply 'net.minecraftforge.gradle.patcher'
apply plugin: 'de.undercouch.download'
apply plugin: "com.dorongold.task-tree" // For debug purposes
import com.google.common.io.Resources
import de.undercouch.gradle.tasks.download.Download
import net.minecraftforge.gradle.common.Constants
import net.minecraftforge.gradle.patcher.PatcherConstants
import net.minecraftforge.gradle.patcher.TaskReobfuscate
import net.minecraftforge.gradle.patcher.TaskSubprojectCall
import net.minecraftforge.gradle.util.json.version.OS
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import java.util.zip.ZipFile
// ===== PROPERTIES =====
// Set basic project properties
group = name
version = gradle.modVersion
def capitalizedName = '' + Character.toUpperCase(project.name.charAt(0)) + project.name.substring(1)
allprojects {
sourceSets.main.java.srcDirs = ['src']
sourceSets.main.resources.srcDirs = ['resources']
repositories {
mavenCentral()
maven { url 'https://files.minecraftforge.net/maven' }
maven { url 'https://libraries.minecraft.net/' }
}
dependencies
{
implementation files('resources/1.12.2.jar')
}
configurations.compile.extendsFrom configurations.forgeGradleMcDeps
}
sourceSets {
main {
java {
srcDirs = ['src']
mainClassName = 'net.minecraft.server.MinecraftServer'
}
}
}
File runningDir = new File('server/')
runningDir.mkdirs()
tasks.run.workingDir = runningDir
//tasks.run.args = ['nogui'] // add this to remove server gui
// ForgeGradle settings
minecraft
{
version = gradle.mcVersion
mappings = gradle.mappings
workspaceDir = 'projects'
// versionJson is used to download assets because ForgeGradle insists
versionJson = "jsons/${minecraft.version}-dev.json"
ant.replaceregexp(
file: "${project.name}Src/carpet/CarpetSettings.java",
match: 'v2\\d_[0|1]\\d_[0-3]\\d',
replace: 'v' + new Date().format('yy_MM_dd')
)
def common = {
patchPrefixOriginal = '../src-base/minecraft'
patchPrefixChanged = '../src-work/minecraft'
mainClassServer = 'net.minecraft.server.MinecraftServer'
}
project(project.name)
{
rootDir '.'
sourcesDir project.name + 'Src'
patchDir 'patches'
patchAfter 'clean'
genPatchesFrom 'clean'
genMcpPatches = false
applyMcpPatches = false
s2sKeepImports = true
with common
}
}
processJson
{
// also used to download assets
releaseJson = "jsons/${minecraft.version}-rel.json"
}
// ===== TOP-LEVEL TASKS =====
/**
* setup[Project] is used after you pull from the remote repository
* 1. git pull ...
* 2. gradlew setup[Project]
*/
task('setup' + capitalizedName) {
group = 'ForgeGradle'
dependsOn 'setup'
}
/**
* createRelease creates a ZIP file with all the modified classes
*/
task('createRelease') {
group = 'ForgeGradle'
}
project.afterEvaluate { createRelease.dependsOn tasks.getByName(project.name + 'OutputJar') }
gradle.taskGraph.whenReady
{ graph ->
if (graph.hasTask(':copyCodeToSrc'))
warnOverwrite()
}
void warnOverwrite() {
ant.input(message: 'WARNING: this will overwrite your working changes. Continue? (y/n)', addproperty: 'answer', defaultValue: 'y')
def answer = ant.properties.answer.toLowerCase()
if (answer != 'y' && answer != 'yes')
throw new Exception('User canceled execution')
}
// ===== MODIFY EXISTING TASKS =====
// Exclude Forge files
tasks.getByName('extract' + capitalizedName + 'Sources').exclude '**/SideOnly.java', '**/Side.java'
// ===== DECOMPILING AND DEOBFUSCATING =====
// Only decompile the right side
if (gradle.side == 'client') {
deobfuscateJar.dependsOn.remove mergeJars
deobfuscateJar.dependsOn downloadClient
sourceProcessJar.patches = patcher_plugin.delayedFile(Constants.MCP_PATCHES_CLIENT)
deobfuscateJar.inJar = patcher_plugin.delayedFile(Constants.JAR_CLIENT_FRESH)
} else if (gradle.side == 'server') {
// TODO: ffs half these lines don't work, fix later
deobfuscateJar.dependsOn.remove mergeJars
deobfuscateJar.dependsOn splitServerJar
sourceProcessJar.patches = patcher_plugin.delayedFile(Constants.MCP_PATCHES_SERVER)
deobfuscateJar.inJar = patcher_plugin.delayedFile(Constants.JAR_SERVER_PURE)
}
// Make decompilation as close as possible to the original MCP
if (gradle.useJavadocs) {
remapCleanJar.addsJavadocs = true
tasks.getByName('remap' + capitalizedName + 'Jar').addsJavadocs = true
}
if (gradle.useAstyle) {
task(downloadMcp, type: Download) {
src 'https://www.modcoderpack.com/files/mcp940.zip'
dest 'build/localCache/downloadMcp/mcp940.zip'
}
task(extractAstyle, type: Copy) {
from(zipTree('build/localCache/downloadMcp/mcp940.zip'))
{
include 'runtime/bin/astyle.exe'
include 'runtime/bin/astyle-osx'
}
into 'build/localCache/mcp'
dependsOn downloadMcp
}
sourceProcessJar.outJar = 'build/localCache/sourceProcessJar/sourceProcessed.jar'
task(extractSrcForAstyle, type: Copy) {
from zipTree('build/localCache/sourceProcessJar/sourceProcessed.jar')
into 'build/localCache/astyle'
dependsOn sourceProcessJar
}
task(runAstyle, type: Exec) {
def extra_args = ['--suffix=none', '--quiet', '--recursive',
'--options=' + patcher_plugin.delayedFile(Constants.MCP_DATA_STYLE), 'build/localCache/astyle/*.java']
switch (OS.CURRENT) {
case OS.WINDOWS:
commandLine(['"build/localCache/mcp/runtime/bin/astyle.exe"'] + extra_args)
break
case OS.OSX:
commandLine(['build/localCache/mcp/runtime/bin/astyle-osx'] + extra_args)
break
default:
commandLine(['astyle'] + extra_args)
break
}
dependsOn extractSrcForAstyle
if (OS.CURRENT == OS.WINDOWS || OS.CURRENT == OS.OSX)
dependsOn extractAstyle
}
task(zipAstyledSrc, type: Zip) {
from('build/localCache/astyle')
exclude '**/*.orig'
def destFile = file(patcher_plugin.delayedFile(PatcherConstants.JAR_DECOMP_POST))
destinationDir = destFile.getParentFile()
archiveName = destFile.getName()
includeEmptyDirs = false
dependsOn runAstyle
}
remapCleanJar.dependsOn zipAstyledSrc
tasks.getByName('patch' + capitalizedName + 'Jar').dependsOn zipAstyledSrc
tasks.getByName('remap' + capitalizedName + 'Jar').dependsOn zipAstyledSrc
}
// ===== RECOMPILING AND REOBFUSCATING =====
// Create recompile clean tasks so that we can properly check that two class files are equal without relying on using the same compiler as Mojang
// Compile
task(compileClean, type: TaskSubprojectCall)
{
projectDir = patcher_plugin.subWorkspace('Clean')
callLine = 'jar'
addInitScript(Resources.getResource(TaskSubprojectCall, 'initscriptJar.gradle'))
addReplacement('@RECOMP_DIR@', 'build/compileClean')
addReplacement('@JAR_NAME@', 'recompiled.jar')
mustRunAfter setup
}
// Obfuscate
task(reobfClean, type: TaskReobfuscate)
{
srg = reobfuscate.srg
exc = reobfuscate.exc
preFFJar = reobfuscate.preFFJar
inJar = file('projects/Clean/build/compileClean/recompiled.jar')
methodsCsv = reobfuscate.methodsCsv
fieldsCsv = reobfuscate.fieldsCsv
outJar = file('build/localCache/reobfClean/reobfuscated.jar')
addLibs configurations.forgeGradleMcDeps
dependsOn compileClean, genSrgs, setup
}
// Do the output Jar ourselves because the build-in ForgeGradle version assumes we have permission
// to redistribute the MCP mappings (we don't)
task(project.name + 'OutputJar', type: Zip)
{
from(zipTree(patcher_plugin.delayedFile(PatcherConstants.JAR_OBFUSCATED)))
{
eachFile
{ moddedFile ->
def entryName = moddedFile.getRelativePath().toString()
def vanillaJar = new ZipFile(file('build/localCache/reobfClean/reobfuscated.jar'))
def vanillaEntry = vanillaJar.getEntry entryName
if (vanillaEntry != null) {
def moddedJar = new ZipFile(file(patcher_plugin.delayedFile(PatcherConstants.JAR_OBFUSCATED)))
def moddedEntry = moddedJar.getEntry entryName
if (IOUtils.contentEquals(vanillaJar.getInputStream(vanillaEntry), moddedJar.getInputStream(moddedEntry)))
moddedFile.exclude()
}
}
}
archiveName = "${capitalizedName}_${project.version}.zip"
destinationDir = outputJar.destinationDir
includeEmptyDirs = false
dependsOn reobfClean, reobfuscate
}
// Make [project]OutputJar replace outputJar
tasks.each
{ t ->
if (t.dependsOn.contains(outputJar)) {
t.dependsOn.remove outputJar
t.dependsOn tasks.getByName(project.name + 'OutputJar')
}
}
outputJar.destinationDir = file('build/localCache/outputTrash')
// ===== MAKE ALL SOURCES IN SAME DIRECTORY =====
task('copy' + capitalizedName + 'FromSrc', type: Sync) {
from('src/')
{
eachFile
{ file ->
if (new File('projects/Clean/src/main/java', file.getRelativePath().toString()).isFile())
file.exclude()
}
}
into project.name + 'Src/'
includeEmptyDirs = false
dependsOn extractCleanSources
}
task(copyMcFromSrc, type: Sync) {
from('src/')
{
include 'mcp/**'
}
from('src/')
{
eachFile
{ file ->
if (!(new File('projects/Clean/src/main/java', file.getRelativePath().toString()).isFile()))
file.exclude()
}
exclude 'mcp/**'
}
into "projects/${capitalizedName}/src/main/java"
includeEmptyDirs = false
dependsOn extractCleanSources
}
task('copyCodeToSrc', type: Sync) {
from project.name + 'Src/'
from "projects/${capitalizedName}/src/main/java"
into 'src/'
dependsOn tasks.getByName('extract' + capitalizedName + 'Sources')
includeEmptyDirs = false
}
task(copyResources, type: Sync) {
from "projects/${capitalizedName}/src/main/resources"
into 'resources/'
dependsOn tasks.getByName('extract' + capitalizedName + 'Resources')
includeEmptyDirs = false
}
task downloadFile(type: Download) {
src 'https://launcher.mojang.com/mc/game/1.12.2/server/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar'
dest 'resources/1.12.2.jar'
}
tasks.getByName('makeJar' + capitalizedName).dependsOn tasks.getByName('copy' + capitalizedName + 'FromSrc'), copyMcFromSrc
genIdeProjects.dependsOn copyCodeToSrc, downloadFile
clean {
delete 'src'
}
// ===== PATCH FIXES =====
if (gradle.useJavadocs) {
def retromap = tasks.getByName('retromapMc' + capitalizedName)
task(stripJavadoc, type: Zip) {
from(zipTree('build/localCache/retromapped/retromapped.zip')) {
include '**/*.java'
exclude 'mcp/**'
filter StripJavadoc
}
from(zipTree('build/localCache/retromapped/retromapped.zip')) {
exclude '**/*.java'
}
from(zipTree('build/localCache/retromapped/retromapped.zip')) {
include 'mcp/**'
}
archiveName = file(retromap.out).getName()
destinationDir = file(retromap.out).getParentFile()
dependsOn retromap
}
retromap.out = 'build/localCache/retromapped/retromapped.zip'
project.afterEvaluate { tasks.getByName('gen' + capitalizedName + 'Patches').dependsOn stripJavadoc }
}
task(deleteUnnecessaryPatches) << {
fileTree('patches/').visit
{ file ->
def fileName = file.getPath()
if (fileName.endsWith('.patch')) {
fileName = fileName.substring(0, fileName.length() - 6)
if (FileUtils.contentEquals(project.file('src/' + fileName), project.file('projects/Clean/src/main/java/' + fileName))) {
delete file.getFile()
}
}
}
}
deleteUnnecessaryPatches.dependsOn extractCleanSources
afterEvaluate {
tasks.getByName('gen' + capitalizedName + 'Patches').dependsOn.each { deleteUnnecessaryPatches.dependsOn it }
tasks.each
{ task ->
if (task.dependsOn.contains(tasks.getByName('gen' + capitalizedName + 'Patches')))
task.dependsOn deleteUnnecessaryPatches
}
}
// ===== REMOVE UNNECESSARY TASKS =====
// Again, half these lines don't work either, ffs
def sideToIgnore = null
if (gradle.side == 'client')
sideToIgnore = 'Server'
else if (gradle.side == 'server')
sideToIgnore = 'Client'
tasks.each
{ t ->
t.dependsOn.remove makeCleanStart
t.dependsOn.remove tasks.getByName('make' + capitalizedName + 'Start')
if (sideToIgnore != null) {
t.dependsOn.remove tasks.getByName('makeEclipseCleanRun' + sideToIgnore)
t.dependsOn.remove tasks.getByName('makeEclipse' + capitalizedName + 'Run' + sideToIgnore)
t.dependsOn.remove tasks.getByName('makeIdeaCleanRun' + sideToIgnore)
t.dependsOn.remove tasks.getByName('makeIdea' + capitalizedName + 'Run' + sideToIgnore)
}
}
installer.enabled = false
installer.dependsOn.remove downloadInstaller
installer.dependsOn.remove outputJar
installer.dependsOn.remove processJson
//Adds idea tools tab
task setupProject {
group = 'tools ' + capitalizedName
description = 'Sets project up from patches, or clean project running it the first time'
dependsOn 'setup' + capitalizedName
}
task generatePatches {
group = 'tools ' + capitalizedName
description = 'Convert project to patches for public distribution'
dependsOn genPatches
}
task releaseProject {
group = 'tools ' + capitalizedName
description = 'Creates a release from the current project'
dependsOn createRelease
}
task runServer {
group = 'tools ' + capitalizedName
description = 'runs the minecraft server'
dependsOn run
}