-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.gradle
More file actions
321 lines (291 loc) · 12 KB
/
build.gradle
File metadata and controls
321 lines (291 loc) · 12 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
buildscript {
ext {
spotlessVersion = (project['spotless.version'] as String)
errorpronePluginVersion = (project['errorprone-plugin.version'] as String)
}
}
plugins {
id 'java-base'
id 'net.ltgt.errorprone' version "$errorpronePluginVersion" apply false
id 'com.diffplug.spotless' version "$spotlessVersion" apply false
}
final File hypertaleGradleDirectory = new File(project.gradle.gradleUserHomeDir, "hypertale")
if (!hypertaleGradleDirectory.isDirectory() && !hypertaleGradleDirectory.mkdirs()) {
// Fail if we cannot create the folder required for building Hypertale!
throw new IOException("Failed to create hypertale gradle directory")
}
final File runDirectory = new File(rootDir, "run")
if (!runDirectory.isDirectory() && !runDirectory.mkdirs()) {
// Fail if we cannot create the folder required for building Hypertale!
throw new IOException("Failed to create run directory")
}
final File mavenLocalFile = new File(System.getProperty("user.home") +
File.separator + ".m2" + File.separator + "repository")
final File releaseFolder = new File(project.layout.buildDirectory.get().asFile, "release")
final File mavenDestination = new File(releaseFolder, "maven")
final File javaDocDestination = new File(releaseFolder,
"javadoc" + File.separator + "hypertale")
final File javaDocSourceRoot = new File(rootDir, "dev" + File.separator +
"src" + File.separator + "main" + File.separator + "javadoc")
final File javadocExtraCSS = new File(javaDocSourceRoot,
"resource-files" + File.separator + "hypertale-javadoc.css")
final File localPropertiesFile = new File(rootProject.rootDir, "local.properties")
final Properties localProperties = new Properties()
if (localPropertiesFile.isFile()) {
try (FileInputStream fileInputStream = new FileInputStream(localPropertiesFile)) {
localProperties.load(new BufferedInputStream(fileInputStream))
}
}
boolean nonRelease = "release" != localProperties.getOrDefault("build.patchline", "release")
tasks.register('publishToMavenLocal', Task).configure {
shouldRunAfter("build")
}
tasks.register('spotlessApply', Task)
tasks.register('buildAndPublishToMavenLocal', Task).configure {
group = "build"
description = "Build this project then publish it to maven local"
dependsOn("publishToMavenLocal")
dependsOn("build")
}
final String processedLicense = '/*\n' + file('LICENSE').readLines()
.collect { ' * ' + it }.join('\n') + '\n */\n'
subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.spotless'
version = project['hypertale.version']
group = 'com.fox2code.Hypertale'
configurations {
include { transitive = false }
compileOnly.extendsFrom(include)
testCompileOnly.extendsFrom(include)
}
repositories {
mavenCentral()
maven {
name = 'Fox2Code Maven'
url = 'https://cdn.fox2code.com/maven'
content {
includeGroup 'com.github.bawnorton.mixinsquared'
includeGroup 'com.fox2code.Hypertale'
includeGroup 'com.fox2code'
}
}
}
spotless {
java {
targetExclude "build/generated/**/*.java"
cleanthat().excludeMutator('ModifierOrder')
licenseHeader(processedLicense)
removeUnusedImports()
formatAnnotations()
}
}
afterEvaluate {
jar {
from(configurations.include.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude("module-info.class")
}
}
tasks.withType(Javadoc).configureEach {
options.addStringOption('Xdoclint:-missing', '-quiet')
}
if (project.pluginManager.hasPlugin("net.ltgt.errorprone")) {
tasks.withType(JavaCompile).configureEach {
options.errorprone {
disableWarningsInGeneratedCode.set(true)
allErrorsAsWarnings.set(true)
disable("EmptyCatch", "ThreadPriorityCheck", "NonApiType", "MutablePublicArray",
"StringSplitter", "FloggerFormatString", "FloggerLogString", "FloggerStringConcatenation",
"AssignmentExpression", "FutureReturnValueIgnored")
warn("DefaultCharset")
}
}
}
tasks.withType(AbstractArchiveTask).configureEach {
reproducibleFileOrder = true
preserveFileTimestamps = false
}
// Always apply spotless on compile
spotlessJavaCheck.enabled = false
compileJava.dependsOn(spotlessApply)
if (project.pluginManager.hasPlugin("groovy")) {
spotless {
groovy {
licenseHeader(processedLicense)
}
}
compileGroovy.dependsOn(spotlessApply)
}
rootProject.tasks.spotlessApply.dependsOn(spotlessApply)
if (project.pluginManager.hasPlugin("maven-publish")) {
rootProject.tasks.publishToMavenLocal.dependsOn(publishToMavenLocal)
publishing {
publications {
release(MavenPublication) {
from components.java
pom {
url = 'https://github.com/Fox2Code/Hypertale'
}
}
}
}
}
}
}
tasks.build.dependsOn(":patcher:patchHytale")
tasks.register("fastBuild").configure {
group = "build"
description = "Build this project skipping testing and patching"
dependsOn(":launcher:assemble")
dependsOn(":launcher:test")
dependsOn(":init:test")
dependsOn(":dev:test")
}
tasks.register("runServer").configure {
dependsOn(tasks.build)
dependsOn(":launcher:runServer")
}
tasks.register("cleanRelease", Delete) {
delete releaseFolder
}
record ReplaceAction(String from, String to, boolean firstOnly) {
ReplaceAction(String from, String to) {
this(from, to, false)
}
String replace(String text) {
if (this.firstOnly) {
int index = text.indexOf(this.from)
if (index == -1) return text;
return new StringBuilder(text.length() + this.to.length() - this.from.length())
.append(text, 0, index).append(this.to)
.append(text, index + this.from.length(), text.length()).toString()
} else {
return text.replace(this.from, this.to)
}
}
}
tasks.register("aggregateJavadocs", Javadoc) {
group = "documentation"
description = "Merge Javadocs from all subprojects into a single unified site."
destinationDir = javaDocDestination
source = files({
subprojects.collect {sub ->
if (sub.name === "patcher" || sub.name === "launcher") {
sub.provider { sub.sourceSets.main.allJava }
}
}
})
classpath = files({
subprojects.collect {sub ->
if (sub.name === "patcher") {
sub.provider { sub.sourceSets.main.compileClasspath }
} else if (sub.name === "launcher") {
sub.provider {
[sub.sourceSets.main.compileClasspath, sub.sourceSets.main.output]
}
}
}
})
exclude("com/build_9/hyxin/*")
exclude("com/fox2code/hypertale/commands/*")
exclude("com/fox2code/hypertale/dashboard/*")
exclude("com/fox2code/hypertale/patcher/mixin/*")
exclude("com/fox2code/hypertale/patcher/patches/*")
options.addStringOption('Xdoclint:-missing', '-quiet')
options.addStringOption('-add-stylesheet', javadocExtraCSS.absolutePath)
options.addStringOption('header', "<span class='hypertale-nav-title'>" +
"<span class='hypertale-name'>Hypertale</span> ${project['hypertale.version']} API</span>")
options.addStringOption('doctitle', "<span class='hypertale-overview-title'>" +
"<span class='hypertale-name'>Hypertale</span> ${project['hypertale.version']} API</span>")
options.windowTitle = "Hypertale ${project['hypertale.version']} API"
options.memberLevel = JavadocMemberLevel.PUBLIC
options.links += "https://asm.ow2.io/javadoc/"
doFirst {
if (nonRelease) {
throw new RuntimeException("Cannot make a release while targetting a non-release hytale branch")
}
}
doLast {
copy {
from javaDocSourceRoot
into javaDocDestination
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
ArrayList<ReplaceAction> replaceActions = new ArrayList<>()
for (String modifier : ["public", "static", "abstract", "final", "interface"]) {
replaceActions.add(new ReplaceAction(modifier,
"<span class='hypertale-modifier'>" + modifier + "</span>"))
}
for (String primitive : ["void", "byte", "short", "int", "long",
"float", "double", "char", "boolean"]) {
replaceActions.add(new ReplaceAction(primitive + " ",
"<span class='hypertale-primitive'>" + primitive + "</span> "))
replaceActions.add(new ReplaceAction(primitive + "\n",
"<span class='hypertale-primitive'>" + primitive + "</span>\n"))
replaceActions.add(new ReplaceAction(primitive + "<",
"<span class='hypertale-primitive'>" + primitive + "</span><"))
}
for (String modifier : ["extends", "throws"]) {
replaceActions.add(new ReplaceAction(modifier,
"<span class='hypertale-keyword'>" + modifier + "</span>"))
}
replaceActions.add(new ReplaceAction("class com.fox2code.hypertale.",
"<span class='hypertale-keyword'>class</span> com.fox2code.hypertale."))
replaceActions.add(new ReplaceAction("package com.fox2code.hypertale.",
"<span class='hypertale-keyword'>package</span> com.fox2code.hypertale."))
replaceActions.add(new ReplaceAction(
"<span class='hypertale-modifier'>interface</span> in ", "interface in "))
replaceActions.add(new ReplaceAction(">com.fox2code.hypertale.",
">com.fox2code.<span class='hypertale-package'>hypertale</span>."))
replaceActions.add(new ReplaceAction('</li>\n</ul>',
'</li>\n' + // Add GitHub link to JavaDoc!
'<li><a target="_blank" href="https://github.com/Fox2Code/Hypertale">GitHub</a></li>' +
'</ul>', true))
replaceActions.add(new ReplaceAction('</head>',
'<meta name="darkreader-lock">\n' +
'</head>'))
fileTree(javaDocDestination).matching {
include '**/*.html'
}.forEach { htmlFile ->
String text = htmlFile.getText('UTF-8')
for (ReplaceAction replaceAction : replaceActions) {
text = replaceAction.replace(text)
}
htmlFile.write(text, 'UTF-8')
}
}
dependsOn("cleanRelease")
dependsOn(":launcher:jar")
}
tasks.register("fastUpdateJavaDocResources") {
doLast {
copy {
from javaDocSourceRoot
into javaDocDestination
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
}
tasks.register("makeRelease", Copy) {
group = "build"
description = "Make release for maven uploading!"
dependsOn("cleanRelease")
dependsOn("aggregateJavadocs")
dependsOn("buildAndPublishToMavenLocal")
dependsOn(":launcher:test")
from(mavenLocalFile) {
include "com/fox2code/Hypertale/dev/${project['hypertale.version']}/*"
include "com/fox2code/Hypertale/launcher/${project['hypertale.version']}/*"
include "hypertale/dev/hypertale.dev.gradle.plugin/${project['hypertale.version']}/*"
}
into mavenDestination
}
tasks.register("makeMajorRelease") {
group = "build"
description = "Make release for maven uploading with extra libraries!"
dependsOn("makeRelease")
dependsOn(":launcher:makeLibraries")
}
build {
dependsOn(":launcher:clean")
}