Skip to content

Commit

Permalink
refactor: data and domain use caller co-routine scope (#262)
Browse files Browse the repository at this point in the history
* chore: remove android.work:work-test module

* refactor: simplify data source and factory
  • Loading branch information
wax911 committed Jun 11, 2024
1 parent e2987b8 commit cacbc80
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 290 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,5 @@ fabric.properties

# Exclude client credentail files
secrets.properties

.kotlin/sessions/
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package co.anitrend.arch.buildSrc.plugin
import co.anitrend.arch.buildSrc.plugin.components.configureAndroid
import co.anitrend.arch.buildSrc.plugin.components.configureSpotless
import co.anitrend.arch.buildSrc.plugin.components.configureDependencies
import co.anitrend.arch.buildSrc.plugin.components.configureOptions
import co.anitrend.arch.buildSrc.plugin.components.configurePlugins
import co.anitrend.arch.buildSrc.plugin.components.configureSources
import co.anitrend.arch.buildSrc.plugin.components.configureDokka
import co.anitrend.arch.buildSrc.plugin.extensions.containsBasePlugin
import co.anitrend.arch.buildSrc.plugin.extensions.isKotlinLibraryGroup
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -30,7 +32,8 @@ open class CorePlugin : Plugin<Project> {
if (!project.isKotlinLibraryGroup()) {
project.configureAndroid()
}
project.configureOptions()
project.configureDokka()
project.configureSources()
project.configureDependencies()
project.configureSpotless()
project.availableExtensions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package co.anitrend.arch.buildSrc.plugin.components

import co.anitrend.arch.buildSrc.plugin.extensions.spotlessExtension
import co.anitrend.arch.buildSrc.plugin.extensions.baseExtension
import co.anitrend.arch.buildSrc.plugin.extensions.libraryExtension
import co.anitrend.arch.buildSrc.plugin.extensions.isDomainModule
import co.anitrend.arch.buildSrc.plugin.extensions.isThemeModule
import co.anitrend.arch.buildSrc.plugin.extensions.kotlinAndroidProjectExtension
import co.anitrend.arch.buildSrc.plugin.extensions.props
import co.anitrend.arch.buildSrc.plugin.extensions.libs
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
Expand All @@ -22,20 +20,6 @@ private fun Project.configureLint() = libraryExtension().run {
}
}

internal fun Project.configureSpotless(): Unit = spotlessExtension().run {
kotlin {
target("**/*.kt")
targetExclude(
"${layout.buildDirectory.get()}/**/*.kt",
"**/androidTest/**/*.kt",
"**/test/**/*.kt",
"bin/**/*.kt"
)
ktlint(libs.pintrest.ktlint.get().version)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
}

internal fun Project.configureAndroid(): Unit = baseExtension().run {
compileSdkVersion(34)
defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package co.anitrend.arch.buildSrc.plugin.components

import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.jetbrains.dokka.gradle.DokkaTask
import co.anitrend.arch.buildSrc.module.Modules
import co.anitrend.arch.buildSrc.plugin.extensions.*
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.invoke
import org.gradle.kotlin.dsl.named
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import java.net.URL

private fun Project.dependenciesOfProject(): List<Modules.Module> {
Expand Down Expand Up @@ -59,49 +54,11 @@ private fun Project.dependenciesOfProject(): List<Modules.Module> {
}
}

private fun Project.createMavenPublicationUsing(sources: Jar) {
publishingExtension().publications {
val component = components.findByName("android")

val projectName = this@createMavenPublicationUsing.name

logger.lifecycle("Configuring maven publication options for ${path}:maven with component -> ${component?.name}")
create("maven", MavenPublication::class.java) {
groupId = "co.anitrend.arch"
artifactId = projectName
version = props[PropertyTypes.VERSION]

artifact(sources)
artifact("${layout.buildDirectory.get()}/outputs/aar/${projectName}-release.aar")
from(component)

pom {
name.set("support-arch")
description.set("A multi-module template library that attempts to make clean arch apps easier to build")
url.set("https://github.com/anitrend/support-arch")
licenses {
license {
name.set("Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("wax911")
name.set("Maxwell Mapako")
organizationUrl.set("https://github.com/anitrend")
}
}
}
}
}
}

private fun Project.createDokkaTaskProvider() = tasks.named<DokkaTask>("dokkaHtml") {
internal fun Project.configureDokka() = tasks.named<DokkaTask>("dokkaHtml") {
outputDirectory.set(layout.buildDirectory.dir("docs/dokka"))

// Set module name displayed in the final output
moduleName.set(this@createDokkaTaskProvider.name)
moduleName.set(project.name)

// Use default or set to custom path to cache directory
// to enable package-list caching
Expand Down Expand Up @@ -207,35 +164,4 @@ private fun Project.createDokkaTaskProvider() = tasks.named<DokkaTask>("dokkaHtm
}
}
}
}

internal fun Project.configureOptions() {
if (containsBasePlugin()) {
logger.lifecycle("Applying extension options for ${project.path}")

val mainSourceSets = when {
!isKotlinLibraryGroup() -> baseExtension().sourceSets["main"].java.srcDirs
else -> kotlinJvmProjectExtension().sourceSets["main"].kotlin.srcDirs()
}

logger.lifecycle("Applying additional tasks options for dokka and javadoc on ${project.path}")

createDokkaTaskProvider()

val sourcesJar by tasks.register("sourcesJar", Jar::class.java) {
archiveClassifier.set("sources")
from(mainSourceSets)
}

val classesJar by tasks.register("classesJar", Jar::class.java) {
from("${project.layout.buildDirectory.get()}/intermediates/classes/release")
}

artifacts {
add("archives", classesJar)
add("archives", sourcesJar)
}

createMavenPublicationUsing(sourcesJar)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package co.anitrend.arch.buildSrc.plugin.components

import co.anitrend.arch.buildSrc.plugin.extensions.props
import co.anitrend.arch.buildSrc.plugin.extensions.publishingExtension
import org.gradle.api.Project
import org.gradle.api.publish.maven.MavenPublication


internal fun Project.configureMaven() {
publishingExtension().publications {
val component = components.findByName("java")

logger.lifecycle("Configuring maven publication options for ${path}:maven with component -> ${component?.name}")
create("maven", MavenPublication::class.java) {
groupId = "co.anitrend.arch"
artifactId = project.name
version = props[PropertyTypes.VERSION]

from(component)

pom {
name.set("support-arch")
description.set("A multi-module template library that attempts to make clean arch apps easier to build")
url.set("https://github.com/anitrend/support-arch")
licenses {
license {
name.set("Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("wax911")
name.set("Maxwell Mapako")
organizationUrl.set("https://github.com/anitrend")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package co.anitrend.arch.buildSrc.plugin.components

import co.anitrend.arch.buildSrc.plugin.extensions.baseExtension
import co.anitrend.arch.buildSrc.plugin.extensions.isKotlinLibraryGroup
import co.anitrend.arch.buildSrc.plugin.extensions.kotlinJvmProjectExtension
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.provideDelegate

internal fun Project.configureSources() {
val mainSourceSets = when {
!isKotlinLibraryGroup() -> baseExtension().sourceSets["main"].java.srcDirs
else -> kotlinJvmProjectExtension().sourceSets["main"].kotlin.srcDirs()
}

val sourcesJar by tasks.register("sourcesJar", Jar::class.java) {
archiveClassifier.set("sources")
from(mainSourceSets)
}

val classesJar by tasks.register("classesJar", Jar::class.java) {
from("${project.layout.buildDirectory.get()}/intermediates/classes/release")
}

artifacts {
add("archives", classesJar)
add("archives", sourcesJar)
}

afterEvaluate {
configureMaven()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.anitrend.arch.buildSrc.plugin.components

import co.anitrend.arch.buildSrc.plugin.extensions.libs
import co.anitrend.arch.buildSrc.plugin.extensions.spotlessExtension
import org.gradle.api.Project


internal fun Project.configureSpotless(): Unit = spotlessExtension().run {
kotlin {
target("**/*.kt")
targetExclude(
"${layout.buildDirectory.get()}/**/*.kt",
"**/androidTest/**/*.kt",
"**/test/**/*.kt",
"bin/**/*.kt"
)
ktlint(libs.pintrest.ktlint.get().version)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import co.anitrend.arch.domain.entities.LoadState
*
* @property model observable model from a use case output
* @property loadState observable network state from underlying sources
* @property refreshState observable network refresh state from underlying sources
*
* @param R type of your [model]
*
Expand All @@ -33,7 +32,6 @@ import co.anitrend.arch.domain.entities.LoadState
interface ISupportViewModelState<R> {
val model: LiveData<R>
val loadState: LiveData<LoadState>
val refreshState: LiveData<LoadState>

/**
* Triggers use case to perform a retry operation
Expand All @@ -44,13 +42,4 @@ interface ISupportViewModelState<R> {
* Triggers use case to perform refresh operation
*/
suspend fun refresh()

/**
* Called upon [androidx.lifecycle.ViewModel.onCleared] and should optionally
* call cancellation of any ongoing jobs.
*
* If your use case source is of type [co.anitrend.arch.domain.common.IUseCase]
* then you could optionally call [co.anitrend.arch.domain.common.IUseCase.onCleared] here
*/
fun onCleared()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import co.anitrend.arch.request.callback.RequestCallback
*
* @since v1.1.0
*/
interface ISupportResponse<in RESOURCE, out RESPONSE> {
interface ISupportResponse<in I, out O> {
/**
* Response handler for coroutine contexts which need to observe [NetworkState]
* Response handler for coroutine contexts which need to observe [LoadState]
*
* @param resource awaiting execution
* @param requestCallback for the deferred result
*
* @return resource fetched if present
*/
suspend operator fun invoke(
resource: RESOURCE,
resource: I,
requestCallback: RequestCallback,
): RESPONSE?
): O?
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit cacbc80

Please sign in to comment.