-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added application flavor and applied convention plugin to all module (#…
…2102) * Refactor - renamed datastore module to database module * Refactor - Added application flavor - Moved files to respective module - Applied convention plugins in all module - Removed unnecessary dependencies from all module - Added few modules like :core:ui, :core:testing, :core:domain
- Loading branch information
Showing
390 changed files
with
807 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
build-logic/convention/src/main/kotlin/AndroidApplicationFlavorsConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.mifos.configureFlavors | ||
|
||
class AndroidApplicationFlavorsConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
extensions.configure<ApplicationExtension> { | ||
configureFlavors(this) | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
build-logic/convention/src/main/kotlin/AndroidApplicationJacocoConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import com.android.build.api.variant.ApplicationAndroidComponentsExtension | ||
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.mifos.configureJacoco | ||
|
||
class AndroidApplicationJacocoConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("jacoco") | ||
val androidExtension = extensions.getByType<BaseAppModuleExtension>() | ||
|
||
androidExtension.buildTypes.configureEach { | ||
enableAndroidTestCoverage = true | ||
enableUnitTestCoverage = true | ||
} | ||
|
||
configureJacoco(extensions.getByType<ApplicationAndroidComponentsExtension>()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
build-logic/convention/src/main/kotlin/AndroidLibraryJacocoConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import com.android.build.api.dsl.LibraryExtension | ||
import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.mifos.configureJacoco | ||
|
||
class AndroidLibraryJacocoConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("jacoco") | ||
val androidExtension = extensions.getByType<LibraryExtension>() | ||
|
||
androidExtension.buildTypes.configureEach { | ||
enableAndroidTestCoverage = true | ||
enableUnitTestCoverage = true | ||
} | ||
|
||
configureJacoco(extensions.getByType<LibraryAndroidComponentsExtension>()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
build-logic/convention/src/main/kotlin/org/mifos/GradleManagedDevices.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.mifos | ||
|
||
import com.android.build.api.dsl.CommonExtension | ||
import com.android.build.api.dsl.ManagedVirtualDevice | ||
import org.gradle.kotlin.dsl.get | ||
import org.gradle.kotlin.dsl.invoke | ||
|
||
/** | ||
* Configure project for Gradle managed devices | ||
*/ | ||
internal fun configureGradleManagedDevices( | ||
commonExtension: CommonExtension<*, *, *, *, *>, | ||
) { | ||
val pixel4 = DeviceConfig("Pixel 4", 30, "aosp-atd") | ||
val pixel6 = DeviceConfig("Pixel 6", 31, "aosp") | ||
val pixelC = DeviceConfig("Pixel C", 30, "aosp-atd") | ||
|
||
val allDevices = listOf(pixel4, pixel6, pixelC) | ||
val ciDevices = listOf(pixel4, pixelC) | ||
|
||
commonExtension.testOptions { | ||
managedDevices { | ||
devices { | ||
allDevices.forEach { deviceConfig -> | ||
maybeCreate(deviceConfig.taskName, ManagedVirtualDevice::class.java).apply { | ||
device = deviceConfig.device | ||
apiLevel = deviceConfig.apiLevel | ||
systemImageSource = deviceConfig.systemImageSource | ||
} | ||
} | ||
} | ||
groups { | ||
maybeCreate("ci").apply { | ||
ciDevices.forEach { deviceConfig -> | ||
targetDevices.add(devices[deviceConfig.taskName]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private data class DeviceConfig( | ||
val device: String, | ||
val apiLevel: Int, | ||
val systemImageSource: String, | ||
) { | ||
val taskName = buildString { | ||
append(device.lowercase().replace(" ", "")) | ||
append("api") | ||
append(apiLevel.toString()) | ||
append(systemImageSource.replace("-", "")) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
build-logic/convention/src/main/kotlin/org/mifos/Jacoco.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.mifos | ||
|
||
import com.android.build.api.artifact.ScopedArtifact | ||
import com.android.build.api.variant.AndroidComponentsExtension | ||
import com.android.build.api.variant.ScopedArtifacts | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.tasks.testing.Test | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.register | ||
import org.gradle.kotlin.dsl.withType | ||
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension | ||
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension | ||
import org.gradle.testing.jacoco.tasks.JacocoReport | ||
import java.util.Locale | ||
|
||
private val coverageExclusions = listOf( | ||
// Android | ||
"**/R.class", | ||
"**/R\$*.class", | ||
"**/BuildConfig.*", | ||
"**/Manifest*.*", | ||
"**/*_Hilt*.class", | ||
"**/Hilt_*.class", | ||
) | ||
|
||
private fun String.capitalize() = replaceFirstChar { | ||
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() | ||
} | ||
|
||
/** | ||
* Creates a new task that generates a combined coverage report with data from local and | ||
* instrumented tests. | ||
* | ||
* `create{variant}CombinedCoverageReport` | ||
* | ||
* Note that coverage data must exist before running the task. This allows us to run device | ||
* tests on CI using a different Github Action or an external device farm. | ||
*/ | ||
internal fun Project.configureJacoco( | ||
androidComponentsExtension: AndroidComponentsExtension<*, *, *>, | ||
) { | ||
configure<JacocoPluginExtension> { | ||
toolVersion = libs.findVersion("jacoco").get().toString() | ||
} | ||
|
||
androidComponentsExtension.onVariants { variant -> | ||
val myObjFactory = project.objects | ||
val buildDir = layout.buildDirectory.get().asFile | ||
val allJars: ListProperty<RegularFile> = myObjFactory.listProperty(RegularFile::class.java) | ||
val allDirectories: ListProperty<Directory> = | ||
myObjFactory.listProperty(Directory::class.java) | ||
val reportTask = | ||
tasks.register( | ||
"create${variant.name.capitalize()}CombinedCoverageReport", | ||
JacocoReport::class | ||
) { | ||
|
||
classDirectories.setFrom( | ||
allJars, | ||
allDirectories.map { dirs -> | ||
dirs.map { dir -> | ||
myObjFactory.fileTree().setDir(dir).exclude(coverageExclusions) | ||
} | ||
} | ||
) | ||
reports { | ||
xml.required.set(true) | ||
html.required.set(true) | ||
} | ||
|
||
// TODO: This is missing files in src/debug/, src/prod, src/demo, src/demoDebug... | ||
sourceDirectories.setFrom( | ||
files( | ||
"$projectDir/src/main/java", | ||
"$projectDir/src/main/kotlin" | ||
) | ||
) | ||
|
||
executionData.setFrom( | ||
project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest") | ||
.matching { include("**/*.exec") }, | ||
|
||
project.fileTree("$buildDir/outputs/code_coverage/${variant.name}AndroidTest") | ||
.matching { include("**/*.ec") } | ||
) | ||
} | ||
|
||
|
||
variant.artifacts.forScope(ScopedArtifacts.Scope.PROJECT) | ||
.use(reportTask) | ||
.toGet( | ||
ScopedArtifact.CLASSES, | ||
{ _ -> allJars }, | ||
{ _ -> allDirectories }, | ||
) | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
configure<JacocoTaskExtension> { | ||
// Required for JaCoCo + Robolectric | ||
// https://github.com/robolectric/robolectric/issues/2230 | ||
isIncludeNoLocationClasses = true | ||
|
||
// Required for JDK 11 with the above | ||
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009 | ||
excludes = listOf("jdk.internal.*") | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
build-logic/convention/src/main/kotlin/org/mifos/MifosBuildType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.mifos | ||
|
||
/** | ||
* This is shared between :app and :benchmarks module to provide configurations type safety. | ||
*/ | ||
enum class MifosBuildType(val applicationIdSuffix: String? = null) { | ||
DEBUG(".debug"), | ||
RELEASE, | ||
} |
Oops, something went wrong.