forked from mchorse/blockbuster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
383 lines (309 loc) · 11.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
import java.util.regex.Matcher
import java.util.regex.Pattern
buildscript
{
repositories
{
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath 'org.yaml:snakeyaml:1.18'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
if (project.hasProperty("dev"))
{
version += "-dev" + dev
}
group = "mchorse.blockbuster"
archivesBaseName = "blockbuster"
sourceCompatibility = targetCompatibility = "1.8"
compileJava
{
sourceCompatibility = targetCompatibility = "1.8"
}
/* Minecraft configuration */
minecraft
{
version = "${mc_version}-${forge_version}"
runDir = "run"
mappings = snapshot
clientJvmArgs = ["-Xmx5G", "-Dfml.coreMods.load=" + coremodPath]
serverJvmArgs = ["-Xmx5G"]
replace "%VERSION%", project.version
replace "%METAMORPH%", project.metamorph
replace "%MCLIB%", project.mclib
replace "%APERTURE%", project.aperture
replace "%EMOTICONS%", project.emoticons
replace "%MINEMA%", project.minema
}
dependencies
{
compile files("run/libs/mclib-${mclib}-${project.minecraft.version}-dev.jar")
compile files("run/libs/metamorph-${metamorph}-${project.minecraft.version}-dev.jar")
compile files("run/libs/aperture-${aperture}-${project.minecraft.version}-dev.jar")
compile files("run/libs/Minema-${minema}-${project.minecraft.version}-dev.jar")
}
jar {
manifest {
attributes 'FMLCorePlugin': coremodPath, 'FMLCorePluginContainsFMLMod': 'true'
}
}
eclipse
{
classpath
{
file
{
whenMerged
{ classpath ->
def ver = project.minecraft.version
/* Fucking gradle 2.14 doesn't have fileReference() method,
* screw you piece of shit */
def getMeReference = { File file ->
return [
getFile: { return file },
getPath: { return file.getAbsolutePath() },
getJarURL: { return file.getAbsolutePath() },
isRelativeToPathVariable: { return false }
] as org.gradle.plugins.ide.eclipse.model.FileReference
}
def lib = entries.find { it.path.contains "metamorph-${metamorph}" }
lib.sourcePath = getMeReference(file("run/libs/metamorph-${metamorph}-${ver}-sources.jar"))
lib = entries.find { it.path.contains "aperture-${aperture}" }
lib.sourcePath = getMeReference(file("run/libs/aperture-${aperture}-${ver}-sources.jar"))
lib = entries.find { it.path.contains "mclib-${mclib}" }
lib.sourcePath = getMeReference(file("run/libs/mclib-${mclib}-${ver}-sources.jar"))
}
}
}
}
processResources
{
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
project.version += "-" + project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
/* Dev build */
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'dev'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
classifier = 'sources'
}
artifacts {
archives deobfJar
archives sourcesJar
}
/* Build language files from YML */
task buildLangFiles {
doLast {
def help = file("help")
def flatten
/**
* Flattens the map
*/
flatten = { Map map, Map original, String prefix ->
for (entry in original.entrySet())
{
def value = entry.getValue();
if (value instanceof String)
{
map.put(prefix + entry.getKey(), value)
}
else if (value instanceof Map)
{
flatten(map, value, prefix + entry.getKey() + ".")
}
else
{
map.put(prefix + entry.getKey(), value.toString())
}
}
}
/**
* Process the string read from the YML.
*
* This method replaces new line symbols to escaped new line symbols
* and processes {} formatting to § Minecraft formatting.
*/
def processString = { String str ->
return str.replace("\n", "\\n").replaceAll('\\{([\\w\\d_]+)\\}', '§$1')
}
/**
* Compile YML file's contents to ini string
*/
def compile = {File file ->
def output = "\n\n# " + file.getName() + "\n";
def yaml = new org.yaml.snakeyaml.Yaml()
def map = yaml.load(file.text)
def flat_map = new HashMap()
flatten(flat_map, map, "")
for (entry in flat_map.entrySet())
{
output += "${entry.getKey()}=${processString(entry.getValue())}\n";
}
return output
}
def replaceNestedLanguageKeys = {File langFile ->
String newLangText = langFile.text
/* replace {yamlfile.key_bla_bla} with the value of the language key in the current language dir */
Matcher m = Pattern.compile('\\{([\\w\\d_.]+)\\}').matcher(newLangText);
while (m.find())
{
String match = m.group()
String langKey = project.archivesBaseName + "." + match.replace('{', '').replace('}', '')
int indexKey = newLangText.indexOf(langKey)
int end = indexKey
int begin = -1
while (end < newLangText.length())
{
if (newLangText[end] == "\n" || newLangText[end] == "\r\n")
{
break
}
if (newLangText[end].equals("=") && begin == -1)
{
begin = end + 1
}
end++
}
String value = newLangText.substring(begin, end)
if (value != null)
{
newLangText = newLangText.replace(match, '"' + value + '"')
}
m = Pattern.compile('\\{([\\w\\d_.]+)\\}').matcher(newLangText);
}
return newLangText
}
/**
* Convert given langauge dir from YML to ini
*/
def convert = { File lang_dir ->
/* Forge directive that allows \n symbols to be allowed in the chat */
def output = "#PARSE_ESCAPES"
def output_file = file("src/main/resources/assets/${project.archivesBaseName}/lang/${lang_dir.getName()}.lang")
for (file in lang_dir.listFiles())
{
if (file.getName().endsWith(".yml"))
{
output += compile(file)
}
}
def parentFile = output_file.getParentFile()
if (!parentFile.exists())
{
parentFile.mkdirs();
}
OutputStream os = new FileOutputStream(output_file);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
writer.println(output.trim())
writer.close()
}
if (help.exists())
{
for (lang_dir in help.listFiles())
{
if (lang_dir.isDirectory())
{
convert(lang_dir)
println "Converted ${lang_dir.getName()} to language file"
}
}
def langFile = file("src/main/resources/assets/${project.archivesBaseName}/lang/")
if (langFile.exists())
{
for (file in langFile.listFiles())
{
String output = replaceNestedLanguageKeys(file)
OutputStream os = new FileOutputStream(file);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
writer.print(output.trim())
writer.close()
}
}
else
{
println "Directory 'lang' is not found!"
}
}
else
{
println "Directory 'help' is not found!"
}
}
}
tasks.processResources.dependsOn('buildLangFiles')
/* Comparing keys */
task compareLangFiles {
doLast {
def help = file("src/main/resources/assets/${project.archivesBaseName}/lang/")
def parse = { File file ->
def map = new HashMap()
def splits = file.text.split("\n");
for (split in splits) {
def index = split.indexOf("=")
if (index == -1) {
continue
}
map.put(split.substring(0, index), true)
}
return map
}
if (!help.exists()) {
return
}
def en = file("${help.getAbsolutePath()}/en_US.lang")
def en_map = parse(en)
for (lang_file in help.listFiles()) {
if (!lang_file.name.endsWith(".lang") || lang_file.name.startsWith("en_US")) {
continue
}
def lang_map = parse(lang_file)
def missing = new ArrayList()
def extra = new ArrayList()
for (key in en_map.keySet()) {
if (!lang_map.containsKey(key)) {
missing.add(key)
}
}
for (key in lang_map.keySet()) {
if (!en_map.containsKey(key)) {
extra.add(key)
}
}
missing.sort()
extra.sort()
print("\n")
if (!missing.isEmpty() || !extra.isEmpty()) {
if (!missing.isEmpty()) {
print("Language file ${lang_file.getName()} misses following keys:\n")
for (key in missing) {
print("- ${key}\n")
}
}
if (!extra.isEmpty()) {
print("Language file ${lang_file.getName()} has additional keys:\n")
for (key in extra) {
print("- ${key}\n")
}
}
}
else {
print("Language file ${lang_file.getName()} fully matches ${en.getName()}!\n")
}
}
}
}