Skip to content

Commit

Permalink
mustRunAfter assemle and bundle task without affect on configuration …
Browse files Browse the repository at this point in the history
…cache
  • Loading branch information
cosic committed Dec 8, 2023
1 parent f0d272c commit 02dab9e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 65 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildToolsVersion = "33.0.0"
kotlin = "1.8.0"
junitJupiter = "5.7.0"
androidGradlePlugin = "7.4.2"
sampleRustorePlugin = "0.2.0-SNAPSHOT"
sampleRustorePlugin = "0.2.2-SNAPSHOT"

[libraries]
appcompat = "androidx.appcompat:appcompat:1.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ class RustorePublishExtensionConfig(
var releaseTime: String? = null
var releasePhase: ReleasePhaseExtension? = null
var releaseNotes: List<ReleaseNote>? = null
var pluginSettings: PluginSettings = PluginSettings()

init {
if (name.isBlank()) {
throw IllegalArgumentException("Name must not be blank nor empty")
}
}

fun pluginSettings(closure: Closure<PluginSettings>): PluginSettings {
pluginSettings = PluginSettings()
project.configure(pluginSettings, closure)
return pluginSettings
}
fun releasePhase(closure: Closure<ReleasePhaseExtension>): ReleasePhaseExtension {
releasePhase = ReleasePhaseExtension()
project.configure(releasePhase!!, closure)
Expand All @@ -61,8 +55,7 @@ class RustorePublishExtensionConfig(
"buildFile='$buildFile', " +
"releaseTime='$releaseTime', " +
"releasePhase='$releasePhase', " +
"releaseNotes='$releaseNotes', " +
"pluginSettings='$pluginSettings'" +
"releaseNotes='$releaseNotes'" +
")"
}
}
Expand Down Expand Up @@ -104,24 +97,6 @@ open class ReleaseNote {
}
}

open class PluginSettings {

var applyConfigureOptimization: Boolean = true

constructor() {
// nothing;
}
constructor(applyConfigureOptimization: Boolean) {
this.applyConfigureOptimization = applyConfigureOptimization
}

override fun toString(): String {
return "PluginSettings(" +
"applyConfigureOptimization='$applyConfigureOptimization'" +
")"
}
}

enum class BuildFormat(val fileExtension: String) {
APK("apk"),
AAB("aab"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import org.gradle.kotlin.dsl.withType

class RustorePublishPlugin : Plugin<Project> {

private val tasksMustRunAfter = mutableMapOf<String, String>()

override fun apply(project: Project) {
project.plugins.withType<AppPlugin> {
configureRustorePublish(project)
Expand Down Expand Up @@ -44,45 +42,29 @@ class RustorePublishPlugin : Plugin<Project> {
val publishTaskName = "${RustorePublishTask.TASK_NAME}$variantName"
val publishTask = project.tasks.register<RustorePublishTask>(publishTaskName, variant)
val extension = rustorePublishExtension.instances.find { it.name.equals(variant.name, ignoreCase = true) }
val applyConfigureOptimization = extension?.pluginSettings?.applyConfigureOptimization
tasksMustRunAfter.put(publishTaskName, "assemble$variantName")
tasksMustRunAfter.put(publishTaskName, "bundle$variantName")

sheduleTasksOrder(applyConfigureOptimization, publishTask, project, variantName)
scheduleTasksOrder(publishTask, project, variantName)
}

private fun sheduleTasksOrder(
applyConfigureOptimization: Boolean?,
private fun scheduleTasksOrder(
publishTask: TaskProvider<RustorePublishTask>,
project: Project,
variantName: String
) {
if (applyConfigureOptimization == true) {
publishTask.configure {
// println("--> RustorePublishTask registered: ($publishTaskName)")
// project.tasks.forEach {
// println("--> (1): ${it.name}")
// }
// setMustRunAfter(
// setOf(
//// project.tasks.named("clean"),
// project.tasks.named("assemble$variantName"),
// project.tasks.named("bundle$variantName"),
// )
// )
if (project.tasks.findByName("assemble$variantName") != null) {
setMustRunAfter(setOf(project.tasks.named("assemble$variantName")))
}
if (project.tasks.findByName("bundle$variantName") != null) {
setMustRunAfter(setOf(project.tasks.named("bundle$variantName")))
}
}
} else {
project.tasks.whenTaskAdded {
if (this.name == "assemble$variantName" || this.name == "bundle$variantName") {
publishTask.get().mustRunAfter(this)
}
}
project.gradle.projectsEvaluated {
mustRunAfter(project, publishTask, "assemble$variantName")
mustRunAfter(project, publishTask, "bundle$variantName")
}
}

private fun mustRunAfter(
project: Project,
publishTask: TaskProvider<RustorePublishTask>,
taskBeforeName: String,
) {
if (project.tasks.findByName(taskBeforeName) != null) {
val assembleTask = project.tasks.named(taskBeforeName).get()
publishTask.get().mustRunAfter(assembleTask)
}
}
}
3 changes: 0 additions & 3 deletions sample-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ rustorePublish {
filePath = "$projectDir/release-notes-ru.txt"
),
)
pluginSettings = ru.cian.rustore.publish.PluginSettings(
applyConfigureOptimization = true
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include(

pluginManagement {

val rustorePublish = "0.2.0-SNAPSHOT"
val rustorePublish = "0.2.2-SNAPSHOT"

resolutionStrategy {
eachPlugin {
Expand Down

0 comments on commit 02dab9e

Please sign in to comment.