From ff8de6a830548f6f9e02c11d7ba649a9eefd666b Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Sun, 21 Feb 2021 11:47:47 +0300 Subject: [PATCH] Print notarization status (#406) * Always write external tool output logs to files Previous implementation always passed an empty string to `processStdout`, when verbose mode was used. * Print notarization status in non-verbose mode too --- .../application/internal/MultiOutputStream.kt | 40 +++++++++++++++++++ .../AbstractCheckNotarizationStatusTask.kt | 7 +++- .../tasks/AbstractComposeDesktopTask.kt | 18 +++++---- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/MultiOutputStream.kt diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/MultiOutputStream.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/MultiOutputStream.kt new file mode 100644 index 0000000000..e0ed8a647f --- /dev/null +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/MultiOutputStream.kt @@ -0,0 +1,40 @@ +package org.jetbrains.compose.desktop.application.internal + +import java.io.FilterOutputStream +import java.io.OutputStream + +internal class MultiOutputStream( + mainStream: OutputStream, + private val secondaryStream: OutputStream +) : FilterOutputStream(mainStream) { + override fun write(b: ByteArray, off: Int, len: Int) { + super.write(b, off, len) + secondaryStream.write(b, off, len) + } + + override fun write(b: ByteArray) { + super.write(b) + secondaryStream.write(b) + } + + override fun write(b: Int) { + super.write(b) + secondaryStream.write(b) + } + + override fun flush() { + super.flush() + secondaryStream.flush() + } + + override fun close() { + try { + super.close() + } finally { + secondaryStream.close() + } + } +} + +internal fun OutputStream.alsoOutputTo(secondaryStream: OutputStream): OutputStream = + MultiOutputStream(this, secondaryStream) \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNotarizationStatusTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNotarizationStatusTask.kt index 8cbffdcd5a..489859e02f 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNotarizationStatusTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNotarizationStatusTask.kt @@ -43,7 +43,12 @@ abstract class AbstractCheckNotarizationStatusTask : AbstractNotarizationTask() "--notarization-info", request.uuid, "--username", notarization.appleID, "--password", notarization.password - ) + ), + processStdout = { output -> + if (!verbose.get()) { + logger.quiet(output) + } + } ) } catch (e: Exception) { logger.error("Could not check notarization request '${request.uuid}'", e) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractComposeDesktopTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractComposeDesktopTask.kt index d19a12ea6b..3f0fc4d959 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractComposeDesktopTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractComposeDesktopTask.kt @@ -12,12 +12,12 @@ import org.gradle.api.tasks.LocalState import org.gradle.process.ExecOperations import org.gradle.process.ExecResult import org.jetbrains.compose.desktop.application.internal.ComposeProperties +import org.jetbrains.compose.desktop.application.internal.alsoOutputTo import org.jetbrains.compose.desktop.application.internal.ioFile import org.jetbrains.compose.desktop.application.internal.notNullProperty import java.io.File import java.time.LocalDateTime import java.time.format.DateTimeFormatter -import java.util.function.Consumer import javax.inject.Inject abstract class AbstractComposeDesktopTask : DefaultTask() { @@ -55,11 +55,12 @@ abstract class AbstractComposeDesktopTask : DefaultTask() { logsDir.mkdirs() val toolName = tool.nameWithoutExtension + val logToConsole = verbose.get() val outFile = logsDir.resolve("${toolName}-${currentTimeStamp()}-out.txt") - val errFile = logsDir.resolve("${toolName}-${currentTimeStamp()}-out.txt") + val errFile = logsDir.resolve("${toolName}-${currentTimeStamp()}-err.txt") - val result = outFile.outputStream().buffered().use { outStream -> - errFile.outputStream().buffered().use { errStream -> + val result = outFile.outputStream().buffered().use { outFileStream -> + errFile.outputStream().buffered().use { errFileStream -> execOperations.exec { spec -> spec.executable = tool.absolutePath spec.args(*args.toTypedArray()) @@ -68,9 +69,12 @@ abstract class AbstractComposeDesktopTask : DefaultTask() { // check exit value later spec.isIgnoreExitValue = true - if (!verbose.get()) { - spec.standardOutput = outStream - spec.errorOutput = errStream + if (logToConsole) { + spec.standardOutput = spec.standardOutput.alsoOutputTo(outFileStream) + spec.errorOutput = spec.errorOutput.alsoOutputTo(errFileStream) + } else { + spec.standardOutput = outFileStream + spec.errorOutput = errFileStream } } }