Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arbitrary metadata in the manifest #1153

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import okio.ByteString.Companion.decodeHex
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
Expand Down Expand Up @@ -62,6 +63,10 @@ abstract class ZiplineCompileTask : DefaultTask() {
@get:Input
abstract val version: Property<String>

@get:Optional
@get:Input
abstract val metadata: MapProperty<String, String>

internal fun configure(
jsProductionTask: JsProductionTask,
extension: ZiplineExtension,
Expand All @@ -79,6 +84,7 @@ abstract class ZiplineCompileTask : DefaultTask() {
mainModuleId.set(extension.mainModuleId)
mainFunction.set(extension.mainFunction)
version.set(extension.version)
metadata.set(extension.metadata)

signingKeys.set(
project.provider {
Expand Down Expand Up @@ -111,6 +117,7 @@ abstract class ZiplineCompileTask : DefaultTask() {
else -> null
}
val version = version.orNull
val metadata = metadata.orNull ?: mapOf()

if (inputChanges.isIncremental) {
fun filterByChangeType(filter: (ChangeType) -> Boolean): List<File> {
Expand All @@ -128,6 +135,7 @@ abstract class ZiplineCompileTask : DefaultTask() {
mainModuleId = mainModuleId,
manifestSigner = manifestSigner,
version = version,
metadata = metadata,
)
} else {
ZiplineCompiler.compile(
Expand All @@ -137,6 +145,7 @@ abstract class ZiplineCompileTask : DefaultTask() {
mainModuleId = mainModuleId,
manifestSigner = manifestSigner,
version = version,
metadata = metadata,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal object ZiplineCompiler {
mainModuleId: String?,
manifestSigner: ManifestSigner?,
version: String?,
metadata: Map<String, String>,
) {
val jsFiles = getJsFiles(inputDir.listFiles()!!.asList())
val modules = compileFilesInParallel(jsFiles, outputDir)
Expand All @@ -56,6 +57,7 @@ internal object ZiplineCompiler {
manifestSigner = manifestSigner,
modules = modules,
version = version,
metadata = metadata,
)
}

Expand All @@ -68,6 +70,7 @@ internal object ZiplineCompiler {
mainModuleId: String?,
manifestSigner: ManifestSigner?,
version: String?,
metadata: Map<String, String>,
) {
val modifiedFileNames = getJsFiles(modifiedFiles).map { it.name }.toSet()
val removedFileNames = getJsFiles(removedFiles).map { it.name }.toSet()
Expand Down Expand Up @@ -95,6 +98,7 @@ internal object ZiplineCompiler {
manifestSigner = manifestSigner,
modules = unchangedModules + compiledModules,
version = version,
metadata = metadata,
)
}

Expand Down Expand Up @@ -150,17 +154,19 @@ internal object ZiplineCompiler {

private fun writeManifest(
outputDir: File,
mainFunction: String? = null,
mainModuleId: String? = null,
manifestSigner: ManifestSigner? = null,
mainFunction: String?,
mainModuleId: String?,
manifestSigner: ManifestSigner?,
modules: Map<String, ZiplineManifest.Module>,
version: String? = null,
version: String?,
metadata: Map<String, String>,
) {
val unsignedManifest = ZiplineManifest.create(
modules = modules,
mainFunction = mainFunction,
mainModuleId = mainModuleId,
version = version,
metadata = metadata,
)

val manifest = manifestSigner?.sign(unsignedManifest) ?: unsignedManifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package app.cash.zipline.gradle

import app.cash.zipline.loader.SignatureAlgorithmId
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property

abstract class ZiplineExtension {
Expand All @@ -25,6 +26,7 @@ abstract class ZiplineExtension {
abstract val version: Property<String>
abstract val signingKeys: NamedDomainObjectContainer<SigningKey>
abstract val httpServerPort: Property<Int>
abstract val metadata: MapProperty<String, String>

abstract class SigningKey(val name: String) {
abstract val algorithmId: Property<SignatureAlgorithmId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class ZiplineCompilerTest {
mainModuleId = mainModuleId,
manifestSigner = null,
version = null,
metadata = mapOf(),
)

val expectedNumberFiles = if (dirHasSourceMaps) inputDir.listFiles()!!.size / 2 else inputDir.listFiles()!!.size
Expand Down Expand Up @@ -182,6 +183,7 @@ class ZiplineCompilerTest {
removedFiles = removedFiles,
manifestSigner = null,
version = null,
metadata = mapOf(),
)

val expectedNumberFiles = inputDir.listFiles()!!.size + addedFiles.size - removedFiles.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ class ZiplinePluginTest {
assertThat(ziplineOut.resolve("multipleJsTargets-lib-blue.zipline").exists()).isTrue()
}

@Test
fun versionAndMetadata() {
val projectDir = File("src/test/projects/basic")

val taskName = ":lib:compileDevelopmentExecutableKotlinJsZipline"
val result = createRunner(projectDir, "clean", taskName).build()
assertThat(SUCCESS_OUTCOMES)
.contains(result.task(taskName)!!.outcome)

val ziplineOut = projectDir.resolve(
"lib/build/compileSync/js/main/developmentExecutable/kotlinZipline",
)
val manifest = ziplineOut.resolve(manifestFileName)
val manifestText = manifest.readText()
assertThat(manifestText)
.contains(""""version":"1.2.3"""")
assertThat(manifestText)
.contains(""""metadata":{"build_timestamp":"2023-10-25T12:00:00T"}""")
}

@Test
fun manifestSigning() {
val projectDir = File("src/test/projects/signing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ val launchGreetService by tasks.creating(JavaExec::class) {

zipline {
mainFunction.set("app.cash.zipline.tests.launchGreetService")
version.set("1.2.3")
metadata.put("build_timestamp", "2023-10-25T12:00:00T")
}

plugins.withType<YarnPlugin> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

kotlin {
js() {
js {
browser()
binaries.executable()
}
Expand Down
18 changes: 13 additions & 5 deletions zipline/api/android/zipline.api
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,29 @@ public abstract interface class app/cash/zipline/ZiplineFunction {

public final class app/cash/zipline/ZiplineManifest {
public static final field Companion Lapp/cash/zipline/ZiplineManifest$Companion;
public synthetic fun <init> (ILapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lapp/cash/zipline/ZiplineManifest$Unsigned;
public final fun component2 ()Ljava/util/Map;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/lang/String;
public final fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun component6 ()Ljava/util/Map;
public final synthetic fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public final synthetic fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public final fun encodeJson ()Ljava/lang/String;
public fun equals (Ljava/lang/Object;)Z
public final fun getBaseUrl ()Ljava/lang/String;
public final fun getFreshAtEpochMs ()Ljava/lang/Long;
public final fun getMainFunction ()Ljava/lang/String;
public final fun getMainModuleId ()Ljava/lang/String;
public final fun getMetadata ()Ljava/util/Map;
public final fun getModules ()Ljava/util/Map;
public final fun getSignaturePayload ()Lokio/ByteString;
public final fun getSignatures ()Ljava/util/Map;
Expand All @@ -237,8 +243,10 @@ public final class app/cash/zipline/ZiplineManifest$$serializer : kotlinx/serial
}

public final class app/cash/zipline/ZiplineManifest$Companion {
public final fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final synthetic fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun create$default (Lapp/cash/zipline/ZiplineManifest$Companion;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun create$default (Lapp/cash/zipline/ZiplineManifest$Companion;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public final fun decodeJson (Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
Expand Down
18 changes: 13 additions & 5 deletions zipline/api/jvm/zipline.api
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,29 @@ public abstract interface class app/cash/zipline/ZiplineFunction {

public final class app/cash/zipline/ZiplineManifest {
public static final field Companion Lapp/cash/zipline/ZiplineManifest$Companion;
public synthetic fun <init> (ILapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public synthetic fun <init> (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lapp/cash/zipline/ZiplineManifest$Unsigned;
public final fun component2 ()Ljava/util/Map;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/lang/String;
public final fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun component6 ()Ljava/util/Map;
public final synthetic fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public final synthetic fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun copy (Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Lapp/cash/zipline/ZiplineManifest$Unsigned;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun copy$default (Lapp/cash/zipline/ZiplineManifest;Ljava/util/Map;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public final fun encodeJson ()Ljava/lang/String;
public fun equals (Ljava/lang/Object;)Z
public final fun getBaseUrl ()Ljava/lang/String;
public final fun getFreshAtEpochMs ()Ljava/lang/Long;
public final fun getMainFunction ()Ljava/lang/String;
public final fun getMainModuleId ()Ljava/lang/String;
public final fun getMetadata ()Ljava/util/Map;
public final fun getModules ()Ljava/util/Map;
public final fun getSignaturePayload ()Lokio/ByteString;
public final fun getSignatures ()Ljava/util/Map;
Expand All @@ -237,8 +243,10 @@ public final class app/cash/zipline/ZiplineManifest$$serializer : kotlinx/serial
}

public final class app/cash/zipline/ZiplineManifest$Companion {
public final fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final synthetic fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun create (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun create$default (Lapp/cash/zipline/ZiplineManifest$Companion;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public static synthetic fun create$default (Lapp/cash/zipline/ZiplineManifest$Companion;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lapp/cash/zipline/ZiplineManifest;
public final fun decodeJson (Ljava/lang/String;)Lapp/cash/zipline/ZiplineManifest;
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}
Expand Down
Loading