-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
460 lines (385 loc) · 15.8 KB
/
Copy pathbuild.gradle
File metadata and controls
460 lines (385 loc) · 15.8 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
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
buildscript {
repositories {
mavenCentral()
google()
maven {
url = "https://plugins.gradle.org/m2/"
}
maven { url = uri("https://teavm.org/maven/repository") }
maven { url = uri("https://maven.ngengine.org/riccardobl/teavm") }
}
dependencies {
classpath libs.android.build.gradle
classpath libs.spotbugs.gradle.plugin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20"
}
}
plugins {
id 'org.jetbrains.dokka' version '2.0.0'
id 'com.diffplug.spotless' version '7.0.2' apply false
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
}
apply from: file('version.gradle')
if(System.getenv("SONATYPE_USERNAME") || project.findProperty("sonatypeUsername")){
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
username = System.getenv("SONATYPE_USERNAME") ?: project.findProperty("sonatypeUsername") ?: ""
password = System.getenv("SONATYPE_PASSWORD") ?: project.findProperty("sonatypePassword") ?: ""
packageGroup = "org.ngengine"
}
}
}
}
allprojects {
group = 'org.ngengine'
version = jmeFullVersion
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri("https://central.sonatype.com/repository/maven-snapshots")
}
google()
maven { url = uri("https://teavm.org/maven/repository") }
maven { url = uri("https://maven.ngengine.org/riccardobl/teavm") }
}
tasks.withType(Jar) {
duplicatesStrategy = 'include'
}
}
def mergedJavadocSubprojects = [
":jme3-android",
":jme3-core",
":jme3-desktop",
":jme3-effects",
":jme3-ios",
":jme3-jbullet",
":jme3-jogg",
":jme3-lwjgl3",
":jme3-networking",
":jme3-plugins",
":jme3-terrain",
":nge-core",
":nge-app",
":nge-auth",
":nge-networking",
":nge-gui",
":nge-ads"
]
def ragDocProjects = [
":jme3-core",
":jme3-effects",
":jme3-networking",
":jme3-plugins",
":nge-core",
":nge-app",
":nge-auth",
":nge-networking",
":nge-gui",
":nge-ads"
]
// Set the license for IDEs that understand this
ext.license = file("$rootDir/source-file-header-template.txt")
apply plugin: 'base'
apply plugin: 'com.github.spotbugs'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'org.jetbrains.kotlin.jvm'
// This is applied to all sub projects
subprojects {
if(!project.name.equals('jme3-android-examples')) {
apply from: rootProject.file('common.gradle')
} else {
apply from: rootProject.file('common-android-app.gradle')
}
if (!project.name.endsWith("-native") && enableSpotBugs != "false" ) {
apply plugin: 'com.github.spotbugs'
// Currently we only warn about issues and try to fix them as we go, but those aren't mission critical.
spotbugs {
ignoreFailures = true
toolVersion = libs.versions.spotbugs.get()
}
tasks.withType(com.github.spotbugs.snom.SpotBugsTask ) {
reports {
html.required = !project.hasProperty("xml-reports")
xml.required = project.hasProperty("xml-reports")
}
}
}
if (ragDocProjects.contains(path)) {
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'org.jetbrains.kotlin.jvm'
dokkaGfm {
moduleName.set(project.name)
moduleVersion.set(project.version.toString())
}
}
if (name.startsWith("nge-")) {
apply plugin: 'com.diffplug.spotless'
spotless {
enforceCheck = false
java {
importOrder()
removeUnusedImports()
cleanthat()
prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0'])
.config(['parser': 'java', 'tabWidth': 4, 'printWidth': 128])
formatAnnotations()
}
}
}
// Prefer: <module>.LICENSE (e.g. nge-gui.LICENSE)
// Fallback: <prefix>.LICENSE where prefix is before first '-' (e.g. nge.LICENSE)
def moduleLicenseFile = file("${rootProject.rootDir}/${project.name}.LICENSE")
def prefix = (project.name.contains('-') ? project.name.substring(0, project.name.indexOf('-')) : project.name)
def prefixLicenseFile = file("${rootProject.rootDir}/${prefix}.LICENSE")
File chosenLicenseFile = moduleLicenseFile.exists()
? moduleLicenseFile
: (prefixLicenseFile.exists() ? prefixLicenseFile : null)
if (chosenLicenseFile != null) {
project.tasks.register('addLicenseHeaders') {
description = 'Adds or updates license headers in Java files'
group = 'formatting'
def srcFiles = project.fileTree(dir: 'src', include: '**/java/**/*.java')
def licenseText = chosenLicenseFile.text
licenseText = licenseText.readLines().collect { " * " + it }.join("\n")
licenseText = "/**\n" + licenseText + "\n */"
doLast {
def licenseHeader = licenseText
// Only strip the legacy NGE header block.
// Then only add the license if the file has no block comment containing "Copyright".
def afterFirstComma = { String s ->
if (s == null) {
return null
}
def idx = s.indexOf(',')
if (idx < 0 || idx == s.length() - 1) {
return null
}
return s.substring(idx + 1).trim()
}
def licenseFirstLine = chosenLicenseFile.readLines('UTF-8')?.find { it != null } ?: ""
def legacyHeaderMarker = afterFirstComma(licenseFirstLine) ?: licenseFirstLine.trim()
def firstNonEmptyTextInBlock = { String block ->
def body = block
.replaceFirst(/(?s)\A\/\*{1,2}/, "")
.replaceFirst(/(?s)\*\/\s*\z/, "")
for (String line : body.readLines()) {
def t = line.trim()
if (t.startsWith("*")) {
t = t.substring(1).trim()
}
if (!t.isEmpty()) {
return t
}
}
return null
}
def shouldStripLegacyHeaderBlock = { String block ->
def firstLine = firstNonEmptyTextInBlock(block)
if (firstLine == null) {
return false
}
def markerInBlock = afterFirstComma(firstLine) ?: firstLine.trim()
return firstLine.trim().startsWith("Copyright") && markerInBlock == legacyHeaderMarker
}
def stripLeadingLegacyHeaderBlocks = { String s ->
s = s.replaceFirst(/^\uFEFF/, "")
while (true) {
def m = (s =~ /(?s)\A(\s*)(\/\*{1,2}.*?\*\/)(\s*)/)
if (!m.find()) {
break
}
def block = m.group(2)
if (shouldStripLegacyHeaderBlock(block)) {
s = s.substring(m.end())
continue
}
break
}
return s
}
def hasAnyCopyrightBlockComment = { String s ->
def m = (s =~ /(?s)\/\*{1,2}.*?\*\//)
while (m.find()) {
def block = m.group()
if (block != null && block.contains("Copyright")) {
return true
}
}
return false
}
srcFiles.each { f ->
def original = f.getText('UTF-8')
def stripped = stripLeadingLegacyHeaderBlocks(original)
// Rule 2: if any block comment contains "Copyright", do not add the license.
// Still persist the legacy-header removal if it changed the file.
def updated
if (hasAnyCopyrightBlockComment(stripped)) {
updated = stripped
} else {
def packageMatcher = stripped =~ /(?m)^package\s+[\w.]+;/
if (packageMatcher.find()) {
def position = packageMatcher.start()
updated =
stripped.substring(0, position) +
licenseHeader +
"\n\n" +
stripped.substring(position)
} else {
updated = licenseHeader + "\n\n" + stripped
}
}
if (updated != original) {
logger.info("Rewriting license header(s) in: ${f.path}")
f.write(updated, 'UTF-8')
} else {
logger.debug("License header already up-to-date in: ${f.path}")
}
}
}
}
} else {
logger.info("No license file found for ${project.path} (tried ${project.name}.LICENSE and ${prefix}.LICENSE). Skipping addLicenseHeaders task.")
}
}
tasks.register('run') {
dependsOn ':jme3-examples:run'
description = 'Run the jME3 examples'
}
defaultTasks 'run'
task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
title = 'Nostr Game Engine'
destinationDir = mkdir("dist/javadoc")
options.encoding = 'UTF-8'
// Allows Javadoc to be generated on Java 8 despite doclint errors.
if (JavaVersion.current().isJava8Compatible()) {
options.addStringOption('Xdoclint:none', '-quiet')
}
options.overview = file("javadocfiles/javadoc-overview.html")
options.stylesheetFile = file("javadocfiles/javadoc-style.css")
source = mergedJavadocSubprojects.collect { project(it).sourceSets.main.allJava }
classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
}
def cleanMergedJavadoc = tasks.register('cleanMergedJavadoc', Delete) {
delete file('dist/javadoc')
}
tasks.named('clean') {
dependsOn cleanMergedJavadoc
}
ext {
ndkCommandPath = ""
ndkExists = false
}
apply from: 'gradle/jacoco.gradle'
task configureAndroidNDK {
def ndkBuildFile = "ndk-build"
// if windows, use ndk-build.cmd instead
if (System.properties['os.name'].toLowerCase().contains('windows')) {
ndkBuildFile = "ndk-build.cmd"
}
// ndkPath is defined in the root project gradle.properties file
String ndkBuildPath = null;
//Use the environment variable for the NDK location if defined
if (System.env.ANDROID_NDK != null) {
ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
} else if (System.env.ANDROID_SDK != null) {
ndkBuildPath = System.env.ANDROID_SDK + File.separator + "ndk" + File.separator + ndkBuildFile
} else if (System.env.ANDROID_HOME != null) {
def ndkBase = new File(System.env.ANDROID_HOME + File.separator + "Sdk" + File.separator + "ndk");
if (ndkBase.exists()) {
def ndkDirs = ndkBase.listFiles()?.findAll { it.isDirectory() } ?: []
if (!ndkDirs.isEmpty()) {
def latest = ndkDirs
.collect { [dir: it, ver: it.name.tokenize('._-').collect { token -> token.isInteger() ? token.toInteger() : token }] }
.max { it.ver }?.dir
if (latest) {
ndkBuildPath = new File(latest, ndkBuildFile).absolutePath
}
}
}
}
if (ndkBuildPath == null){
ndkBuildPath = ndkPath + File.separator + ndkBuildFile
}
println "Using NDK path: " + ndkBuildPath
if (new File(ndkBuildPath).exists()) {
println "Found NDK build tool: " + ndkBuildPath
ndkExists = true
ndkCommandPath = ndkBuildPath
}
}
gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
File nativesSnapshotPropF = file('natives-snapshot.properties')
if (nativesSnapshotPropF.exists()) {
def readNativesConfig = {
Properties nativesSnapshotProp = new Properties()
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot")
if (!nativesSnapshot) {
throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}")
}
[
snapshot: nativesSnapshot,
url: PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot),
zipFile: layout.buildDirectory.file("${nativesSnapshot}-natives.zip"),
nativeDir: layout.buildDirectory.dir("native"),
]
}
def nativesZipFile = providers.provider { readNativesConfig().zipFile.get().asFile }
def nativesPath = layout.buildDirectory.dir("native")
def getNativesZipFile = tasks.register('getNativesZipFile') {
outputs.file(nativesZipFile)
doFirst {
def nativesConfig = readNativesConfig()
File target = nativesConfig.zipFile.get().asFile
println("Use natives snapshot: ${nativesConfig.url}")
println("Download natives from ${nativesConfig.url} to ${target}")
target.getParentFile().mkdirs()
ant.get(src: nativesConfig.url, dest: target)
}
}
def extractPrebuiltNatives = tasks.register('extractPrebuiltNatives', Sync) {
dependsOn(getNativesZipFile)
into(nativesPath)
from({
zipTree(readNativesConfig().zipFile.get().asFile)
}) {
eachFile { details ->
def segments = details.relativePath.segments
if (segments.length <= 1) {
details.exclude()
} else {
details.relativePath = new RelativePath(details.isDirectory(), segments[1..-1] as String[])
}
}
includeEmptyDirs = false
}
}
tasks.named('assemble') {
dependsOn extractPrebuiltNatives
}
}
}
dokkaGfmMultiModule {
outputDirectory.set(file("build/dokka"))
}
tasks.register('refreshCatalog') {
group = 'build setup'
description = 'Downloads the central NostrGameEngine Gradle version catalog.'
def catalogUrl = providers.gradleProperty('centralCatalogUrl')
.orElse('https://raw.githubusercontent.com/NostrGameEngine/libs.catalog/main/libs.versions.toml')
def outputFile = layout.projectDirectory.file('gradle/libs.versions.toml')
outputs.file(outputFile)
doLast {
def target = outputFile.asFile
target.parentFile.mkdirs()
target.text = new URI(catalogUrl.get()).toURL().getText('UTF-8')
println "Refreshed ${target}"
}
}