Skip to content

Commit a2007dd

Browse files
committed
feat(abg): only create sources and jars when they are actually requested
1 parent 4fcc137 commit a2007dd

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ private fun Route.artifact(
124124
val file = call.parameters["file"]!!
125125
if (file in bindingArtifacts) {
126126
when (val artifact = bindingArtifacts[file]) {
127-
is TextArtifact -> call.respondText(text = artifact.data)
127+
is TextArtifact -> call.respondText(text = artifact.data())
128128
is JarArtifact ->
129129
call.respondBytes(
130-
bytes = artifact.data,
130+
bytes = artifact.data(),
131131
contentType = ContentType.parse("application/java-archive"),
132132
)
133133

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/JarBuilding.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,34 @@ import kotlin.io.path.div
2222
import kotlin.io.path.writeText
2323

2424
internal data class Jars(
25-
val mainJar: ByteArray,
26-
val sourcesJar: ByteArray,
25+
val mainJar: () -> ByteArray,
26+
val sourcesJar: () -> ByteArray,
2727
)
2828

2929
internal fun ActionCoords.buildJars(types: String?): Jars? {
3030
val binding =
3131
generateBinding(metadataRevision = NewestForVersion, types = types).also {
3232
if (it.isEmpty()) return null
3333
}
34-
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
3534

36-
val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
37-
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
38-
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
35+
val mainJar by lazy {
36+
val (sourceFilePaths, compilationInputDir) = binding.prepareDirectoryWithSources()
37+
val pathWithJarContents = compileBinding(sourceFilePaths = sourceFilePaths)
38+
val mainJarByteArrayOutputStream = ByteArrayOutputStream()
39+
mainJarByteArrayOutputStream.createZipFile(pathWithJarContents)
40+
mainJarByteArrayOutputStream.toByteArray()
41+
}
3942

40-
val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
41-
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
43+
val sourcesJar by lazy {
44+
val (_, compilationInputDir) = binding.prepareDirectoryWithSources()
45+
val sourcesJarByteArrayOutputStream = ByteArrayOutputStream()
46+
sourcesJarByteArrayOutputStream.createZipFile(compilationInputDir)
47+
sourcesJarByteArrayOutputStream.toByteArray()
48+
}
4249

4350
return Jars(
44-
mainJar = mainJarByteArrayOutputStream.toByteArray(),
45-
sourcesJar = sourcesJarByteArrayOutputStream.toByteArray(),
51+
mainJar = { mainJar },
52+
sourcesJar = { sourcesJar },
4653
)
4754
}
4855

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/VersionArtifactsBuilding.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import java.security.MessageDigest
66
sealed interface Artifact
77

88
data class TextArtifact(
9-
val data: String,
9+
val data: () -> String,
1010
) : Artifact
1111

1212
data class JarArtifact(
13-
val data: ByteArray,
13+
val data: () -> ByteArray,
1414
) : Artifact
1515

1616
fun ActionCoords.buildVersionArtifacts(types: String? = null): Map<String, Artifact>? {
@@ -19,13 +19,13 @@ fun ActionCoords.buildVersionArtifacts(types: String? = null): Map<String, Artif
1919
val module = buildModuleFile()
2020
return mapOf(
2121
"$name-$version.jar" to JarArtifact(jars.mainJar),
22-
"$name-$version.jar.md5" to TextArtifact(jars.mainJar.md5Checksum()),
22+
"$name-$version.jar.md5" to TextArtifact { jars.mainJar().md5Checksum() },
2323
"$name-$version-sources.jar" to JarArtifact(jars.sourcesJar),
24-
"$name-$version-sources.jar.md5" to TextArtifact(jars.sourcesJar.md5Checksum()),
25-
"$name-$version.pom" to TextArtifact(pom),
26-
"$name-$version.pom.md5" to TextArtifact(pom.md5Checksum()),
27-
"$name-$version.module" to TextArtifact(module),
28-
"$name-$version.module.md5" to TextArtifact(module.md5Checksum()),
24+
"$name-$version-sources.jar.md5" to TextArtifact { jars.sourcesJar().md5Checksum() },
25+
"$name-$version.pom" to TextArtifact { pom },
26+
"$name-$version.pom.md5" to TextArtifact { pom.md5Checksum() },
27+
"$name-$version.module" to TextArtifact { module },
28+
"$name-$version.module.md5" to TextArtifact { module.md5Checksum() },
2929
)
3030
}
3131

0 commit comments

Comments
 (0)