Pill: Refactor Pill variants, replace DEFAULT variant with nullable value
This commit is contained in:
@@ -10,26 +10,16 @@ import java.io.File
|
||||
import org.gradle.api.Project
|
||||
|
||||
open class PillExtension {
|
||||
/*
|
||||
* Here's how you can specify a custom variant:
|
||||
* `./gradlew pill -Dpill.variant=<NAME>`
|
||||
*/
|
||||
enum class Variant {
|
||||
// Default variant (./gradlew pill)
|
||||
BASE {
|
||||
override val includes = setOf(BASE)
|
||||
},
|
||||
|
||||
// Full variant (./gradlew pill -Dpill.variant=full)
|
||||
FULL {
|
||||
override val includes = setOf(BASE, FULL)
|
||||
},
|
||||
|
||||
// 'BASE' if the "jps-compatible" plugin is applied, 'NONE' otherwise
|
||||
DEFAULT {
|
||||
override val includes = emptySet<Variant>()
|
||||
};
|
||||
|
||||
abstract val includes: Set<Variant>
|
||||
BASE, // Includes compiler and IDE (default)
|
||||
FULL, // Includes compiler, IDE and Gradle plugin
|
||||
}
|
||||
|
||||
open var variant: Variant = Variant.DEFAULT
|
||||
open var variant: Variant? = null
|
||||
|
||||
open var excludedDirs: List<File> = emptyList()
|
||||
|
||||
@@ -40,7 +30,7 @@ open class PillExtension {
|
||||
|
||||
@Suppress("unused")
|
||||
fun serialize() = mapOf<String, Any?>(
|
||||
"variant" to variant.name,
|
||||
"variant" to variant?.name,
|
||||
"excludedDirs" to excludedDirs
|
||||
)
|
||||
}
|
||||
@@ -86,11 +86,6 @@ class JpsCompatiblePluginTasks(private val rootProject: Project, private val pla
|
||||
|
||||
rootProject.logger.lifecycle("Pill: Setting up project for the '${variant.name.toLowerCase()}' variant...")
|
||||
|
||||
if (variant == PillExtensionMirror.Variant.DEFAULT) {
|
||||
rootProject.logger.error("'none' and 'default' should not be passed as a Pill variant property value")
|
||||
return
|
||||
}
|
||||
|
||||
val parserContext = ParserContext(variant)
|
||||
|
||||
val dependencyPatcher = DependencyPatcher(rootProject)
|
||||
|
||||
@@ -8,26 +8,14 @@ package org.jetbrains.kotlin.pill
|
||||
import java.io.File
|
||||
import org.gradle.api.Project
|
||||
|
||||
open class PillExtensionMirror(variant: String, val excludedDirs: List<File>) {
|
||||
val variant = Variant.valueOf(variant)
|
||||
open class PillExtensionMirror(variant: String?, val excludedDirs: List<File>) {
|
||||
val variant = if (variant == null) null else Variant.valueOf(variant)
|
||||
|
||||
enum class Variant {
|
||||
// Default variant (./gradlew pill)
|
||||
BASE {
|
||||
override val includes = setOf(BASE)
|
||||
},
|
||||
enum class Variant(includesFactory: () -> Set<Variant>) {
|
||||
BASE({ setOf(BASE) }), // Includes compiler and IDE (default)
|
||||
FULL({ setOf(BASE, FULL) }); // Includes compiler, IDE and Gradle plugin
|
||||
|
||||
// Full variant (./gradlew pill -Dpill.variant=full)
|
||||
FULL {
|
||||
override val includes = setOf(BASE, FULL)
|
||||
},
|
||||
|
||||
// 'BASE' if the "jps-compatible" plugin is applied, 'NONE' otherwise
|
||||
DEFAULT {
|
||||
override val includes = emptySet<Variant>()
|
||||
};
|
||||
|
||||
abstract val includes: Set<Variant>
|
||||
val includes by lazy { includesFactory() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +25,10 @@ fun Project.findPillExtensionMirror(): PillExtensionMirror? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val serialized = ext::class.java.getMethod("serialize").invoke(ext) as Map<String, Any>
|
||||
|
||||
val variant = serialized["variant"] as String
|
||||
val variant = serialized["variant"] as String?
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val excludedDirs = serialized["excludedDirs"] as List<File>
|
||||
|
||||
val constructor = PillExtensionMirror::class.java.declaredConstructors.single()
|
||||
return constructor.newInstance(variant, excludedDirs) as PillExtensionMirror
|
||||
return PillExtensionMirror(variant, excludedDirs)
|
||||
}
|
||||
@@ -114,7 +114,7 @@ fun parse(project: Project, context: ParserContext): PProject = with(context) {
|
||||
|
||||
fun Project.matchesSelectedVariant(): Boolean {
|
||||
val extension = this.findPillExtensionMirror() ?: return true
|
||||
val projectVariant = extension.variant.takeUnless { it == Variant.DEFAULT } ?: Variant.BASE
|
||||
val projectVariant = extension.variant ?: Variant.BASE
|
||||
return projectVariant in context.variant.includes
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user