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
|
import org.gradle.api.Project
|
||||||
|
|
||||||
open class PillExtension {
|
open class PillExtension {
|
||||||
|
/*
|
||||||
|
* Here's how you can specify a custom variant:
|
||||||
|
* `./gradlew pill -Dpill.variant=<NAME>`
|
||||||
|
*/
|
||||||
enum class Variant {
|
enum class Variant {
|
||||||
// Default variant (./gradlew pill)
|
BASE, // Includes compiler and IDE (default)
|
||||||
BASE {
|
FULL, // Includes compiler, IDE and Gradle plugin
|
||||||
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>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open var variant: Variant = Variant.DEFAULT
|
open var variant: Variant? = null
|
||||||
|
|
||||||
open var excludedDirs: List<File> = emptyList()
|
open var excludedDirs: List<File> = emptyList()
|
||||||
|
|
||||||
@@ -40,7 +30,7 @@ open class PillExtension {
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun serialize() = mapOf<String, Any?>(
|
fun serialize() = mapOf<String, Any?>(
|
||||||
"variant" to variant.name,
|
"variant" to variant?.name,
|
||||||
"excludedDirs" to excludedDirs
|
"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...")
|
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 parserContext = ParserContext(variant)
|
||||||
|
|
||||||
val dependencyPatcher = DependencyPatcher(rootProject)
|
val dependencyPatcher = DependencyPatcher(rootProject)
|
||||||
|
|||||||
@@ -8,26 +8,14 @@ package org.jetbrains.kotlin.pill
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
|
||||||
open class PillExtensionMirror(variant: String, val excludedDirs: List<File>) {
|
open class PillExtensionMirror(variant: String?, val excludedDirs: List<File>) {
|
||||||
val variant = Variant.valueOf(variant)
|
val variant = if (variant == null) null else Variant.valueOf(variant)
|
||||||
|
|
||||||
enum class Variant {
|
enum class Variant(includesFactory: () -> Set<Variant>) {
|
||||||
// Default variant (./gradlew pill)
|
BASE({ setOf(BASE) }), // Includes compiler and IDE (default)
|
||||||
BASE {
|
FULL({ setOf(BASE, FULL) }); // Includes compiler, IDE and Gradle plugin
|
||||||
override val includes = setOf(BASE)
|
|
||||||
},
|
|
||||||
|
|
||||||
// Full variant (./gradlew pill -Dpill.variant=full)
|
val includes by lazy { includesFactory() }
|
||||||
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>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,11 +25,10 @@ fun Project.findPillExtensionMirror(): PillExtensionMirror? {
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val serialized = ext::class.java.getMethod("serialize").invoke(ext) as Map<String, Any>
|
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")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val excludedDirs = serialized["excludedDirs"] as List<File>
|
val excludedDirs = serialized["excludedDirs"] as List<File>
|
||||||
|
|
||||||
val constructor = PillExtensionMirror::class.java.declaredConstructors.single()
|
return PillExtensionMirror(variant, excludedDirs)
|
||||||
return constructor.newInstance(variant, excludedDirs) as PillExtensionMirror
|
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ fun parse(project: Project, context: ParserContext): PProject = with(context) {
|
|||||||
|
|
||||||
fun Project.matchesSelectedVariant(): Boolean {
|
fun Project.matchesSelectedVariant(): Boolean {
|
||||||
val extension = this.findPillExtensionMirror() ?: return true
|
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
|
return projectVariant in context.variant.includes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user