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 654cf6c761..8c27e4a5e2 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 @@ -109,10 +109,10 @@ private fun Route.artifact( val file = call.parameters["file"]!! if (file in bindingArtifacts) { when (val artifact = bindingArtifacts[file]) { - is TextArtifact -> call.respondText(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 78c1619546..043e8798d4 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 buildJars( @@ -35,18 +35,25 @@ internal fun buildJars( generateBinding(owner = owner, name = name, version = version).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 eb9800c4a4..db0c2553fd 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(): Map? { @@ -19,13 +19,13 @@ fun ActionCoords.buildVersionArtifacts(): Map? { val module = buildModuleFile(owner = owner, name = name.replace("__", "/"), version = version) return mapOf( "$name-$version.jar" to JarArtifact(jars.mainJar), - "$name-$version.jar.md5" to TextArtifact(jars.mainJar.md5Checksum()), + "$name-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() }, "$name-$version-sources.jar" to JarArtifact(jars.sourcesJar), - "$name-$version-sources.jar.md5" to TextArtifact(jars.sourcesJar.md5Checksum()), - "$name-$version.pom" to TextArtifact(pom), - "$name-$version.pom.md5" to TextArtifact(pom.md5Checksum()), - "$name-$version.module" to TextArtifact(module), - "$name-$version.module.md5" to TextArtifact(module.md5Checksum()), + "$name-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() }, + "$name-$version.pom" to TextArtifact { pom }, + "$name-$version.pom.md5" to TextArtifact { pom.md5Checksum() }, + "$name-$version.module" to TextArtifact { module }, + "$name-$version.module.md5" to TextArtifact { module.md5Checksum() }, ) }