Fix: Gradle scripts aren't compatible with Java 8. (#2706)

* Fix: Gradle scripts aren't compatible with Java 8.

* update

---------

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Burning_TNT 2024-01-30 21:39:16 +08:00 committed by GitHub
parent 4102029d6d
commit 017d688e32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -101,10 +101,7 @@ tasks.getByName<JavaCompile>("compileJava") {
doLast {
Gson().also { gsonInstance ->
Files.newBufferedReader(
rootProject.rootDir.toPath().resolve("data-json/dynamic-remote-resources-raw.json"),
Charsets.UTF_8
).use { br ->
rootProject.rootDir.resolve("data-json/dynamic-remote-resources-raw.json").bufferedReader().use { br ->
(gsonInstance.fromJson(br, JsonElement::class.java) as JsonObject)
}.also { data ->
data.asMap().forEach { (namespace, namespaceData) ->
@ -117,7 +114,7 @@ tasks.getByName<JavaCompile>("compileJava") {
val currentSha1 = digest(
"SHA-1",
Files.readAllBytes(rootProject.rootDir.toPath().resolve(localPath))
rootProject.rootDir.resolve(localPath).readBytes()
).joinToString(separator = "") { "%02x".format(it) }
if (!sha1.equals(currentSha1, ignoreCase = true)) {
@ -127,20 +124,20 @@ tasks.getByName<JavaCompile>("compileJava") {
}
}
rootProject.rootDir.toPath().resolve("data-json/dynamic-remote-resources.json").also { zippedPath ->
rootProject.rootDir.resolve("data-json/dynamic-remote-resources.json").also { zippedPath ->
gsonInstance.toJson(data).also { expectedData ->
if (Files.exists(zippedPath)) {
Files.readString(zippedPath, Charsets.UTF_8).also { rawData ->
if (!rawData.equals(expectedData)) {
if (zippedPath.exists()) {
zippedPath.readText().also { rawData ->
if (rawData != expectedData) {
if (System.getenv("GITHUB_SHA") == null) {
Files.writeString(zippedPath, expectedData, Charsets.UTF_8)
zippedPath.writeText(expectedData)
} else {
throw IllegalStateException("Mismatched zipped dynamic-remote-resources json file!")
}
}
}
} else {
Files.writeString(zippedPath, expectedData, Charsets.UTF_8)
zippedPath.writeText(expectedData)
}
}
}