diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c986eaa..355823b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,7 +29,6 @@ gradle-tooling-api = { module = "org.gradle:gradle-tooling-api", version.ref = " gradle-declarative-dsl-core = { module = "org.gradle:gradle-declarative-dsl-core", version.ref = "declarative-dsl" } gradle-declarative-dsl-evaluator = { module = "org.gradle:gradle-declarative-dsl-evaluator", version.ref = "declarative-dsl" } gradle-declarative-dsl-tooling-models = { module = "org.gradle:gradle-declarative-dsl-tooling-models", version.ref = "declarative-dsl" } -gradle-prototypes-plugins-android = { module = "org.gradle.experimental:plugin-android", version.ref = "unified-prototype" } material3WindowSizeClassMultiplatform = { module = "dev.chrisbanes.material3:material3-window-size-class-multiplatform", version = "0.3.1" } materialKolor = { module = "com.materialkolor:material-kolor", version = "1.4.4" } slf4j-api = { module = "org.slf4j:slf4j-api", version = "2.0.12" } diff --git a/mutations-demo/build.gradle.kts b/mutations-demo/build.gradle.kts index 1cf11a7..3286493 100644 --- a/mutations-demo/build.gradle.kts +++ b/mutations-demo/build.gradle.kts @@ -4,5 +4,4 @@ plugins { dependencies { implementation(libs.gradle.declarative.dsl.core) - implementation(libs.gradle.prototypes.plugins.android) } diff --git a/mutations-demo/src/main/kotlin/AndroidPrototypeMutationDefinition.kt b/mutations-demo/src/main/kotlin/AndroidPrototypeMutationDefinition.kt new file mode 100644 index 0000000..1ee64bd --- /dev/null +++ b/mutations-demo/src/main/kotlin/AndroidPrototypeMutationDefinition.kt @@ -0,0 +1,9 @@ +package org.gradle.client.demo.mutations + +import org.gradle.declarative.dsl.schema.AnalysisSchema +import org.gradle.internal.declarativedsl.dom.mutation.MutationDefinition + +interface AndroidPrototypeMutationDefinition : MutationDefinition { + override fun isCompatibleWithSchema(projectAnalysisSchema: AnalysisSchema): Boolean = + projectAnalysisSchema.hasAndroidPrototype() +} \ No newline at end of file diff --git a/mutations-demo/src/main/kotlin/MutationDefinitions.kt b/mutations-demo/src/main/kotlin/MutationDefinitions.kt index 91fa8e8..799a13b 100644 --- a/mutations-demo/src/main/kotlin/MutationDefinitions.kt +++ b/mutations-demo/src/main/kotlin/MutationDefinitions.kt @@ -1,18 +1,12 @@ package org.gradle.client.demo.mutations -import org.gradle.api.experimental.android.AndroidSoftware -import org.gradle.api.experimental.android.application.AndroidApplication -import org.gradle.api.experimental.android.extensions.testing.Testing -import org.gradle.api.experimental.android.library.AndroidLibrary import org.gradle.declarative.dsl.schema.AnalysisSchema import org.gradle.internal.declarativedsl.dom.mutation.* import org.gradle.internal.declarativedsl.dom.mutation.ModelMutation.IfPresentBehavior -import org.gradle.internal.declarativedsl.schemaUtils.findTypeFor import org.gradle.internal.declarativedsl.schemaUtils.propertyNamed import org.gradle.internal.declarativedsl.schemaUtils.singleFunctionNamed -import org.gradle.internal.declarativedsl.schemaUtils.typeFor -object SetVersionCodeMutation : MutationDefinition { +object SetVersionCodeMutation : AndroidPrototypeMutationDefinition { override val id: String = "org.gradle.client.demo.mutations.versionCode" override val name: String = "Set version code" override val description: String = "Update versionCode in androidApplication" @@ -23,13 +17,8 @@ object SetVersionCodeMutation : MutationDefinition { override val parameters: List> get() = listOf(versionCodeParam) - override fun isCompatibleWithSchema(projectAnalysisSchema: AnalysisSchema): Boolean = - hasAndroidSoftwareType(projectAnalysisSchema) - override fun defineModelMutationSequence(projectAnalysisSchema: AnalysisSchema): List = with(projectAnalysisSchema) { - val androidApplication = typeFor() - listOf( ModelMutationRequest( ScopeLocation.inAnyScope().inObjectsOfType(androidApplication), @@ -43,7 +32,7 @@ object SetVersionCodeMutation : MutationDefinition { } } -object SetNamespaceMutation : MutationDefinition { +object SetNamespaceMutation : AndroidPrototypeMutationDefinition { override val id: String = "org.gradle.client.demo.mutations.namespace" override val name: String = "Set the library namespace" override val description: String = "Updates the namespace in an Android library" @@ -54,18 +43,13 @@ object SetNamespaceMutation : MutationDefinition { override val parameters: List> get() = listOf(newNamespaceParam) - override fun isCompatibleWithSchema(projectAnalysisSchema: AnalysisSchema): Boolean = - hasAndroidSoftwareType(projectAnalysisSchema) - override fun defineModelMutationSequence(projectAnalysisSchema: AnalysisSchema): List = with(projectAnalysisSchema) { - val android = typeFor() - listOf( ModelMutationRequest( - ScopeLocation.inAnyScope().inObjectsOfType(android), + ScopeLocation.inAnyScope().inObjectsOfType(androidSoftware), ModelMutation.SetPropertyValue( - android.propertyNamed("namespace"), + androidSoftware.propertyNamed("namespace"), NewValueNodeProvider.ArgumentBased { args -> valueFromString("\"" + args[newNamespaceParam] + "\"")!! }, @@ -80,20 +64,16 @@ val addTestingDependencyMutation = AddDependencyMutation( "org.gradle.client.demo.mutations.addDependency.testing" ) { - val android = typeFor() - ScopeLocation.fromTopLevel() - .inObjectsOfType(android) - .inObjectsConfiguredBy(android.singleFunctionNamed("testing")) - .inObjectsConfiguredBy(typeFor().singleFunctionNamed("dependencies")) + .inObjectsOfType(androidSoftware) + .inObjectsConfiguredBy(androidSoftware.singleFunctionNamed("testing")) + .inObjectsConfiguredBy(testing.singleFunctionNamed("dependencies")) } val addLibraryDependencyMutation = AddDependencyMutation( "org.gradle.client.demo.mutations.addDependency.topLevel.library" ) { - val androidLibrary = typeFor() - ScopeLocation.fromTopLevel() .inObjectsOfType(androidLibrary) .inObjectsConfiguredBy(androidLibrary.singleFunctionNamed("dependencies")) @@ -103,15 +83,15 @@ val addApplicationDependencyMutation = AddDependencyMutation( "org.gradle.client.demo.mutations.addDependency.topLevel.application" ) { - val androidApplication = typeFor() - ScopeLocation.fromTopLevel() .inObjectsOfType(androidApplication) .inObjectsConfiguredBy(androidApplication.singleFunctionNamed("dependencies")) } -class AddDependencyMutation(override val id: String, private val scopeLocation: AnalysisSchema.() -> ScopeLocation) : - MutationDefinition { +class AddDependencyMutation( + override val id: String, + private val scopeLocation: AnalysisSchema.() -> ScopeLocation +) : AndroidPrototypeMutationDefinition { override val name: String = "Add a dependency" override val description: String = "Add a dependency to the dependencies block" @@ -125,9 +105,6 @@ class AddDependencyMutation(override val id: String, private val scopeLocation: override val parameters: List> get() = listOf(dependencyCoordinatesParam) - override fun isCompatibleWithSchema(projectAnalysisSchema: AnalysisSchema): Boolean = - hasAndroidSoftwareType(projectAnalysisSchema) - override fun defineModelMutationSequence(projectAnalysisSchema: AnalysisSchema): List = listOf( ModelMutationRequest( @@ -140,6 +117,3 @@ class AddDependencyMutation(override val id: String, private val scopeLocation: ) ) } - -private fun hasAndroidSoftwareType(projectAnalysisSchema: AnalysisSchema) = - projectAnalysisSchema.findTypeFor() != null \ No newline at end of file diff --git a/mutations-demo/src/main/kotlin/SchemaAccessors.kt b/mutations-demo/src/main/kotlin/SchemaAccessors.kt new file mode 100644 index 0000000..f98ad4e --- /dev/null +++ b/mutations-demo/src/main/kotlin/SchemaAccessors.kt @@ -0,0 +1,27 @@ +package org.gradle.client.demo.mutations + +import org.gradle.declarative.dsl.schema.AnalysisSchema +import org.gradle.declarative.dsl.schema.DataClass + +fun AnalysisSchema.hasAndroidPrototype(): Boolean = + dataClassesByFqName.keys.any { it.qualifiedName == "org.gradle.api.experimental.android.AndroidSoftware" } + +val AnalysisSchema.androidApplication: DataClass + get() = dataClassesByFqName.entries.single { + it.key.qualifiedName == "org.gradle.api.experimental.android.application.AndroidApplication" + }.value + +val AnalysisSchema.androidLibrary: DataClass + get() = dataClassesByFqName.entries.single { + it.key.qualifiedName == "org.gradle.api.experimental.android.library.AndroidLibrary" + }.value + +val AnalysisSchema.androidSoftware: DataClass + get() = dataClassesByFqName.entries.single { + it.key.qualifiedName == "org.gradle.api.experimental.android.AndroidSoftware" + }.value + +val AnalysisSchema.testing: DataClass + get() = dataClassesByFqName.entries.single { + it.key.qualifiedName == "org.gradle.api.experimental.android.extensions.testing.Testing" + }.value \ No newline at end of file