forked from MinecraftForge/ForgeGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPatcherProject.java
More file actions
674 lines (584 loc) · 18.1 KB
/
PatcherProject.java
File metadata and controls
674 lines (584 loc) · 18.1 KB
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
/*
* A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins.
* Copyright (C) 2013-2019 Minecraft Forge
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.minecraftforge.gradle.patcher;
import static net.minecraftforge.gradle.patcher.PatcherConstants.DEFAULT_RES_DIR;
import static net.minecraftforge.gradle.patcher.PatcherConstants.DEFAULT_SRC_DIR;
import static net.minecraftforge.gradle.patcher.PatcherConstants.DEFAULT_TEST_RES_DIR;
import static net.minecraftforge.gradle.patcher.PatcherConstants.DEFAULT_TEST_SRC_DIR;
import groovy.lang.Closure;
import java.io.File;
import java.io.Serializable;
import net.minecraftforge.gradle.common.Constants;
import net.minecraftforge.gradle.util.GradleConfigurationException;
import org.gradle.api.Project;
import com.google.common.base.Strings;
public class PatcherProject implements Serializable
{
private static final long serialVersionUID = 1L;
private final transient Project project;
private final String name;
private final String capName;
private String patchAfter = "clean";
private String genPatchesFrom;
private File rootDir;
private File patchDir;
private File sourcesDir;
private File resourcesDir;
private File testSourcesDir;
private File testResourcesDir;
private String mainClassClient = "GradleStart";
private String mainClassServer = "GradleStartServer";
private String tweakClassClient = "";
private String tweakClassServer = "";
private String runArgsClient = "";
private String runArgsServer = "";
private String patchPrefixOriginal = "";
private String patchPrefixChanged = "";
private boolean genMcpPatches = false;
private boolean applyMcpPatches = false;
private boolean s2sKeepImports = true;
protected PatcherProject(String name, PatcherPlugin plugin)
{
this.name = name;
this.project = plugin.project;
rootDir = project.getProjectDir();
// make capName
char char1 = name.charAt(0);
capName = Character.toUpperCase(char1) + name.substring(1);
}
public String getName()
{
return name;
}
public String getCapName()
{
return capName;
}
/**
* @return NULL if only applies to clean
*/
public String getPatchAfter()
{
return patchAfter;
}
/**
* Sets the project after which this project will apply its patches.
* All patches apply on top of the clean project anyways.
* @param patchAfter project to patch after
*/
public void setPatchAfter(String patchAfter)
{
if (Strings.isNullOrEmpty(patchAfter))
this.patchAfter = "clean";
else
this.patchAfter = patchAfter;
}
/**
* Sets the project after which this project will apply its patches
* All patches apply on top of the clean project anyways.
* @param patchAfter project to patch after
*/
public void patchAfter(String patchAfter)
{
setPatchAfter(patchAfter);
}
/**
* Sets the project after which this project will apply its patches
* All patches apply on top of the clean project anyways.
* @param patcher project to patch after
*/
public void setPatchAfter(PatcherProject patcher)
{
this.patchAfter = patcher.getName();
}
/**
* Sets the project after which this project will apply its patches
* All patches apply on top of the clean project anyways.
* @param patcher project to patch after
*/
public void patchAfter(PatcherProject patcher)
{
setPatchAfter(patcher);
}
/**
* @return NULL to not generate patches, "clean" to generate from the clean project.
*/
public String getGenPatchesFrom()
{
return genPatchesFrom;
}
/**
* The project from witch the patches for this project will be generated.
* By default, patches are not generated at all.
* To generate patches against the "clean" project, specify "clean" ast the argument.
* @param generateFrom Project to generate patches from
*/
public void setGenPatchesFrom(String generateFrom)
{
this.genPatchesFrom = generateFrom;
}
/**
* The project from witch the patches for this project will be generated.
* By default, patches are not generated at all.
* To generate patches against the "clean" project, specify "clean" ast the argument.
* @param patcher Project to generate patches from
*/
public void setGenPatchesFrom(PatcherProject patcher)
{
this.genPatchesFrom = patcher.getName();
}
/**
* The project from witch the patches for this project will be generated.
* By default, patches are not generated at all.
* To generate patches against the "clean" project, specify "clean" ast the argument.
* @param generateFrom Project to generate patches from
*/
public void genPatchesFrom(String generateFrom)
{
setGenPatchesFrom(generateFrom);
}
protected boolean doesGenPatches()
{
return genPatchesFrom != null;
}
/**
* The project from witch the patches for this project will be generated.
* By default, patches are not generated at all.
* To generate patches against the "clean" project, specify "clean" ast the argument.
* @param patcher Project to generate patches from
*/
public void generateFrom(PatcherProject patcher)
{
setGenPatchesFrom(patcher);
}
public File getRootDir()
{
return rootDir;
}
/**
* The root directory of the project. This may or may not be actually used depending on the other directories.
* @param rootDir root directory of the project
*/
public void setRootDir(Object rootDir)
{
this.rootDir = project.file(rootDir);
}
/**
* The root directory of the project. This may or may not be actually used depending on the other directories.
* @param rootDir root directory of the project
*/
public void rootDir(Object rootDir)
{
setRootDir(rootDir);
}
public File getPatchDir()
{
return patchDir;
}
/**
* The directory where the patches are found, and to whitch generated patches should be saved.
* By default this is rootDir/patches
* @param patchDir patch directory of the project
*/
public void setPatchDir(Object patchDir)
{
this.patchDir = project.file(patchDir);
}
/**
* The directory where the patches are found, and to witch generated patches should be saved.
* By default this is rootDir/patches
* @param patchDir patch directory of the project
*/
public void patchDir(Object patchDir)
{
setPatchDir(patchDir);
}
public File getSourcesDir()
{
return getFile(sourcesDir, DEFAULT_SRC_DIR);
}
/**
* The directory where the non-patch sources for this project are.
* By default this is rootDir/src/main/java
* @param sourcesDir non-MC source directory of the project
*/
public void setSourcesDir(Object sourcesDir)
{
this.sourcesDir = project.file(sourcesDir);
}
/**
* The directory where the non-patch sources for this project are.
* By default this is rootDir/src/main/java
* @param sourcesDir non-MC source directory of the project
*/
public void sourcesDir(Object sourcesDir)
{
setSourcesDir(sourcesDir);
}
public File getResourcesDir()
{
return getFile(resourcesDir, DEFAULT_RES_DIR);
}
/**
* The directory where the non-patch resources for this project are.
* By default this is rootDir/src/main/resources
* @param resourcesDir non-MC resource directory of the project
*/
public void setResourcesDir(Object resourcesDir)
{
this.resourcesDir = project.file(resourcesDir);
}
/**
* The directory where the non-patch resources for this project are.
* By default this is rootDir/src/main/resources
* @param resourcesDir non-MC resource directory of the project
*/
public void resourcesDir(Object resourcesDir)
{
setResourcesDir(resourcesDir);
}
public File getTestSourcesDir()
{
return getFile(testSourcesDir,DEFAULT_TEST_SRC_DIR);
}
/**
* The directory where the test sourcess for this project are.
* By default this is rootDir/src/test/sources
* @param testSourcesDir test source directory of the project
*/
public void setTestSourcesDir(Object testSourcesDir)
{
this.testSourcesDir = project.file(testSourcesDir);
}
/**
* The directory where the test sourcess for this project are.
* By default this is rootDir/src/test/sources
* @param testSourcesDir test source directory of the project
*/
public void testSourcesDir(Object testSourcesDir)
{
setSourcesDir(testSourcesDir);
}
public File getTestResourcesDir()
{
return getFile(testResourcesDir, DEFAULT_TEST_RES_DIR);
}
/**
* The directory where the non-patch resources for this project are.
* By default this is rootDir/src/test/resources
* @param testResourcesDir test resource directory of the project
*/
public void setTestResourcesDir(Object testResourcesDir)
{
this.testResourcesDir = project.file(testResourcesDir);
}
/**
* The directory where the non-patch resources for this project are.
* By default this is rootDir/src/test/resources
* @param testResourcesDir test resource directory of the project
*/
public void testResourcesDir(Object testResourcesDir)
{
setTestResourcesDir(testResourcesDir);
}
public String getMainClassClient()
{
return mainClassClient;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param mainClass main class name
*/
public void setMainClassClient(Object mainClass)
{
this.mainClassClient = Constants.resolveString(mainClass);
}
public void mainClassClient(Object mainClass)
{
setMainClassClient(mainClass);
}
public String getTweakClassClient()
{
return tweakClassClient;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param tweakClass tweaker class name
*/
public void setTweakClassClient(Object tweakClass)
{
this.tweakClassClient = Constants.resolveString(tweakClass);
}
public void tweakClassClient(Object mainClass)
{
setTweakClassClient(mainClass);
}
public String getRunArgsClient()
{
return runArgsClient;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param runArgs arguments
*/
public void setRunArgsClient(Object runArgs)
{
this.runArgsClient = Constants.resolveString(runArgs);
}
public void runArgsClient(Object mainClass)
{
setRunArgsClient(mainClass);
}
public String getMainClassServer()
{
return mainClassServer;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param mainClass main class name
*/
public void setMainClassServer(Object mainClass)
{
this.mainClassServer = Constants.resolveString(mainClass);
}
public void mainClassServer(Object mainClass)
{
setMainClassServer(mainClass);
}
public String getTweakClassServer()
{
return tweakClassServer;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param tweakClass tweaker class name
*/
public void setTweakClassServer(Object tweakClass)
{
this.tweakClassServer = Constants.resolveString(tweakClass);
}
public void tweakClassServer(Object mainClass)
{
setTweakClassServer(mainClass);
}
public String getRunArgsServer()
{
return runArgsServer;
}
/**
* This is used for the run configs and the manifest of the universal jar.
* @param runArgs arguments
*/
public void setRunArgsServer(Object runArgs)
{
this.runArgsServer = Constants.resolveString(runArgs);
}
public void runArgsServer(Object mainClass)
{
setRunArgsServer(mainClass);
}
public String getPatchPrefixOriginal()
{
return patchPrefixOriginal;
}
/**
* The path prefix of the "original" path in the patch files.
* @param patchPrefixOriginal prefix
*/
public void setPatchPrefixOriginal(Object patchPrefixOriginal)
{
this.patchPrefixOriginal = Constants.resolveString(patchPrefixOriginal);
}
public void patchPrefixOriginal(Object patchPrefixOriginal)
{
setPatchPrefixOriginal(patchPrefixOriginal);
}
public String getPatchPrefixChanged()
{
return patchPrefixChanged;
}
/**
* The path prefix of the "changed" path in the patch files.
* @param patchPrefixChanged prefix
*/
public void setPatchPrefixChanged(Object patchPrefixChanged)
{
this.patchPrefixChanged = Constants.resolveString(patchPrefixChanged);
}
public void patchPrefixChanged(Object patchPrefixChanged)
{
setPatchPrefixChanged(patchPrefixChanged);
}
// ------------------------
// HELPERS
// ------------------------
/**
* Validates the object to ensure its been configured correctly and isnt missing something.
*/
protected void validate()
{
if (rootDir == null && patchDir == null)
throw new GradleConfigurationException("PatchDir not specified for project '"+ name +"'");
}
private File getFile(File field, String defaultPath)
{
if (field == null && rootDir != null)
return new File(getRootDir(), defaultPath);
else
return ((File) field);
}
public boolean isGenMcpPatches()
{
return genMcpPatches;
}
public void setGenMcpPatches(boolean genMcpPatches)
{
this.genMcpPatches = genMcpPatches;
}
public boolean isApplyMcpPatches()
{
return applyMcpPatches;
}
public void setApplyMcpPatches(boolean applyMcpPatches)
{
this.applyMcpPatches = applyMcpPatches;
}
public boolean isS2sKeepImports()
{
return s2sKeepImports;
}
public void setS2sKeepImports(boolean value)
{
this.s2sKeepImports = value;
}
// ------------------------
// DELAYED GETTERS
// ------------------------
@SuppressWarnings("serial")
protected Closure<String> getDelayedMainClassClient()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getMainClassClient();
}
};
}
@SuppressWarnings("serial")
protected Closure<String> getDelayedTweakClassClient()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getTweakClassClient();
}
};
}
@SuppressWarnings("serial")
protected Closure<String> getDelayedRunArgsClient()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getRunArgsClient();
}
};
}
@SuppressWarnings("serial")
protected Closure<String> getDelayedMainClassServer()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getMainClassServer();
}
};
}
@SuppressWarnings("serial")
protected Closure<String> getDelayedTweakClassServer()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getTweakClassServer();
}
};
}
@SuppressWarnings("serial")
protected Closure<String> getDelayedRunArgsServer()
{
return new Closure<String>(PatcherProject.class) {
public String call()
{
return getRunArgsServer();
}
};
}
@SuppressWarnings("serial")
protected Closure<File> getDelayedSourcesDir()
{
return new Closure<File>(PatcherProject.class) {
public File call()
{
return getSourcesDir();
}
};
}
@SuppressWarnings("serial")
protected Closure<File> getDelayedResourcesDir()
{
return new Closure<File>(PatcherProject.class) {
public File call()
{
return getResourcesDir();
}
};
}
@SuppressWarnings("serial")
protected Closure<File> getDelayedTestSourcesDir()
{
return new Closure<File>(PatcherProject.class) {
public File call()
{
return getTestSourcesDir();
}
};
}
@SuppressWarnings("serial")
protected Closure<File> getDelayedTestResourcesDir()
{
return new Closure<File>(PatcherProject.class) {
public File call()
{
return getTestResourcesDir();
}
};
}
@SuppressWarnings("serial")
protected Closure<File> getDelayedPatchDir()
{
return new Closure<File>(PatcherProject.class) {
public File call()
{
return getPatchDir();
}
};
}
}