@@ -5,27 +5,31 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.NewestFo
55import io.github.typesafegithub.workflows.actionbindinggenerator.generation.ActionBinding
66import io.github.typesafegithub.workflows.actionbindinggenerator.generation.ClientType
77import io.github.typesafegithub.workflows.actionbindinggenerator.generation.generateBinding
8+ import org.jetbrains.kotlin.cli.common.ExitCode
89import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
910import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
1011import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
1112import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
1213import org.jetbrains.kotlin.config.Services
13- import java.io.OutputStream
14+ import java.io.ByteArrayOutputStream
15+ import java.io.PrintStream
1416import java.nio.file.Path
1517import kotlin.io.path.Path
1618import kotlin.io.path.createParentDirectories
1719import kotlin.io.path.createTempDirectory
1820import kotlin.io.path.div
1921import kotlin.io.path.writeText
2022
21- fun OutputStream. buildJar (
23+ fun buildJar (
2224 owner : String ,
2325 name : String ,
2426 version : String ,
25- ) {
27+ ): ByteArray {
2628 val binding = generateBinding(owner = owner, name = name, version = version)
2729 val pathWithJarContents = binding.compileBinding()
28- return this .createZipFile(pathWithJarContents)
30+ val byteArrayOutputStream = ByteArrayOutputStream ()
31+ byteArrayOutputStream.createZipFile(pathWithJarContents)
32+ return byteArrayOutputStream.toByteArray()
2933}
3034
3135private fun generateBinding (
@@ -62,16 +66,21 @@ private fun ActionBinding.compileBinding(): Path {
6266 noReflect = true
6367 includeRuntime = false
6468 }
69+ val compilerMessagesOutputStream = ByteArrayOutputStream ()
6570 val compilerMessageCollector =
6671 PrintingMessageCollector (
67- System . out ,
72+ PrintStream (compilerMessagesOutputStream) ,
6873 MessageRenderer .GRADLE_STYLE ,
6974 false ,
7075 )
71- K2JVMCompiler ().exec(
72- messageCollector = compilerMessageCollector,
73- services = Services .EMPTY ,
74- arguments = args,
75- )
76+ val exitCode =
77+ K2JVMCompiler ().exec(
78+ messageCollector = compilerMessageCollector,
79+ services = Services .EMPTY ,
80+ arguments = args,
81+ )
82+ require(exitCode == ExitCode .OK ) {
83+ " Binding compilation failed! Compiler messages: $compilerMessagesOutputStream "
84+ }
7685 return compilationOutput
7786}
0 commit comments