Skip to content

Commit

Permalink
Feature: Beta label and hint (#7)
Browse files Browse the repository at this point in the history
* Added beta label and hint.

* Cleanup code.

* remove debug return.
  • Loading branch information
TimOrtel authored Sep 21, 2023
1 parent ffe72bf commit 24332c8
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 60 deletions.
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ android {
versionNameSuffix =
"-" + ProductFlavors.Dimensions.InstanceSelection.Flavors.Tum
}

findByName(ProductFlavors.Dimensions.ReleaseType.Flavors.Beta)?.apply {
versionNameSuffix =
"-beta"
}

findByName(ProductFlavors.Dimensions.ReleaseType.Flavors.Production)?.apply {
versionNameSuffix =
"-prod"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import commonConfiguration.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -20,7 +19,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {

extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
configureInstanceSelectionFlavor(this)
configureInstanceSelectionFlavors(this)
defaultConfig.targetSdk = 33
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")

import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.internal.coverage.JacocoReportTask
import commonConfiguration.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.lang.Boolean
import kotlin.Suppress
import kotlin.apply
import kotlin.with
Expand All @@ -30,7 +21,7 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
}

extensions.configure<LibraryExtension> {
configureInstanceSelectionFlavor(this)
configureInstanceSelectionFlavors(this)

buildTypes {
all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AndroidLibraryInstanceSelectionFlavorConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
extensions.configure<LibraryExtension> {
configureInstanceSelectionFlavor(this)
configureInstanceSelectionFlavors(this)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ internal fun Project.configureJacoco(
androidComponentsExtension.onVariants { variant ->
val testTaskName = "test${variant.name.capitalize()}UnitTest"

val reportTask = tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport::class) {
dependsOn(testTaskName)
val reportTask =
tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport::class) {
dependsOn(testTaskName)

reports {
xml.required.set(true)
html.required.set(true)
}

classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
exclude(coverageExclusions)
reports {
xml.required.set(true)
html.required.set(true)
}
)

sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin"))
executionData(tasks.getByName(testTaskName))
}
classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
exclude(coverageExclusions)
}
)

sourceDirectories.setFrom(
files(
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin"
)
)
executionData(tasks.getByName(testTaskName))
}

jacocoTestReport.dependsOn(reportTask)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")

import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ProductFlavor
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.JavaVersion
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
Expand All @@ -26,12 +28,24 @@ object ProductFlavors {
const val Tum = "tum"
}
}

object ReleaseType {
const val Key = "release-type"

object Flavors {
const val Beta = "beta"

const val Production = "production"
}
}
}

object BuildConfigFields {
const val HasInstanceRestriction = "hasInstanceRestriction"

const val DefaultServerUrl = "defaultServerUrl"

const val IsBeta = "isBeta"
}
}

Expand Down Expand Up @@ -92,52 +106,90 @@ internal fun Project.configureKotlinAndroid(
dependencies {
add("coreLibraryDesugaring", libs.findLibrary("android.desugarJdkLibs").get())
}

configureReleaseTypeFlavors(commonExtension)
}

internal fun Project.configureReleaseTypeFlavors(
commonExtension: CommonExtension<*, *, *, *, *>,
) {
commonExtension.apply {
flavorDimensions += ProductFlavors.Dimensions.ReleaseType.Key

productFlavors {
createFlavor(
ProductFlavors.Dimensions.ReleaseType.Key,
ProductFlavors.Dimensions.ReleaseType.Flavors.Beta
) {
buildConfigField("boolean", ProductFlavors.BuildConfigFields.IsBeta, "true")
}

createFlavor(
ProductFlavors.Dimensions.ReleaseType.Key,
ProductFlavors.Dimensions.ReleaseType.Flavors.Production
) {
buildConfigField("boolean", ProductFlavors.BuildConfigFields.IsBeta, "false")
}
}
}
}

internal fun Project.configureInstanceSelectionFlavor(
internal fun Project.configureInstanceSelectionFlavors(
commonExtension: CommonExtension<*, *, *, *, *>,
) {
commonExtension.apply {
flavorDimensions += ProductFlavors.Dimensions.InstanceSelection.Key

productFlavors {
if (!Boolean.getBoolean("skip.flavor.${ProductFlavors.Dimensions.InstanceSelection.Flavors.FreeInstanceSelection}")) {
create(ProductFlavors.Dimensions.InstanceSelection.Flavors.FreeInstanceSelection) {
dimension = ProductFlavors.Dimensions.InstanceSelection.Key

buildConfigField(
"boolean",
ProductFlavors.BuildConfigFields.HasInstanceRestriction,
"false"
)
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"\""
)
}
createFlavor(
ProductFlavors.Dimensions.InstanceSelection.Key,
ProductFlavors.Dimensions.InstanceSelection.Flavors.FreeInstanceSelection
) {
buildConfigField(
"boolean",
ProductFlavors.BuildConfigFields.HasInstanceRestriction,
"false"
)
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"\""
)
}

if (!Boolean.getBoolean("skip.flavor.${ProductFlavors.Dimensions.InstanceSelection.Flavors.Tum}")) {
create(ProductFlavors.Dimensions.InstanceSelection.Flavors.Tum) {
dimension = ProductFlavors.Dimensions.InstanceSelection.Key

buildConfigField(
"boolean",
ProductFlavors.BuildConfigFields.HasInstanceRestriction,
"true"
)
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"https://artemis.cit.tum.de\""
)
}
createFlavor(
ProductFlavors.Dimensions.InstanceSelection.Key,
ProductFlavors.Dimensions.InstanceSelection.Flavors.Tum
) {
buildConfigField(
"boolean",
ProductFlavors.BuildConfigFields.HasInstanceRestriction,
"true"
)
buildConfigField(
"String",
ProductFlavors.BuildConfigFields.DefaultServerUrl,
"\"https://artemis.cit.tum.de\""
)
}
}
}
}

private fun NamedDomainObjectContainer<out ProductFlavor>.createFlavor(
dimensionKey: String,
name: String,
configure: ProductFlavor.() -> Unit
) {
if (!Boolean.getBoolean("skip.flavor.$name")) {
create(name) {
dimension = dimensionKey

configure()
}
}
}

fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
3 changes: 3 additions & 0 deletions feature/dashboard/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ dependencies {
implementation(project(":core:data"))
implementation(project(":core:device"))

implementation(libs.androidx.dataStore.core)
implementation(libs.androidx.dataStore.preferences)

implementation(libs.accompanist.swiperefresh)
testImplementation(project(":feature:login"))
testImplementation(project(":feature:login-test"))
Expand Down
Loading

0 comments on commit 24332c8

Please sign in to comment.