Skip to content

Commit

Permalink
More fields from AndroidExtension read
Browse files Browse the repository at this point in the history
  • Loading branch information
tabere-ubique committed Sep 6, 2024
1 parent 353982f commit c7c6671
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 64 deletions.
4 changes: 2 additions & 2 deletions appexample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
flavorDimensions += "version"
productFlavors {
create("dev") {
applicationIdSuffix = ".demo"
versionNameSuffix = "-demo"
applicationIdSuffix = ".dev"
versionNameSuffix = "-dev"
}
create("prod") {
applicationIdSuffix = ".prod"
Expand Down
11 changes: 2 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ retrofit = "2.11.0"
moshi = "1.15.1"
agp = "8.6.0"

agpVersion = "8.6.0"
kotlinVersion = "2.0.20"
runner = "1.0.2"
espressoCore = "3.0.2"
appcompatV7 = "28.0.0"
constraintLayout = "2.0.4"
livedata = "1.1.1"
Expand All @@ -19,9 +15,8 @@ viewmodel = "1.1.1"
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"}

androidApplication = { id = "com.android.application", version.ref = "agpVersion" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" }
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

[libraries]
junit = "junit:junit:4.13.2"
Expand All @@ -35,8 +30,6 @@ moshiKotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi
moshiAdapters = { module = "com.squareup.moshi:moshi-adapters", version.ref = "moshi"}
agp = { module = "com.android.tools.build:gradle", version.ref = "agp"}

runner = { group = "com.android.support.test", name = "runner", version.ref = "runner" }
espressoCore = { group = "com.android.support.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompatV7 = { group = "com.android.support", name = "appcompat-v7", version.ref = "appcompatV7" }
constraintLayout = { group = "com.android.support.constraint", name = "constraint-layout", version.ref = "constraintLayout" }
livedata = { group = "android.arch.lifecycle", name = "livedata", version.ref = "livedata" }
Expand Down
32 changes: 26 additions & 6 deletions plugin-build/plugin/src/main/java/ch/ubique/linth/LinthPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ch.ubique.linth

import ch.ubique.linth.common.capitalize
import ch.ubique.linth.model.UploadRequest
import com.android.build.gradle.AppExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File

abstract class LinthPlugin : Plugin<Project> {

Expand All @@ -17,26 +17,46 @@ abstract class LinthPlugin : Plugin<Project> {
uploadTask.uploadKey = extension.uploadKey.get()
uploadTask.proxy = extension.proxy.orNull

//val apkFilesNotSet = extension.apkFiles.isEmpty.not()

// setup upload task
val releaseApks = mutableListOf<File>()
val uploadRequests = mutableListOf<UploadRequest>()
val uploadFlavors = extension.flavors.orNull?.split(",")?.map { it.trim() }

val minSdk = requireNotNull(androidExtension.defaultConfig.minSdk)
val targetSdk = requireNotNull(androidExtension.defaultConfig.targetSdk)
val versionName = requireNotNull(androidExtension.defaultConfig.versionName)

androidExtension.applicationVariants.forEach { variant ->
val flavor = variant.flavorName.capitalize()
val packageName = variant.applicationId
if (uploadFlavors == null || uploadFlavors.contains(variant.flavorName)) {
uploadTask.dependsOn(project.tasks.named("assemble${flavor}Release"))

variant.outputs.forEach {
if (it.outputFile.parentFile.name == "release") {
releaseApks.add(it.outputFile)
val uploadRequest = UploadRequest(
apk = it.outputFile,
appIcon = it.outputFile,
appName = "some fancy name",
packageName = packageName,
flavor = flavor,
branch = "someFancyBranch",
minSdk = minSdk,
targetSdk = targetSdk,
usesFeature = emptyList(),
buildNumber = 0L,
buildTime = 0L,
buildBatch = "buildBatch",
changelog = "Some fancy changelog",
signature = "someFancySignature",
version = versionName,
)
uploadRequests.add(uploadRequest)
}
}
}
}

uploadTask.inputApks = releaseApks
uploadTask.uploadRequests = uploadRequests.toList()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ constructor(project: Project) {
private val objects = project.objects

val flavors: Property<String> = objects.property(String::class.java)
//val apkFiles: ConfigurableFileCollection = objects.fileCollection()
val uploadKey: Property<String> = objects.property(String::class.java)

val proxy: Property<String> = objects.property(String::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import ch.ubique.linth.network.OkHttpInstance
import kotlinx.coroutines.*
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import java.io.File

abstract class UploadToUbDiagTask : DefaultTask() {

Expand All @@ -19,24 +17,6 @@ abstract class UploadToUbDiagTask : DefaultTask() {
group = "publish"
}

/*
@get:Input
@get:Option(option = "message", description = "A message to be printed in the output file")
abstract val message: Property<String>
@get:Input
@get:Option(option = "tag", description = "A Tag to be used for debug and in the output file")
@get:Optional
abstract val tag: Property<String>
@get:OutputFile
abstract val outputFile: RegularFileProperty
*/

@get:InputFiles
@get:Optional
abstract var inputApks: List<File>?

@get:Input
@get:Option(option = "uploadKey", description = "A proxy in format url:port")
abstract var uploadKey: String
Expand All @@ -46,6 +26,9 @@ abstract class UploadToUbDiagTask : DefaultTask() {
@get:Optional
abstract var proxy: String?

@get:Input
abstract var uploadRequests: List<UploadRequest>

@TaskAction
fun uploadAction() {

Expand All @@ -61,37 +44,20 @@ abstract class UploadToUbDiagTask : DefaultTask() {
runBlocking {
coroutineScope {
val allGood = awaitAll(
*requireNotNull(inputApks).map { inputApk ->
*uploadRequests.map { uploadRequest ->
val apkName = uploadRequest.apk.name
async(Dispatchers.IO) {
val uploadRequest = UploadRequest(
apk = inputApk,
appIcon = inputApk,
appName = "Some fancy name",
packageName = "some.package.name",
flavor = "someFancyFlavor",
branch = "someFancyBranch",
minSdk = 0,
targetSdk = 0,
usesFeature = emptyList(),
buildNumber = 0L,
buildTime = 0L,
buildBatch = "buildBatch",
changelog = "Some fancy changelog",
signature = "someFancySignature",
version = "SomeVersion",
uploadKey = uploadKey,
)
try {
backendRepository.appsUpload(uploadRequest)
backendRepository.appsUpload(uploadRequest = uploadRequest, uploadKey = uploadKey)
true
} catch (e: Exception) {
logger.error("${e.message?.trim()} while uploading \"${inputApk.name}\" of flavor \"${uploadRequest.flavor}\".")
logger.error("${e.message?.trim()} while uploading \"$apkName\" of flavor \"${uploadRequest.flavor}\".")
false
}
}
}.toTypedArray()
)
if(allGood.any { it.not() }){
if (allGood.any { it.not() }) {
logger.lifecycle("Upload to UbDiag had errors.")
} else {
logger.lifecycle("Upload to UbDiag successful.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ data class UploadRequest(
val changelog: String,
val signature: String,
val version: String,
val uploadKey: String,
) {

fun toUploadDataJson() = UploadDataJson(
fun toUploadDataJson(uploadKey: String) = UploadDataJson(
name = appName,
packageName = packageName,
flavor = flavor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class BackendRepository {
resetService()
}

suspend fun appsUpload(uploadRequest: UploadRequest) {
suspend fun appsUpload(uploadRequest: UploadRequest, uploadKey: String) {
val data = MoshiBuilder.createMoshi()
.toJson(uploadRequest.toUploadDataJson())
.toJson(uploadRequest.toUploadDataJson(uploadKey = uploadKey))
.toByteArray()
.toRequestBody("application/json".toMediaType())

Expand Down

0 comments on commit c7c6671

Please sign in to comment.