-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbuildsc.resources.gradle
50 lines (46 loc) · 2.07 KB
/
buildsc.resources.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
/*
* Defines custom project properties.
*/
ext
{
// The following properties are used to dynamically generate properties for 'fabric.mod.json':
fmj_jars = null; //fabric.mod.json/jars - Used to generate the 'jars' property of 'fabric.mod.json'.
fmj_mixins = null; //fabric.mod.json/mixins - Used to generate the 'mixins' property of 'fabric.mod.json'.
}
/*
* Dynamically define the 'ext' properties.
*/
do
{
def rssDirPath = new File("${project.projectDir}/src/main/resources").toPath();
//obtain all jar files in `jarjar`, and construct a String for the `jars` entry in `fabric.mod.json`.
//due to a bug in the compiler, this uses a cheesy workaround that injects json code into a json string
def fmj_jars = new ArrayList<String>();
fileTree(dir: rssDirPath.resolve("META-INF/jarjar").toString(), include: '*.jar')
.each { jarFile -> fmj_jars.add(rssDirPath.relativize(jarFile.toPath()).toString().replace('\\', '/')) };
fmj_jars = fmj_jars.collect { jarFile -> "{ \"file\": \"${jarFile}\" }" };
fmj_jars = "\", \"jars\": [" + fmj_jars.join(', ') + "], \"\": \"";
project.ext.fmj_jars = fmj_jars;
//obtain all mixin files in `resources` and construct a String for the `mixins` entry in `fabric.mod.json`
//due to a bug in the compiler, this uses a cheesy workaround that injects json code into a json string
def fmj_mixins = new ArrayList<String>();
fileTree(dir: rssDirPath.toString(), include: '*.json').each { jsonFile ->
//skip non-mixin files
if(!jsonFile.getName().contains(".mixin.") && !jsonFile.getName().contains(".mixins.")) return;
//add file name to the list
fmj_mixins.add(jsonFile.getName());
}
fmj_mixins = fmj_mixins.collect { jsonFile -> "\"${jsonFile}\"" }.join(", ");
fmj_mixins = "\", \"mixins\": [" + fmj_mixins + "], \"\": \"";
project.ext.fmj_mixins = fmj_mixins;
}
while(false);
/*
* The following task is responsible for processing and including
* resource files in the built mod jar file.
*/
processResources
{
//expand project properties to resources that might need them
filesMatching(["*.json", "pack.mcmeta"]) { expand(project: project); }
}