Skip to content

Commit

Permalink
configured replaceable decorator API on Gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfly committed Oct 29, 2023
1 parent 0edbeb1 commit 1db6dce
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.morfly.airin.plugin

import io.morfly.airin.AndroidProjectDecorator

class AirinAndroidGradlePlugin : AirinGradlePlugin() {
open class AirinAndroidGradlePlugin : AirinGradlePlugin() {

override val defaultDecoratorClass = AndroidProjectDecorator::class.java
override val defaultProjectDecorator = AndroidProjectDecorator::class.java

companion object {
const val ID = "io.morfly.airin.android"
Expand Down
6 changes: 6 additions & 0 deletions airin-gradle-plugin/src/main/kotlin/DslExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import io.morfly.airin.GradleFeatureComponent
import io.morfly.airin.GradlePackageComponent
import io.morfly.airin.GradleProjectDecorator
import io.morfly.airin.dsl.AirinExtension
import io.morfly.airin.dsl.FeatureComponentsHolder
import io.morfly.airin.dsl.PackageComponentsHolder
import org.gradle.api.Action
Expand All @@ -9,3 +11,7 @@ inline fun <reified C : GradlePackageComponent> PackageComponentsHolder.register

inline fun <reified C : GradleFeatureComponent> FeatureComponentsHolder.include(config: Action<C>? = null) =
include(C::class.java, config)

inline fun <reified D: GradleProjectDecorator> AirinExtension.decorateWith() {
projectDecorator = D::class.java
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import org.gradle.api.Project

interface GradleProjectDecorator {

fun GradleProject.decorate(target: Project)
fun GradleProject.decorate(target: Project) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.morfly.airin.Component
import io.morfly.airin.ComponentConflictResolution.UsePriority
import io.morfly.airin.ComponentId
import io.morfly.airin.GradleProject
import io.morfly.airin.GradleProjectDecorator
import io.morfly.airin.HasId
import io.morfly.airin.MissingComponentResolution.Ignore
import io.morfly.airin.PropertiesHolder
Expand All @@ -22,6 +23,7 @@ abstract class AirinExtension :

override val properties: MutableMap<String, Any?> = mutableMapOf()

override var projectDecorator: Class<out GradleProjectDecorator> by property(GradleProjectDecorator::class.java)
override var allowedConfigurations by property(
mutableSetOf("implementation", "api", "kapt", "ksp")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package io.morfly.airin.dsl

import io.morfly.airin.ComponentConflictResolution
import io.morfly.airin.ConfigurationName
import io.morfly.airin.GradleProjectDecorator
import io.morfly.airin.MissingComponentResolution

interface AirinProperties {
var projectDecorator: Class<out GradleProjectDecorator>
var allowedConfigurations: MutableSet<ConfigurationName>
var ignoredConfigurations: MutableSet<ConfigurationName>
var onComponentConflict: ComponentConflictResolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import io.morfly.airin.ConfigurationName
import io.morfly.airin.GradleFeatureComponent
import io.morfly.airin.GradlePackageComponent
import io.morfly.airin.GradleProject
import io.morfly.airin.GradleProjectDecorator
import io.morfly.airin.InternalAirinApi
import io.morfly.airin.MissingComponentResolution
import io.morfly.airin.GradleProjectDecorator
import io.morfly.airin.dsl.AirinExtension
import io.morfly.airin.dsl.AirinProperties
import io.morfly.airin.label.GradleLabel
Expand All @@ -25,7 +25,7 @@ import org.gradle.kotlin.dsl.register

abstract class AirinGradlePlugin : Plugin<Project> {

abstract val defaultDecoratorClass: Class<out GradleProjectDecorator>
abstract val defaultProjectDecorator: Class<out GradleProjectDecorator>

override fun apply(target: Project) {
require(target.rootProject.path == target.path) {
Expand All @@ -35,14 +35,17 @@ abstract class AirinGradlePlugin : Plugin<Project> {
val inputs = target.extensions.create<AirinExtension>(AirinExtension.NAME)

target.tasks.register<MigrateToBazelTask>(MigrateToBazelTask.NAME) {
val decoratorClass =
if (inputs.projectDecorator != GradleProjectDecorator::class.java) inputs.projectDecorator
else defaultProjectDecorator

val components = prepareComponents(inputs.subcomponents)
val decorator = inputs.objects.newInstance(defaultDecoratorClass)
val outputFiles = mutableListOf<RegularFile>()
val root = prepareProjects(
root = target,
components = components,
properties = inputs,
decorator = decorator,
decorator = inputs.objects.newInstance(decoratorClass),
outputFiles = outputFiles
)

Expand Down

0 comments on commit 1db6dce

Please sign in to comment.