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