Wizard: validate project path for emptiness
#KT-38567 fixed
This commit is contained in:
+1
@@ -40,6 +40,7 @@ project.kind.singleplatform=Singleplatform project
|
||||
project=Project
|
||||
|
||||
plugin.structure.setting.location=Location
|
||||
plugin.structure.setting.location.error.is.not.empty=Directory is not empty
|
||||
plugin.structure.setting.name=Name
|
||||
plugin.structure.setting.group.id=Group ID
|
||||
plugin.structure.setting.artifact.id=Artifact ID
|
||||
|
||||
+4
-2
@@ -23,7 +23,8 @@ interface Setting<out V : Any, out T : SettingType<V>> : Entity, ActivityChecker
|
||||
val defaultValue: SettingDefaultValue<V>?
|
||||
val isRequired: Boolean
|
||||
val isSavable: Boolean
|
||||
var neededAtPhase: GenerationPhase
|
||||
val neededAtPhase: GenerationPhase
|
||||
val validateOnProjectCreation: Boolean
|
||||
val type: T
|
||||
}
|
||||
|
||||
@@ -34,8 +35,9 @@ data class InternalSetting<out V : Any, out T : SettingType<V>>(
|
||||
override val isAvailable: Checker,
|
||||
override val isRequired: Boolean,
|
||||
override val isSavable: Boolean,
|
||||
override var neededAtPhase: GenerationPhase,
|
||||
override val neededAtPhase: GenerationPhase,
|
||||
override val validator: SettingValidator<@UnsafeVariance V>,
|
||||
override val validateOnProjectCreation: Boolean,
|
||||
override val type: T
|
||||
) : Setting<V, T>, EntityWithValue<V>()
|
||||
|
||||
|
||||
+3
@@ -19,6 +19,8 @@ abstract class SettingBuilder<V : Any, T : SettingType<V>>(
|
||||
) {
|
||||
var isAvailable: Reader.() -> Boolean = { true }
|
||||
open var defaultValue: SettingDefaultValue<V>? = null
|
||||
|
||||
var validateOnProjectCreation = true
|
||||
var isSavable: Boolean = false
|
||||
var isRequired: Boolean? = null
|
||||
|
||||
@@ -51,6 +53,7 @@ abstract class SettingBuilder<V : Any, T : SettingType<V>>(
|
||||
isSavable = isSavable,
|
||||
neededAtPhase = neededAtPhase,
|
||||
validator = validator,
|
||||
validateOnProjectCreation = validateOnProjectCreation,
|
||||
type = type
|
||||
)
|
||||
}
|
||||
+11
@@ -4,12 +4,14 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins
|
||||
import org.jetbrains.kotlin.tools.projectWizard.KotlinNewProjectWizardBundle
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.StringValidators
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.PomIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
class StructurePlugin(context: Context) : Plugin(context) {
|
||||
@@ -18,6 +20,15 @@ class StructurePlugin(context: Context) : Plugin(context) {
|
||||
GenerationPhase.FIRST_STEP
|
||||
) {
|
||||
defaultValue = value(Paths.get("."))
|
||||
|
||||
validateOnProjectCreation = false
|
||||
|
||||
validate { path ->
|
||||
if (!Files.exists(path)) return@validate ValidationResult.OK
|
||||
ValidationResult.create(Files.list(path).noneMatch { true }) {
|
||||
KotlinNewProjectWizardBundle.message("plugin.structure.setting.location.error.is.not.empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
val name by stringSetting(
|
||||
KotlinNewProjectWizardBundle.message("plugin.structure.setting.name"),
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ abstract class Wizard(createPlugins: PluginsCreator, servicesManager: ServicesMa
|
||||
fun validate(phases: Set<GenerationPhase>): ValidationResult = context.read {
|
||||
pluginSettings.map { setting ->
|
||||
val value = setting.reference.notRequiredSettingValue ?: return@map ValidationResult.OK
|
||||
if (setting.neededAtPhase in phases && setting.isActive(this))
|
||||
if (setting.validateOnProjectCreation && setting.neededAtPhase in phases && setting.isActive(this))
|
||||
(setting.validator as SettingValidator<Any>).validate(this, value)
|
||||
else ValidationResult.OK
|
||||
}.fold()
|
||||
|
||||
Reference in New Issue
Block a user