diff --git a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt index 4e2e74fa4a..0755f3c54e 100644 --- a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt +++ b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt @@ -112,10 +112,10 @@ private fun Route.artifact( val file = call.parameters["file"]!! if (file in bindingArtifacts) { when (val artifact = bindingArtifacts[file]) { - is TextArtifact -> call.respondText(text = artifact.data) + is TextArtifact -> call.respondText(text = artifact.data()) is JarArtifact -> call.respondBytes( - bytes = artifact.data, + bytes = artifact.data(), contentType = ContentType.parse("application/java-archive"), ) diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt index 064cd8886d..6cdab4122a 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt @@ -22,8 +22,8 @@ import kotlin.io.path.div import kotlin.io.path.writeText internal data class Jars( - val mainJar: ByteArray, - val sourcesJar: ByteArray, + val mainJar: () -> ByteArray, + val sourcesJar: () -> ByteArray, ) internal fun ActionCoords.buildJars(types: String?): Jars? { @@ -31,18 +31,25 @@ internal fun ActionCoords.buildJars(types: String?): Jars? { generateBinding(metadataRevision = NewestForVersion, types = types).also { if (it.isEmpty()) return null } - val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources() - val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths) - val mainJarByteArrayOutputStream = ByteArrayOutputStream() - mainJarByteArrayOutputStream.createZipFile(pathWithJarContents) + val mainJar by lazy { + val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources() + val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths) + val mainJarByteArrayOutputStream = ByteArrayOutputStream() + mainJarByteArrayOutputStream.createZipFile(pathWithJarContents) + mainJarByteArrayOutputStream.toByteArray() + } - val sourcesJarByteArrayOutputStream = ByteArrayOutputStream() - sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir) + val sourcesJar by lazy { + val (_, compilationInputDir) = binding.prepareDirectoryWithSources() + val sourcesJarByteArrayOutputStream = ByteArrayOutputStream() + sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir) + sourcesJarByteArrayOutputStream.toByteArray() + } return Jars( - mainJar = mainJarByteArrayOutputStream.toByteArray(), - sourcesJar = sourcesJarByteArrayOutputStream.toByteArray(), + mainJar = { mainJar }, + sourcesJar = { sourcesJar }, ) } diff --git a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt index c14ee171a6..cc38b1e68c 100644 --- a/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt +++ b/maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt @@ -6,11 +6,11 @@ import java.security.MessageDigest sealed interface Artifact data class TextArtifact( - val data: String, + val data: () -> String, ) : Artifact data class JarArtifact( - val data: ByteArray, + val data: () -> ByteArray, ) : Artifact fun ActionCoords.buildVersionArtifacts(types: String? = null): Map? { @@ -19,13 +19,13 @@ fun ActionCoords.buildVersionArtifacts(types: String? = null): Map