From 171cd1b13f32e771cfb1a3f6c5f29072ab31cdc9 Mon Sep 17 00:00:00 2001 From: Ellet Date: Wed, 3 Jul 2024 10:47:31 +0300 Subject: [PATCH] chore: only suppress output of executing proguard task if '-i' is not set --- .../src/main/kotlin/BuildMinimizedJarTask.kt | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt index 393e53e..2642553 100644 --- a/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt +++ b/buildSrc/src/main/kotlin/BuildMinimizedJarTask.kt @@ -1,6 +1,7 @@ import org.gradle.api.DefaultTask import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty +import org.gradle.api.logging.LogLevel import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile @@ -138,26 +139,17 @@ open class BuildMinimizedJarTask : DefaultTask() { generatedProguardConfigurationFiles.forEach { configuration(it) } } + // Execute the Proguard task + // A workaround for executing ProGuard without getting the notes by disabling the logging + // when the `-i` or `--info` is not set - val oldStandardOut = System.out - val oldStandardErr = System.err - val noOpOutputStream = - object : OutputStream() { - override fun write(b: Int) { - // Do nothing - } + if (project.gradle.startParameter.logLevel != LogLevel.INFO) { + suppressOutputAndExecute { + proguardTask.actions.forEach { it.execute(proguardTask) } } - - try { - System.setOut(PrintStream(noOpOutputStream)) - System.setErr(PrintStream(noOpOutputStream)) - - // Execute the Proguard task + } else { proguardTask.actions.forEach { it.execute(proguardTask) } - } finally { - System.setOut(oldStandardOut) - System.setErr(oldStandardErr) } logResultMessage() @@ -177,4 +169,25 @@ open class BuildMinimizedJarTask : DefaultTask() { " The size has been reduced \uD83D\uDCC9 by $formattedPercentageDifference. Location: ${minimized.path}", ) } + + fun suppressOutputAndExecute(action: () -> Unit) { + val oldStandardOut = System.out + val oldStandardErr = System.err + val noOpOutputStream = + object : OutputStream() { + override fun write(b: Int) { + // Do nothing + } + } + + try { + System.setOut(PrintStream(noOpOutputStream)) + System.setErr(PrintStream(noOpOutputStream)) + + action() + } finally { + System.setOut(oldStandardOut) + System.setErr(oldStandardErr) + } + } }