8000 Added the ability to use eternal plugins with forma by ikarenkov · Pull Request #75 · formatools/forma · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added the ability to use eternal plugins with forma #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion application/binary/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ androidBinary(
target(":core:mvvm:library"),
target(":core:di:library")
)
)
)
// TODO: enable when create crashlytics project
// .withPlugins(Plugins.googleServices, Plugins.crashlytics())
1 change: 1 addition & 0 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ buildscript {
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.4.1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have native gradle script part here. I think need to another issue to research, how could migrate on Forma API only

}
}

Expand Down
1 change: 1 addition & 0 deletions application/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(project(":plugins:android"))
implementation(project(":plugins:deps-core"))
implementation("com.google.firebase:firebase-crashlytics-gradle:2.4.1")
}

repositories {
Expand Down
3 changes: 3 additions & 0 deletions application/buildSrc/src/main/java/Google.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ object google {
val gson = deps(
"com.google.code.gson:gson:${versions.google.gson}".dep
)

val firebase = transitivePlatform("com.google.firebase:firebase-bom:26.1.0")

}
21 changes: 21 additions & 0 deletions application/buildSrc/src/main/java/Plugins.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import tools.forma.android.plugin.PluginWrapper
import tools.forma.android.plugin.pluginConfiguration

object Plugins {

val navigationSafeArgs: PluginWrapper<Any> = PluginWrapper(
"androidx.navigation.safeargs.kotlin"
)

val googleServices = PluginWrapper<Any>("com.google.gms.google-services")

fun crashlytics(mappingFileUploadEnabled: Boolean = false) = PluginWrapper(
"com.google.firebase.crashlytics",
google.firebase,
pluginConfiguration<CrashlyticsExtension> {
this.mappingFileUploadEnabled = mappingFileUploadEnabled
}
)

}
5 changes: 1 addition & 4 deletions application/core/navigation/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ androidLibrary(
dependencies = deps(
androidx.navigation
)
)
// TODO https://github.com/formatools/forma/issues/35
// Need configurable plugin integration here
apply(plugin = "androidx.navigation.safeargs.kotlin")
).withPlugin(Plugins.navigationSafeArgs)
18 changes: 18 additions & 0 deletions plugins/android/src/main/java/TargetBuilder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import org.gradle.api.Project
import tools.forma.android.plugin.PluginWrapper

class TargetBuilder(
private val project: Project
) {

fun withPlugin(pluginWrapper: PluginWrapper<*>): TargetBuilder {
pluginWrapper(project)
return this
}

fun withPlugins(vararg pluginWrappers: PluginWrapper<*>): TargetBuilder {
pluginWrappers.forEach { withPlugin(it) }
return this
}

}
15 changes: 8 additions & 7 deletions plugins/android/src/main/java/androidBinary.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import org.gradle.api.Project
import tools.forma.android.feature.AndroidBinaryFeatureConfiguration
import tools.forma.android.feature.androidBinaryFeatureDefinition
import tools.forma.android.feature.applyFeatures
import tools.forma.android.target.BinaryTargetTemplate
import tools.forma.android.owner.NoOwner
import tools.forma.android.owner.Owner
import tools.forma.android.target.BinaryTargetTemplate
import tools.forma.android.utils.BuildConfiguration
import tools.forma.validation.EmptyValidator
import tools.forma.validation.validate
import tools.forma.android.owner.NoOwner
import tools.forma.android.validation.disallowResources
import tools.forma.deps.FormaDependency
import org.gradle.api.Project

import tools.forma.deps.applyDependencies
import tools.forma.validation.EmptyValidator
import tools.forma.validation.validate

