Skip to content

Commit

Permalink
feat(abg): only create sources and jars when they are actually requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Sep 4, 2024
1 parent 9c6721a commit 28d8de9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,34 @@ 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? {
val binding =
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 },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Artifact>? {
Expand All @@ -19,13 +19,13 @@ fun ActionCoords.buildVersionArtifacts(types: String? = null): Map<String, Artif
val module = buildModuleFile()
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() },
)
}

Expand Down

0 comments on commit 28d8de9

Please sign in to comment.