Wizard: introduce unit test mode
This commit is contained in:
+4
-2
@@ -14,13 +14,15 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
class IdeWizard(
|
class IdeWizard(
|
||||||
createPlugins: PluginsCreator,
|
createPlugins: PluginsCreator,
|
||||||
initialServices: List<WizardService>
|
initialServices: List<WizardService>,
|
||||||
|
isUnitTestMode: Boolean
|
||||||
) : Wizard(
|
) : Wizard(
|
||||||
createPlugins,
|
createPlugins,
|
||||||
ServicesManager(initialServices) { services ->
|
ServicesManager(initialServices) { services ->
|
||||||
services.firstOrNull { it is IdeaWizardService }
|
services.firstOrNull { it is IdeaWizardService }
|
||||||
?: services.firstOrNull()
|
?: services.firstOrNull()
|
||||||
}
|
},
|
||||||
|
isUnitTestMode
|
||||||
) {
|
) {
|
||||||
private val allSettings = plugins.flatMap { it.declaredSettings }
|
private val allSettings = plugins.flatMap { it.declaredSettings }
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ import com.intellij.openapi.module.Module as IdeaModule
|
|||||||
|
|
||||||
|
|
||||||
class NewProjectWizardModuleBuilder : ModuleBuilder() {
|
class NewProjectWizardModuleBuilder : ModuleBuilder() {
|
||||||
private val wizard = IdeWizard(Plugins.allPlugins, IdeaServices.PROJECT_INDEPENDENT)
|
private val wizard = IdeWizard(Plugins.allPlugins, IdeaServices.PROJECT_INDEPENDENT, isUnitTestMode = false)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MODULE_BUILDER_ID = "kotlin.newProjectWizard.builder"
|
const val MODULE_BUILDER_ID = "kotlin.newProjectWizard.builder"
|
||||||
|
|||||||
+3
-2
@@ -14,12 +14,13 @@ import java.nio.file.Paths
|
|||||||
class YamlWizard(
|
class YamlWizard(
|
||||||
private val yaml: String,
|
private val yaml: String,
|
||||||
private val path: String,
|
private val path: String,
|
||||||
createPlugins: (Context) -> List<Plugin>
|
createPlugins: (Context) -> List<Plugin>,
|
||||||
|
isUnitTestMode: Boolean
|
||||||
) : Wizard(
|
) : Wizard(
|
||||||
createPlugins,
|
createPlugins,
|
||||||
ServicesManager(Services.IDEA_INDEPENDENT_SERVICES) { services ->
|
ServicesManager(Services.IDEA_INDEPENDENT_SERVICES) { services ->
|
||||||
services.firstOrNull { it is IdeaIndependentWizardService }
|
services.firstOrNull { it is IdeaIndependentWizardService }
|
||||||
}
|
}, isUnitTestMode
|
||||||
) {
|
) {
|
||||||
override fun apply(
|
override fun apply(
|
||||||
services: List<WizardService>,
|
services: List<WizardService>,
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ kotlin:
|
|||||||
modules:
|
modules:
|
||||||
- type:
|
- type:
|
||||||
name: android
|
name: android
|
||||||
androidSdkPath: /home/ilya/Android/Sdk
|
androidSdkPath: /home/user/Android/Sdk
|
||||||
kind: singleplatform
|
kind: singleplatform
|
||||||
name: android
|
name: android
|
||||||
sourcesets:
|
sourcesets:
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ abstract class AbstractBuildFileGenerationTest : AbstractPluginBasedTest() {
|
|||||||
defaultStructure + "\n" +
|
defaultStructure + "\n" +
|
||||||
buildSystem.yaml
|
buildSystem.yaml
|
||||||
val tempDir = Files.createTempDirectory(null)
|
val tempDir = Files.createTempDirectory(null)
|
||||||
val wizard = YamlWizard(yaml, tempDir.toString(), testData.createPlugins)
|
val wizard = YamlWizard(yaml, tempDir.toString(), testData.createPlugins, isUnitTestMode = true)
|
||||||
val result = wizard.apply(Services.IDEA_INDEPENDENT_SERVICES, GenerationPhase.ALL)
|
val result = wizard.apply(Services.IDEA_INDEPENDENT_SERVICES, GenerationPhase.ALL)
|
||||||
result.onFailure { errors ->
|
result.onFailure { errors ->
|
||||||
errors.forEach { error ->
|
errors.forEach { error ->
|
||||||
|
|||||||
+3
-2
@@ -7,8 +7,9 @@ import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
|
|||||||
|
|
||||||
class TaskRunningContext(
|
class TaskRunningContext(
|
||||||
context: Context,
|
context: Context,
|
||||||
servicesManager: ServicesManager
|
servicesManager: ServicesManager,
|
||||||
) : ValuesReadingContext(context, servicesManager) {
|
isUnitTestMode: Boolean
|
||||||
|
) : ValuesReadingContext(context, servicesManager, isUnitTestMode) {
|
||||||
fun <A, B : Any> Task1Reference<A, B>.execute(value: A): TaskResult<B> {
|
fun <A, B : Any> Task1Reference<A, B>.execute(value: A): TaskResult<B> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val task = context.taskContext.getEntity(this) as Task1<A, B>
|
val task = context.taskContext.getEntity(this) as Task1<A, B>
|
||||||
|
|||||||
+5
-2
@@ -6,8 +6,11 @@ import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
open class ValuesReadingContext(
|
||||||
open class ValuesReadingContext(val context: Context, private val servicesManager: ServicesManager) {
|
val context: Context,
|
||||||
|
private val servicesManager: ServicesManager,
|
||||||
|
val isUnitTestMode: Boolean
|
||||||
|
) {
|
||||||
inline fun <reified S : WizardService> service(noinline filter: (S) -> Boolean = { true }) = serviceByClass(S::class, filter)
|
inline fun <reified S : WizardService> service(noinline filter: (S) -> Boolean = { true }) = serviceByClass(S::class, filter)
|
||||||
|
|
||||||
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean = { true }) =
|
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean = { true }) =
|
||||||
|
|||||||
+1
@@ -375,6 +375,7 @@ object PathSettingType : SettingType<Path>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun shouldExists() = validate { pathValue ->
|
fun shouldExists() = validate { pathValue ->
|
||||||
|
if (isUnitTestMode) return@validate ValidationResult.OK
|
||||||
if (!Files.exists(pathValue))
|
if (!Files.exists(pathValue))
|
||||||
ValidationResult.ValidationError("File for ${title.capitalize()} should exists")
|
ValidationResult.ValidationError("File for ${title.capitalize()} should exists")
|
||||||
else ValidationResult.OK
|
else ValidationResult.OK
|
||||||
|
|||||||
+3
-3
@@ -6,9 +6,9 @@ import org.jetbrains.kotlin.tools.projectWizard.core.service.WizardService
|
|||||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
|
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||||
|
|
||||||
abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: ServicesManager) {
|
abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: ServicesManager, private val isUnitTestMode: Boolean) {
|
||||||
val context = Context(createPlugins, EventManager())
|
val context = Context(createPlugins, EventManager())
|
||||||
val valuesReadingContext = ValuesReadingContext(context, servicesManager)
|
val valuesReadingContext = ValuesReadingContext(context, servicesManager, isUnitTestMode)
|
||||||
protected val plugins = context.plugins
|
protected val plugins = context.plugins
|
||||||
protected val pluginSettings = plugins.flatMap { it.declaredSettings }.distinctBy { it.path }
|
protected val pluginSettings = plugins.flatMap { it.declaredSettings }.distinctBy { it.path }
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: Servic
|
|||||||
onTaskExecuting: (PipelineTask) -> Unit = {}
|
onTaskExecuting: (PipelineTask) -> Unit = {}
|
||||||
): TaskResult<Unit> = computeM {
|
): TaskResult<Unit> = computeM {
|
||||||
context.checkAllRequiredSettingPresent(phases).ensure()
|
context.checkAllRequiredSettingPresent(phases).ensure()
|
||||||
val taskRunningContext = TaskRunningContext(context, servicesManager.withServices(services))
|
val taskRunningContext = TaskRunningContext(context, servicesManager.withServices(services), isUnitTestMode)
|
||||||
taskRunningContext.validate(phases).ensure()
|
taskRunningContext.validate(phases).ensure()
|
||||||
val (tasksSorted) = context.sortTasks().map { tasks ->
|
val (tasksSorted) = context.sortTasks().map { tasks ->
|
||||||
tasks.groupBy { it.phase }.toList().sortedBy { it.first }.flatMap { it.second }
|
tasks.groupBy { it.phase }.toList().sortedBy { it.first }.flatMap { it.second }
|
||||||
|
|||||||
Reference in New Issue
Block a user