/**
* Android Binary target - application entry point.
Expand All @@ -35,7 +34,7 @@ fun Project.androidBinary(
testInstrumentationRunner: String = androidJunitRunner,
consumerMinificationFiles: Set<String> = emptySet(),
manifestPlaceholders: Map<String, Any> = emptyMap()
) {
): TargetBuilder {

disallowResources()

Expand All @@ -57,5 +56,7 @@ fun Project.androidBinary(
dependencies = dependencies,
repositoriesConfiguration = Forma.configuration.repositories
)

return TargetBuilder(this)
}

14 changes: 8 additions & 6 deletions plugins/android/src/main/java/androidLibrary.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import org.gradle.api.Project
import tools.forma.android.feature.AndroidLibraryFeatureConfiguration
import tools.forma.android.feature.androidLibraryFeatureDefinition
import tools.forma.android.feature.applyFeatures
import tools.forma.android.feature.kaptConfigurationFeature
import tools.forma.android.feature.kotlinAndroidFeatureDefinition
import tools.forma.android.target.LibraryTargetTemplate
import tools.forma.android.owner.NoOwner
import tools.forma.android.owner.Owner
import tools.forma.android.target.LibraryTargetTemplate
import tools.forma.android.utils.BuildConfiguration
import tools.forma.validation.EmptyValidator
import tools.forma.validation.validate
import tools.forma.android.visibility.Public
import tools.forma.android.visibility.Visibility
import tools.forma.deps.FormaDependency
import tools.forma.deps.NamedDependency
import org.gradle.api.Project
import tools.forma.android.feature.kaptConfigurationFeature
import tools.forma.deps.applyDependencies
import tools.forma.validation.EmptyValidator
import tools.forma.validation.validate

/**
* TODO Can't depend on widgets, cant depend on databindings
Expand All @@ -30,7 +30,7 @@ fun Project.androidLibrary(
buildConfiguration: BuildConfiguration = BuildConfiguration(),
consumerMinificationFiles: Set<String> = emptySet(),
manifestPlaceholders: Map<String, Any> = emptyMap()
) {
): TargetBuilder {
target.validate(LibraryTargetTemplate)
val libraryFeatureConfiguration = AndroidLibraryFeatureConfiguration(
packageName,
Expand All @@ -52,5 +52,7 @@ fun Project.androidLibrary(
repositoriesConfiguration = Forma.configuration.repositories,
configurationFeatures = kaptConfigurationFeature()
)

return TargetBuilder(this)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools.forma.android.plugin

import kotlin.reflect.KClass

data class PluginConfiguration<TPluginExtension : Any>(
val extensionClass: KClass<TPluginExtension>,
val configuration: (TPluginExtension.() -> Unit)
)

inline fun <reified TPluginExtension : Any> pluginConfiguration(noinline configuration: (TPluginExtension.() -> Unit)) =
PluginConfiguration(TPluginExtension::class, configuration)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tools.forma.android.plugin

import Forma
import emptyDependency
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import

import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.the
import tools.forma.deps.FormaDependency
import tools.forma.deps.applyDependencies
import tools.forma.validation.EmptyValidator

class PluginWrapper<TPluginExtension : Any>(
private val pluginId: String,
private val dependencies: FormaDependency = emptyDependency(),
private val pluginConfiguration: PluginConfiguration<TPluginExtension>? = null
) {

operator fun invoke(project: Project) {
project.apply(plugin = pluginId)
pluginConfiguration?.let {
it.configuration(project.the(it.extensionClass))
}
project.applyDependencies(
validator = EmptyValidator,
dependencies = dependencies,
repositoriesConfiguration = Forma.configuration.repositories
)
}

}
36 changes: 23 additions & 13 deletions plugins/deps-core/src/main/java/dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import org.gradle.api.Project

import tools.forma.deps.ConfigurationType
import tools.forma.deps.DepType
import tools.forma.deps.EmptyDependency
import tools.forma.deps.FileDependency
import tools.forma.deps.FileSpec
import tools.forma.deps.NameSpec
import tools.forma.deps.TargetSpec
import tools.forma.deps.ConfigurationType
import tools.forma.deps.FormaDependency
import tools.forma.deps.Implementation
import tools.forma.deps.Kapt
import tools.forma.deps.FormaDependency
import tools.forma.deps.FileDependency
import tools.forma.deps.MixedDependency
import tools.forma.deps.EmptyDependency
import tools.forma.deps.TargetDependency
import tools.forma.deps.NameSpec
import tools.forma.deps.NamedDependency
import tools.forma.deps.PlatformDependency
import tools.forma.deps.PlatformSpec
import tools.forma.deps.TargetDependency
import tools.forma.deps.TargetSpec
import tools.forma.target.FormaTarget
import java.io.File

Expand Down Expand Up @@ -43,12 +44,14 @@ inline fun <reified T : FormaDependency> emptyDependency(): T = when {
fun FormaDependency.forEach(
nameAction: (NameSpec) -> Unit = {},
targetAction: (TargetSpec) -> Unit = {},
fileAction: (FileSpec) -> Unit = {}
fileAction: (FileSpec) -> Unit = {},
platformAction: (PlatformSpec) -> Unit = {}
) {
dependency.forEach loop@ { spec ->
dependency.forEach loop@{ spec ->
return@loop when (spec) {
is TargetSpec -> targetAction(spec)
is NameSpec -> nameAction(spec)
is PlatformSpec -> platformAction(spec)
is FileSpec -> fileAction(spec)
}
}
Expand All @@ -63,12 +66,19 @@ internal fun FormaDependency.hasConfigType(configType: ConfigurationType): Boole

fun deps(vararg names: String): NamedDependency = transitiveDeps(names = *names, transitive = false)

fun platform(vararg names: String): PlatformDependency = transitivePlatform(*names, transitive = false)

fun transitivePlatform(vararg names: String, transitive: Boolean = true): PlatformDependency =
PlatformDependency(names.toList().map { PlatformSpec(it, Implementation, transitive) })

fun transitiveDeps(vararg names: String, transitive: Boolean = true): NamedDependency =
NamedDependency(names.toList().map { NameSpec(it, Implementation, transitive) })

@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("Deprecated in favor of targets version of this function:\n" +
"deps(target(\":name\"))")
@Deprecated(
"Deprecated in favor of targets version of this function:\n" +
"deps(target(\":name\"))"
)
fun deps(vararg projects: Project): TargetDependency =
TargetDependency(projects.toList().map { TargetSpec(it.target, Implementation) })

Expand All @@ -93,5 +103,5 @@ val String.kapt: NamedDependency get() = kapt(this)

val Project.target: FormaTarget get() = FormaTarget(this)

fun Project.target(name: String) : FormaTarget = FormaTarget(project(name))
fun Project.target(name: String): FormaTarget = FormaTarget(project(name))

Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ class NameSpec(
val transitive: Boolean = false
) : DepSpec(config)

class PlatformSpec(
val name: String,
config: ConfigurationType,
val transitive: Boolean = false
) : DepSpec(config)

typealias DepType = List<DepSpec>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ fun DependencyHandler.addDependencyTo(
configuration
)

// TODO: only using for platform, maybe make addPlatformDependencyTo?
fun DependencyHandler.addDependencyTo(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats real different of this method from same signature upper? Is't only in one parameter Dependency instead on String?

configurationName: String,
dependency: Dependency,
configuration: (ExternalModuleDependency).() -> Unit
): ExternalModuleDependency = addDependencyTo(
this,
configurationName,
dependency,
configuration
)

/**
* Adds a dependency to the 'implementation' configuration.
*
Expand Down
D172
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ sealed class FormaDependency(

object EmptyDependency : FormaDependency()

class PlatformDependency(
val names: List<PlatformSpec> = emptyList()
) : FormaDependency(names)

class NamedDependency(
val names: List<NameSpec> = emptyList()
) : FormaDependency(names)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tools.forma.deps

import tools.forma.validation.Validator
import emptyDependency
import forEach
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.dependencies
import tools.forma.validation.Validator

fun Project.applyDependencies(
validator: Validator,
Expand All @@ -27,7 +27,8 @@ fun Project.applyDependencies(
addDependencyTo(it.config.name, it.name) { isTransitive = it.transitive }
},
projectAction,
{ add(it.config.name, files(it.file)) }
{ add(it.config.name, files(it.file)) },
{ addDependencyTo(it.config.name, platform(it.name)) { isTransitive = it.transitive } }
)
testDependencies.forEach(
{ addDependencyTo("testImplementation", it.name) { isTransitive = it.transitive } },
Expand Down
0