Android Extensions: Allow to disable specific features of Android Extensions (#KT-23244)
This commit is contained in:
+16
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.util.Configurable
|
||||
import java.util.*
|
||||
|
||||
enum class CacheImplementation(val optionName: String) {
|
||||
HASH_MAP("hashMap"),
|
||||
@@ -25,6 +26,19 @@ enum class CacheImplementation(val optionName: String) {
|
||||
NONE("none")
|
||||
}
|
||||
|
||||
enum class AndroidExtensionsFeature(val featureName: String) {
|
||||
VIEWS("views"),
|
||||
PARCELIZE("parcelize");
|
||||
|
||||
internal companion object {
|
||||
internal fun parseFeatures(features: Set<String>): SortedSet<AndroidExtensionsFeature> {
|
||||
fun find(name: String) = AndroidExtensionsFeature.values().firstOrNull { it.featureName == name }
|
||||
?: error("Can't find Android Extensions feature $name")
|
||||
return features.mapTo(sortedSetOf()) { find(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class AndroidExtensionsExtension : Configurable<AndroidExtensionsExtension> {
|
||||
private lateinit var onEvaluatedHandler: (AndroidExtensionsExtension) -> Unit
|
||||
|
||||
@@ -34,6 +48,8 @@ open class AndroidExtensionsExtension : Configurable<AndroidExtensionsExtension>
|
||||
|
||||
open var isExperimental: Boolean = false
|
||||
|
||||
open var features: Set<String> = AndroidExtensionsFeature.values().mapTo(mutableSetOf()) { it.featureName }
|
||||
|
||||
open var defaultCacheImplementation: CacheImplementation = CacheImplementation.HASH_MAP
|
||||
|
||||
override fun configure(closure: Closure<*>): AndroidExtensionsExtension {
|
||||
|
||||
+5
@@ -104,6 +104,7 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
val sourceSets = androidExtension.sourceSets
|
||||
|
||||
val pluginOptions = arrayListOf<SubpluginOption>()
|
||||
pluginOptions += SubpluginOption("features", AndroidExtensionsFeature.VIEWS.featureName)
|
||||
|
||||
val mainSourceSet = sourceSets.getByName("main")
|
||||
val manifestFile = mainSourceSet.manifest.srcFile
|
||||
@@ -157,6 +158,8 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
androidProjectHandler as? AbstractAndroidProjectHandler<Any?> ?: return emptyList()
|
||||
|
||||
val pluginOptions = arrayListOf<SubpluginOption>()
|
||||
pluginOptions += SubpluginOption("features",
|
||||
AndroidExtensionsFeature.parseFeatures(androidExtensionsExtension.features).joinToString(",") { it.featureName })
|
||||
|
||||
pluginOptions += SubpluginOption("experimental", "true")
|
||||
pluginOptions += SubpluginOption("defaultCacheImplementation", androidExtensionsExtension.defaultCacheImplementation.optionName)
|
||||
@@ -208,6 +211,8 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
addVariant(sourceSetName, (srcDirs - commonResDirectories).sorted())
|
||||
}
|
||||
|
||||
project.logger.warn("Blah: " + allResDirectories)
|
||||
|
||||
return wrapPluginOptions(pluginOptions, "configuration")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user