From ca420618e94be71bb11793a2383b011acc01323d Mon Sep 17 00:00:00 2001 From: Ellet Date: Thu, 4 Jul 2024 16:33:45 +0300 Subject: [PATCH 01/12] chore: remove duplicated code in function Path.createFileWithParentDirectoriesOrTerminate() in file FilePathUtils.kt --- sync-script/src/main/kotlin/utils/FilePathUtils.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/sync-script/src/main/kotlin/utils/FilePathUtils.kt b/sync-script/src/main/kotlin/utils/FilePathUtils.kt index f7872a0..b11cd5a 100644 --- a/sync-script/src/main/kotlin/utils/FilePathUtils.kt +++ b/sync-script/src/main/kotlin/utils/FilePathUtils.kt @@ -70,16 +70,6 @@ fun Path.createParentDirectoriesIfDoesNotExist() { fun Path.createFileWithParentDirectoriesOrTerminate() { createParentDirectoriesIfDoesNotExist() - if (!parent.exists()) { - try { - createParentDirectories() - } catch (e: Exception) { - showErrorMessageAndTerminate( - title = "File Creation Error ⚠\uFE0F", - message = "❌ Failed to create the directory '${this.name}': $e", - ) - } - } try { createFile() } catch (e: Exception) { From bef6a0c068d5de50c9ec110142f5c2bbc965d43a Mon Sep 17 00:00:00 2001 From: Ellet Date: Thu, 4 Jul 2024 16:39:53 +0300 Subject: [PATCH 02/12] chore: add Path.createFileOrTerminate() in FilePathUtils.kt --- sync-script/src/main/kotlin/utils/FilePathUtils.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sync-script/src/main/kotlin/utils/FilePathUtils.kt b/sync-script/src/main/kotlin/utils/FilePathUtils.kt index b11cd5a..7af21d2 100644 --- a/sync-script/src/main/kotlin/utils/FilePathUtils.kt +++ b/sync-script/src/main/kotlin/utils/FilePathUtils.kt @@ -70,6 +70,10 @@ fun Path.createParentDirectoriesIfDoesNotExist() { fun Path.createFileWithParentDirectoriesOrTerminate() { createParentDirectoriesIfDoesNotExist() + createFileOrTerminate() +} + +fun Path.createFileOrTerminate() { try { createFile() } catch (e: Exception) { From 99332bd8fa4553ee0c42547769eddfeb1df5fb87 Mon Sep 17 00:00:00 2001 From: Ellet Date: Thu, 4 Jul 2024 17:09:05 +0300 Subject: [PATCH 03/12] fix(proguard): the BuildMinimizedJarTask will suppress the output if '-i' is not passed --- buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt index 762de32..de36cd8 100644 --- a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt +++ b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt @@ -152,12 +152,12 @@ open class BuildMinimizedJarTask : DefaultTask() { // A workaround for executing ProGuard without getting the notes by disabling the logging // when the `-i` or `--info` is not set - if (project.gradle.startParameter.logLevel != LogLevel.INFO) { + if (project.gradle.startParameter.logLevel == LogLevel.INFO) { + proguardTask.actions.forEach { it.execute(proguardTask) } + } else { suppressOutputAndExecute { proguardTask.actions.forEach { it.execute(proguardTask) } } - } else { - proguardTask.actions.forEach { it.execute(proguardTask) } } logResultMessage(isObfuscatedEnabled = isObfuscatedEnabled) From 87c8eb3f962facbeb32497469443fd3eba512ec6 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 04:45:44 +0300 Subject: [PATCH 04/12] feat: initial support for syncing server list --- gradle/libs.versions.toml | 2 + sync-script/build.gradle.kts | 2 + sync-script/src/main/kotlin/Main.kt | 2 + .../kotlin/syncService/ServersSyncService.kt | 73 ++++++++++++++++++- 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6493beb..ef34738 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ kolinx-coroutines = "1.9.0-RC" okhttp = "4.12.0" flatlaf = "3.4.1" ktoml = "0.5.2" +knbt = "0.11.5" # Plugins shadow-jar = "8.1.1" @@ -27,6 +28,7 @@ okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } flatlaf-core = { module = "com.formdev:flatlaf", version.ref = "flatlaf" } flatlaf-extras = { module = "com.formdev:flatlaf-extras", version.ref = "flatlaf" } ktoml-core = { module = "com.akuleshov7:ktoml-core", version.ref = "ktoml" } +knbt = { module = "net.benwoodworth.knbt:knbt", version.ref = "knbt" } # For tests kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } diff --git a/sync-script/build.gradle.kts b/sync-script/build.gradle.kts index 56286d2..14c33a0 100644 --- a/sync-script/build.gradle.kts +++ b/sync-script/build.gradle.kts @@ -16,6 +16,8 @@ dependencies { implementation(libs.okhttp) implementation(libs.flatlaf.core) implementation(libs.flatlaf.extras) + // TODO: Explicitly implement Okio will solve Proguard issue with Knbt to use 3.9.0 instead of 3.6.0 + implementation(libs.knbt) testImplementation(libs.kotlin.test) } diff --git a/sync-script/src/main/kotlin/Main.kt b/sync-script/src/main/kotlin/Main.kt index dbdad37..acea32f 100644 --- a/sync-script/src/main/kotlin/Main.kt +++ b/sync-script/src/main/kotlin/Main.kt @@ -22,6 +22,7 @@ import syncInfo.models.SyncInfo import syncInfo.models.instance import syncService.ModsSyncService import syncService.ResourcePacksSyncService +import syncService.ServersSyncService import syncService.SyncService import utils.ExecutionTimer import utils.HttpService @@ -300,6 +301,7 @@ suspend fun performSyncServices(scriptConfig: ScriptConfig) { add(ModsSyncService()) if (scriptConfig.environment.isClient()) { add(ResourcePacksSyncService()) + add(ServersSyncService()) } } diff --git a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt index 90cd71c..f08e1f3 100644 --- a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt @@ -1,11 +1,82 @@ package syncService import constants.SyncScriptDotMinecraftFiles +import net.benwoodworth.knbt.Nbt +import net.benwoodworth.knbt.NbtCompound +import net.benwoodworth.knbt.NbtCompression +import net.benwoodworth.knbt.NbtList +import net.benwoodworth.knbt.NbtTag +import net.benwoodworth.knbt.NbtVariant +import net.benwoodworth.knbt.add +import net.benwoodworth.knbt.buildNbtCompound +import net.benwoodworth.knbt.buildNbtList +import net.benwoodworth.knbt.decodeFromStream +import net.benwoodworth.knbt.encodeToStream +import net.benwoodworth.knbt.nbtCompound +import net.benwoodworth.knbt.put +import syncInfo.models.SyncInfo +import syncInfo.models.instance +import kotlin.io.path.exists +import kotlin.io.path.inputStream +import kotlin.io.path.outputStream class ServersSyncService : SyncService { private val serversFilePath = SyncScriptDotMinecraftFiles.ServersDat.path + private val serversSyncService = SyncInfo.instance.serverSyncInfo + + companion object { + const val SERVER_NBT_MAIN_COMPOUND_KEY = "" + } override suspend fun syncData() { - TODO("Not yet implemented") + val isServersFileExist = serversFilePath.exists() + val nbt = + Nbt { + variant = NbtVariant.Java + compression = NbtCompression.None + } + + val currentRootCompound = + if (isServersFileExist) { + serversFilePath + .inputStream() + .use { inputStream -> + // TODO: If the file exist though empty or invalid this will cause exception + // improve error handling + nbt.decodeFromStream(inputStream) + } as NbtCompound + } else { + NbtCompound(mapOf(SERVER_NBT_MAIN_COMPOUND_KEY to NbtCompound(emptyMap()))) + } + + val newServerListCompound: NbtList = + buildNbtList { + serversSyncService.servers.map { + val serverCompound = + buildNbtCompound { + put("ip", it.address) + put("name", it.name) + } + add(serverCompound) + } + } + + val newRootCompound = + currentRootCompound.let { + val mutableRootMap = it.toMutableMap() + + val mutableMainMap = it[SERVER_NBT_MAIN_COMPOUND_KEY]?.nbtCompound?.toMutableMap() ?: mutableMapOf() + mutableMainMap["servers"] = newServerListCompound + + mutableRootMap[SERVER_NBT_MAIN_COMPOUND_KEY] = NbtCompound(mutableMainMap) + + NbtCompound(mutableRootMap) + } + + serversFilePath + .outputStream() + .use { outputStream -> + nbt.encodeToStream(newRootCompound, outputStream) + } } } From 818619228930f6b5ec4c851816348ae1afe64fd4 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 04:51:12 +0300 Subject: [PATCH 05/12] fix: fix proguard warning related to okio --- gradle/libs.versions.toml | 2 ++ sync-script/build.gradle.kts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ef34738..22128ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,7 @@ kotlin = "2.0.0" kotlinx-serialization = "1.7.0" kolinx-coroutines = "1.9.0-RC" okhttp = "4.12.0" +okio = "3.9.0" flatlaf = "3.4.1" ktoml = "0.5.2" knbt = "0.11.5" @@ -25,6 +26,7 @@ java = "11" kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kolinx-coroutines" } okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } +okio = { module = "com.squareup.okio:okio", version.ref = "okio" } flatlaf-core = { module = "com.formdev:flatlaf", version.ref = "flatlaf" } flatlaf-extras = { module = "com.formdev:flatlaf-extras", version.ref = "flatlaf" } ktoml-core = { module = "com.akuleshov7:ktoml-core", version.ref = "ktoml" } diff --git a/sync-script/build.gradle.kts b/sync-script/build.gradle.kts index 14c33a0..711085f 100644 --- a/sync-script/build.gradle.kts +++ b/sync-script/build.gradle.kts @@ -14,9 +14,10 @@ dependencies { implementation(libs.kotlinx.serialization.json) implementation(libs.kotlinx.coroutines.core) implementation(libs.okhttp) + // Explicitly including Okio to use the latest version to solve some Proguard warnings + implementation(libs.okio) implementation(libs.flatlaf.core) implementation(libs.flatlaf.extras) - // TODO: Explicitly implement Okio will solve Proguard issue with Knbt to use 3.9.0 instead of 3.6.0 implementation(libs.knbt) testImplementation(libs.kotlin.test) From ceec0828a6a59d5788c8644b994b57f0c25ddea5 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 04:52:13 +0300 Subject: [PATCH 06/12] chore(admin): use java.io.IOException for IOException in PrismLauncherDataSource --- .../kotlin/launchers/prismLauncher/PrismLauncherDataSource.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/main/kotlin/launchers/prismLauncher/PrismLauncherDataSource.kt b/admin/src/main/kotlin/launchers/prismLauncher/PrismLauncherDataSource.kt index 34d492b..0984279 100644 --- a/admin/src/main/kotlin/launchers/prismLauncher/PrismLauncherDataSource.kt +++ b/admin/src/main/kotlin/launchers/prismLauncher/PrismLauncherDataSource.kt @@ -5,10 +5,10 @@ import constants.DotMinecraftFileNames import curseForgeDataSource import launchers.Instance import launchers.LauncherDataSource -import okio.IOException import syncInfo.models.mod.Mod import utils.SystemFileProvider import utils.listFilteredPaths +import java.io.IOException import java.nio.file.Path import kotlin.io.path.absolutePathString import kotlin.io.path.exists From 78c340685e12465bef01e6752108aa9bdf8c476c Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 05:31:05 +0300 Subject: [PATCH 07/12] chore(common): add Path.isFileEmpty() in SharedFilePathUtils.kt --- common/src/main/kotlin/utils/SharedFilePathUtils.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/src/main/kotlin/utils/SharedFilePathUtils.kt b/common/src/main/kotlin/utils/SharedFilePathUtils.kt index 7f0fca2..a206561 100644 --- a/common/src/main/kotlin/utils/SharedFilePathUtils.kt +++ b/common/src/main/kotlin/utils/SharedFilePathUtils.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.withContext import java.nio.file.FileSystemException import java.nio.file.Files import java.nio.file.Path +import kotlin.io.path.fileSize import kotlin.io.path.name import kotlin.streams.toList @@ -31,3 +32,5 @@ suspend fun Path.listFilteredPaths(filter: (path: Path) -> Boolean): Result Date: Fri, 5 Jul 2024 05:31:49 +0300 Subject: [PATCH 08/12] chore: remove println() in finalize() function --- sync-script/src/main/kotlin/Main.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/sync-script/src/main/kotlin/Main.kt b/sync-script/src/main/kotlin/Main.kt index acea32f..fed70ce 100644 --- a/sync-script/src/main/kotlin/Main.kt +++ b/sync-script/src/main/kotlin/Main.kt @@ -313,8 +313,6 @@ fun finalize(applicationExecutionTimer: ExecutionTimer) { LoadingIndicatorDialog.instance?.isVisible = false - println() - // The temporary folder usually contains the downloaded files which will be moved once finished // after finish syncing the contents successfully, we don't need it anymore. handleTemporaryDirectory(isStart = false) From 45abc4f7e04b39403ec5e04765b0e3f8daf86554 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 05:46:58 +0300 Subject: [PATCH 09/12] feat: improve error handling and messages in ServersSyncService --- .../kotlin/syncService/ServersSyncService.kt | 111 ++++++++++++++---- sync-script/src/main/kotlin/utils/Utils.kt | 3 + 2 files changed, 93 insertions(+), 21 deletions(-) diff --git a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt index f08e1f3..75c2575 100644 --- a/sync-script/src/main/kotlin/syncService/ServersSyncService.kt +++ b/sync-script/src/main/kotlin/syncService/ServersSyncService.kt @@ -16,37 +16,61 @@ import net.benwoodworth.knbt.nbtCompound import net.benwoodworth.knbt.put import syncInfo.models.SyncInfo import syncInfo.models.instance +import utils.ExecutionTimer +import utils.buildHtml +import utils.isFileEmpty +import utils.showErrorMessageAndTerminate +import java.io.EOFException import kotlin.io.path.exists import kotlin.io.path.inputStream +import kotlin.io.path.isRegularFile +import kotlin.io.path.name import kotlin.io.path.outputStream +import kotlin.io.path.pathString +import kotlin.system.exitProcess class ServersSyncService : SyncService { - private val serversFilePath = SyncScriptDotMinecraftFiles.ServersDat.path + private val serversDatFilePath = SyncScriptDotMinecraftFiles.ServersDat.path private val serversSyncService = SyncInfo.instance.serverSyncInfo companion object { const val SERVER_NBT_MAIN_COMPOUND_KEY = "" } + private val nbt = + Nbt { + variant = NbtVariant.Java + compression = NbtCompression.None + } + override suspend fun syncData() { - val isServersFileExist = serversFilePath.exists() - val nbt = - Nbt { - variant = NbtVariant.Java - compression = NbtCompression.None - } + val executionTimer = ExecutionTimer() + executionTimer.setStartTime() + + println("\n\uD83D\uDD04 Syncing server list...") val currentRootCompound = - if (isServersFileExist) { - serversFilePath - .inputStream() - .use { inputStream -> - // TODO: If the file exist though empty or invalid this will cause exception - // improve error handling - nbt.decodeFromStream(inputStream) - } as NbtCompound - } else { - NbtCompound(mapOf(SERVER_NBT_MAIN_COMPOUND_KEY to NbtCompound(emptyMap()))) + loadServersDatFile().getOrElse { + showErrorMessageAndTerminate( + title = "📁 File Loading Error", + message = + buildHtml { + text("⚠ Unable to read the server list from the file '${serversDatFilePath.pathString}': ") + newLine() + text("$it") + newLines(2) + if (it is EOFException) { + text("This issue might occur if the file is corrupt or incomplete.") + newLine() + text("As a potential workaround, consider deleting the file '${serversDatFilePath.pathString}'.") + } else { + text("Deleting the file '${serversDatFilePath.pathString}' could resolve the issue.") + } + newLine() + boldText("Note: Deleting this file will reset the server list in the game.") + }.buildBodyAsText(), + ) + return } val newServerListCompound: NbtList = @@ -73,10 +97,55 @@ class ServersSyncService : SyncService { NbtCompound(mutableRootMap) } - serversFilePath - .outputStream() - .use { outputStream -> - nbt.encodeToStream(newRootCompound, outputStream) + updateServersDatFile(newRootCompound = newRootCompound).getOrElse { + showErrorMessageAndTerminate( + title = "🚨 File Update Error", + message = "⚠ī¸ Unable to update the '${serversDatFilePath.name}' file: $it", + ) + return + } + + println("\uD83D\uDD52 Finished syncing the server list in ${executionTimer.getRunningUntilNowDuration().inWholeMilliseconds}ms.") + } + + private fun loadServersDatFile(): Result { + return try { + if (serversDatFilePath.exists()) { + if (!serversDatFilePath.isRegularFile()) { + showErrorMessageAndTerminate( + title = "❌ Invalid '${serversDatFilePath.name}' File", + message = + "\uD83D\uDEE0 '${serversDatFilePath.name}' must be a file \uD83D\uDCC2, a directory/folder was found instead.", + ) + // This will never reach due to the previous statement stopping the application + exitProcess(1) + } + if (serversDatFilePath.isFileEmpty()) { + println("ℹī¸ The file '${serversDatFilePath.name}' exists and is currently empty.") + return Result.success(createEmptyServerCompound()) + } + return Result.success( + serversDatFilePath + .inputStream() + .use { inputStream -> + nbt.decodeFromStream(inputStream) + } as NbtCompound, + ) } + Result.success(createEmptyServerCompound()) + } catch (e: Exception) { + Result.failure(e) + } } + + private fun updateServersDatFile(newRootCompound: NbtCompound): Result = + runCatching { + serversDatFilePath + .outputStream() + .use { outputStream -> + nbt.encodeToStream(newRootCompound, outputStream) + } + } + + private fun createEmptyServerCompound(): NbtCompound = NbtCompound(mapOf(SERVER_NBT_MAIN_COMPOUND_KEY to NbtCompound(emptyMap()))) } diff --git a/sync-script/src/main/kotlin/utils/Utils.kt b/sync-script/src/main/kotlin/utils/Utils.kt index 9cc98e2..0ad8a7b 100644 --- a/sync-script/src/main/kotlin/utils/Utils.kt +++ b/sync-script/src/main/kotlin/utils/Utils.kt @@ -19,6 +19,9 @@ import kotlin.system.exitProcess * we might call [showErrorMessageAndTerminate] when having error while loading the [ScriptConfig] * (for example), which is why we can't [ScriptConfig.getInstanceOrThrow] because we will get not initialized error * while showing an error message + * + * TODO: Some usages pass HTML message to [message], which will cause unreadable message in CLI mode, we need to + * either provide a different message parameter for the CLI or convert the HTML to plain text * */ fun showErrorMessageAndTerminate( title: String, From 0a34ae2853340e892235fe1d4615159e50aab87e Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 05:51:53 +0300 Subject: [PATCH 10/12] docs(readme): update server list syncing status in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9b8a63..5a0c945 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The script will sync the following: 1. 🛠ī¸ Mods (experimental) 2. 🎨 Resource packs (highly experimental) 3. ✨ Shader-packs (not implemented yet) -4. 🌐 Server List (in-game) (not implemented yet) +4. 🌐 In-Game Server List (Alpha): It is subject to potential changes or removal in future updates. 5. 🧩 Mods configurations (not implemented yet): These may be synced initially, since each player can have their own configurations. We have not yet found a solution, except by enforcing the same mod settings for all players. From 9f47796c8ccac50e4aa0756fdf840136916bd4e4 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 06:00:31 +0300 Subject: [PATCH 11/12] docs(readme): update the development status for syncing Mods, Resource Packs, Shader packs --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5a0c945..7117272 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ instance**. The script will sync the following: -1. 🛠ī¸ Mods (experimental) -2. 🎨 Resource packs (highly experimental) -3. ✨ Shader-packs (not implemented yet) +1. 🛠ī¸ Mods (Experimental): In the experimental phase and subject to changes. +2. 🎨 Resource Packs (Highly Experimental): In the highly experimental phase and subject to changes. +3. ✨ Shader Packs (Not Implemented Yet): This feature is not available yet. Future updates may implement it 4. 🌐 In-Game Server List (Alpha): It is subject to potential changes or removal in future updates. -5. 🧩 Mods configurations (not implemented yet): These may be synced initially, since each player can have their own +5. 🧩 Mods configurations (Not Implemented Yet): These may be synced initially, since each player can have their own configurations. We have not yet found a solution, except by enforcing the same mod settings for all players. -6. ⌨ī¸ Keybindings (not implemented yet): These may be synced initially since each player can have their own +6. ⌨ī¸ Keybindings (Not Implemented Yet): These may be synced initially since each player can have their own keybindings. We have not yet found a solution for this, except by enforcing the same keybindings for all players From 4226946b57961a469a4e9265580493bdb9f11f79 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 5 Jul 2024 06:07:58 +0300 Subject: [PATCH 12/12] chore: use when block in BuildMinimizedJarTask.execute() to check for project.gradle.startParameter.logLevel --- buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt index de36cd8..13a077f 100644 --- a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt +++ b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt @@ -152,11 +152,12 @@ open class BuildMinimizedJarTask : DefaultTask() { // A workaround for executing ProGuard without getting the notes by disabling the logging // when the `-i` or `--info` is not set - if (project.gradle.startParameter.logLevel == LogLevel.INFO) { - proguardTask.actions.forEach { it.execute(proguardTask) } - } else { - suppressOutputAndExecute { - proguardTask.actions.forEach { it.execute(proguardTask) } + when (project.gradle.startParameter.logLevel) { + LogLevel.INFO -> proguardTask.actions.forEach { it.execute(proguardTask) } + else -> { + suppressOutputAndExecute { + proguardTask.actions.forEach { it.execute(proguardTask) } + } } } @@ -173,7 +174,8 @@ open class BuildMinimizedJarTask : DefaultTask() { val formattedPercentageDifference = String.format("%.2f%%", kotlinMathAbs(percentageDifference)) logger.lifecycle( - "đŸ“Ļ The size of the Proguard ${if (isObfuscatedEnabled) "obfuscated" else "minimized"} JAR file (${minimizedJarFile.name}) is $minimizedFileSizeInMegabytes MB." + + "đŸ“Ļ The size of the Proguard ${if (isObfuscatedEnabled) "obfuscated" else "minimized"} JAR file " + + "(${minimizedJarFile.name}) is $minimizedFileSizeInMegabytes MB." + " The size has been reduced \uD83D\uDCC9 by $formattedPercentageDifference. Location: ${minimizedJarFile.path}", ) }