diff --git a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/AnyExtensions.kt b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/AnyExtensions.kt new file mode 100644 index 0000000..a50a3ec --- /dev/null +++ b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/extensions/AnyExtensions.kt @@ -0,0 +1,12 @@ +package ch.ubique.gradle.alpaka.extensions + +import kotlin.reflect.KProperty1 + +fun Any.prettyPrint(): String { + return this::class + .members + .filterIsInstance>() + .joinToString(separator = "\n") { property -> + property.name + ": " + property.get(this).toString().replace("\n", "\\n") + } +} diff --git a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/task/UploadToAlpakaBackendTask.kt b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/task/UploadToAlpakaBackendTask.kt index ca03ddf..cb05a1b 100644 --- a/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/task/UploadToAlpakaBackendTask.kt +++ b/alpaka/plugin/src/main/java/ch/ubique/gradle/alpaka/task/UploadToAlpakaBackendTask.kt @@ -3,6 +3,7 @@ package ch.ubique.gradle.alpaka.task import ch.ubique.gradle.alpaka.extensions.getResDirs +import ch.ubique.gradle.alpaka.extensions.prettyPrint import ch.ubique.gradle.alpaka.model.UploadRequest import ch.ubique.gradle.alpaka.network.BackendRepository import ch.ubique.gradle.alpaka.network.OkHttpInstance @@ -64,6 +65,10 @@ abstract class UploadToAlpakaBackendTask : DefaultTask() { @get:InputFile abstract var webIcon: Provider + @get:Input + @set:Option(option = "alpaka-dryrun", description = "Execute the Alpaka upload as a dry-run.") + var dryrun: Boolean = false + @TaskAction fun uploadAction() { val proxy = proxy @@ -84,10 +89,22 @@ abstract class UploadToAlpakaBackendTask : DefaultTask() { signature = signature, ) + val apkFile = apk.get() + val webIconFile = webIcon.get() + + logger.lifecycle("apk file: ${apkFile.relativeTo(project.rootDir).path} (${apkFile.length() / 1024} kB)") + logger.lifecycle("icon file: ${webIconFile.relativeTo(project.rootDir).path} (${webIconFile.length() / 1024} kB)") + logger.lifecycle("metadata:\n${uploadRequest.prettyPrint().prependIndent()}") + + if (dryrun) { + logger.lifecycle("Dry-run completed.") + return + } + logger.lifecycle("Starting upload to Alpaka.") try { val backendRepository = BackendRepository() - backendRepository.appsUpload(uploadRequest, apk.get(), webIcon.get(), uploadKey) + backendRepository.appsUpload(uploadRequest, apkFile, webIconFile, uploadKey) logger.lifecycle("Upload to Alpaka successful.") } catch (e: Exception) { val message = if (e is HttpException) { diff --git a/examplegroovy/build.gradle b/examplegroovy/build.gradle index 0c1b3d3..4e7b0d8 100644 --- a/examplegroovy/build.gradle +++ b/examplegroovy/build.gradle @@ -13,7 +13,7 @@ android { minSdk 26 targetSdk 34 versionCode 1 - versionName project.version.toString() + versionName "1.0" alpakaUploadKey = "defaultConfig upload key" } diff --git a/examplegroovy/src/main/AndroidManifest.xml b/examplegroovy/src/main/AndroidManifest.xml index d52fdb8..b6a007e 100644 --- a/examplegroovy/src/main/AndroidManifest.xml +++ b/examplegroovy/src/main/AndroidManifest.xml @@ -1,6 +1,10 @@ + + + + + + + +