Wizard: refactoring: rename contexts
TaskRunningContext -> WriteContext, ValuesReadingContext -> ReadingContext
This commit is contained in:
+2
-2
@@ -10,14 +10,14 @@ import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunCo
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.tools.projectWizard.WizardGradleRunConfiguration
|
||||
import org.jetbrains.kotlin.tools.projectWizard.WizardRunConfiguration
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.RunConfigurationsService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.isBuildSystemAvailable
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType
|
||||
|
||||
class IdeaRunConfigurationsService(private val project: Project) : RunConfigurationsService, IdeaWizardService {
|
||||
override fun ValuesReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>) {
|
||||
override fun ReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>) {
|
||||
configurations.forEach { wizardConfiguration ->
|
||||
if (wizardConfiguration is WizardGradleRunConfiguration && isBuildSystemAvailable(BuildSystemType.GradleKotlinDsl)) {
|
||||
addGradleRunConfiguration(wizardConfiguration)
|
||||
|
||||
+8
-8
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
|
||||
abstract class Component : Displayable {
|
||||
@@ -15,11 +15,11 @@ abstract class Component : Displayable {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DynamicComponent(private val valuesReadingContext: ValuesReadingContext) : Component() {
|
||||
abstract class DynamicComponent(private val readingContext: ReadingContext) : Component() {
|
||||
//TODO do not use it in future
|
||||
protected val context = valuesReadingContext.context
|
||||
protected val context = readingContext.context
|
||||
protected val eventManager
|
||||
get() = valuesReadingContext.context.eventManager
|
||||
get() = readingContext.context.eventManager
|
||||
|
||||
private var isInitialized: Boolean = false
|
||||
|
||||
@@ -29,7 +29,7 @@ abstract class DynamicComponent(private val valuesReadingContext: ValuesReadingC
|
||||
}
|
||||
|
||||
var <V : Any, T : SettingType<V>> SettingReference<V, T>.value: V?
|
||||
get() = with(valuesReadingContext) { notRequiredSettingValue() }
|
||||
get() = with(readingContext) { notRequiredSettingValue() }
|
||||
set(value) {
|
||||
with(context) { settingContext[this@value] = value!! }
|
||||
}
|
||||
@@ -38,13 +38,13 @@ abstract class DynamicComponent(private val valuesReadingContext: ValuesReadingC
|
||||
get() = reference.value
|
||||
|
||||
init {
|
||||
valuesReadingContext.context.eventManager.addSettingUpdaterEventListener { reference ->
|
||||
readingContext.context.eventManager.addSettingUpdaterEventListener { reference ->
|
||||
if (isInitialized) onValueUpdated(reference)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun <T> read(reader: ValuesReadingContext.() -> T): T =
|
||||
reader(valuesReadingContext)
|
||||
protected fun <T> read(reader: ReadingContext.() -> T): T =
|
||||
reader(readingContext)
|
||||
|
||||
open fun onValueUpdated(reference: SettingReference<*, *>?) {}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui
|
||||
|
||||
import com.intellij.ui.components.panels.VerticalLayout
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.StringSettingComponent
|
||||
@@ -9,22 +9,22 @@ import javax.swing.Box
|
||||
import javax.swing.JSeparator
|
||||
import javax.swing.SwingConstants
|
||||
|
||||
class PomWizardStepComponent(valuesReadingContext: ValuesReadingContext) : WizardStepComponent(valuesReadingContext) {
|
||||
class PomWizardStepComponent(readingContext: ReadingContext) : WizardStepComponent(readingContext) {
|
||||
private val groupIdComponent = StringSettingComponent(
|
||||
StructurePlugin::groupId.reference,
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
showLabel = true
|
||||
).asSubComponent()
|
||||
|
||||
private val artifactIdComponent = StringSettingComponent(
|
||||
StructurePlugin::artifactId.reference,
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
showLabel = true
|
||||
).asSubComponent()
|
||||
|
||||
private val versionComponent = StringSettingComponent(
|
||||
StructurePlugin::version.reference,
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
showLabel = true
|
||||
).asSubComponent()
|
||||
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import java.awt.BorderLayout
|
||||
import javax.swing.JComponent
|
||||
|
||||
abstract class SubStep(
|
||||
val valuesReadingContext: ValuesReadingContext
|
||||
) : DynamicComponent(valuesReadingContext) {
|
||||
val readingContext: ReadingContext
|
||||
) : DynamicComponent(readingContext) {
|
||||
protected abstract fun buildContent(): JComponent
|
||||
|
||||
final override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
|
||||
abstract class WizardStepComponent(
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
) : DynamicComponent(valuesReadingContext)
|
||||
readingContext: ReadingContext
|
||||
) : DynamicComponent(readingContext)
|
||||
+3
-5
@@ -1,19 +1,17 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
|
||||
import com.intellij.ui.components.JBCheckBox
|
||||
import com.intellij.ui.components.JBTextField
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.textField
|
||||
|
||||
class CheckboxComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
labelText: String? = null,
|
||||
initialValue: Boolean? = null,
|
||||
validator: SettingValidator<Boolean>? = null,
|
||||
onValueUpdate: (Boolean) -> Unit = {}
|
||||
) : UIComponent<Boolean>(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
labelText,
|
||||
validator,
|
||||
onValueUpdate
|
||||
|
||||
+4
-5
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
import com.intellij.openapi.ui.ComboBox
|
||||
import com.intellij.ui.ColoredListCellRenderer
|
||||
import com.intellij.ui.SimpleTextAttributes
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settingValidator
|
||||
@@ -12,11 +12,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.awt.event.ItemEvent
|
||||
import javax.swing.DefaultComboBoxModel
|
||||
import javax.swing.Icon
|
||||
import javax.swing.JComboBox
|
||||
import javax.swing.JList
|
||||
|
||||
class DropDownComponent<T : DisplayableSettingItem>(
|
||||
private val valuesReadingContext: ValuesReadingContext,
|
||||
private val readingContext: ReadingContext,
|
||||
initialValues: List<T> = emptyList(),
|
||||
labelText: String? = null,
|
||||
private val filter: (T) -> Boolean = { true },
|
||||
@@ -24,7 +23,7 @@ class DropDownComponent<T : DisplayableSettingItem>(
|
||||
private val iconProvider: (T) -> Icon? = { null },
|
||||
onValueUpdate: (T) -> Unit = {}
|
||||
) : UIComponent<T>(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
labelText,
|
||||
validator,
|
||||
onValueUpdate
|
||||
@@ -48,7 +47,7 @@ class DropDownComponent<T : DisplayableSettingItem>(
|
||||
append(" $it", SimpleTextAttributes.GRAYED_ATTRIBUTES)
|
||||
}
|
||||
if (this@apply.selectedItem != value) {
|
||||
validator.validate(valuesReadingContext, value)
|
||||
validator.validate(readingContext, value)
|
||||
.safeAs<ValidationResult.ValidationError>()
|
||||
?.messages
|
||||
?.firstOrNull()
|
||||
|
||||
+3
-11
@@ -3,29 +3,21 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
|
||||
import com.intellij.openapi.ui.TextBrowseFolderListener
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.StringValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settingValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.Component
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.panel
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.textField
|
||||
import java.awt.BorderLayout
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import javax.swing.Icon
|
||||
import javax.swing.JComponent
|
||||
|
||||
class PathFieldComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
labelText: String? = null,
|
||||
initialValue: Path? = null,
|
||||
validator: SettingValidator<Path>? = null,
|
||||
onValueUpdate: (Path) -> Unit = {}
|
||||
) : UIComponent<Path>(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
labelText,
|
||||
validator,
|
||||
onValueUpdate
|
||||
|
||||
+3
-3
@@ -1,18 +1,18 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
|
||||
import com.intellij.ui.components.JBTextField
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.textField
|
||||
|
||||
class TextFieldComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
labelText: String? = null,
|
||||
initialValue: String? = null,
|
||||
validator: SettingValidator<String>? = null,
|
||||
onValueUpdate: (String) -> Unit = {}
|
||||
) : UIComponent<String>(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
labelText,
|
||||
validator,
|
||||
onValueUpdate
|
||||
|
||||
+6
-7
@@ -6,9 +6,8 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.SettingSavingWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.DynamicComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.FocusableComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.label
|
||||
@@ -19,11 +18,11 @@ import java.awt.BorderLayout
|
||||
import javax.swing.JComponent
|
||||
|
||||
abstract class UIComponent<V : Any>(
|
||||
private val valuesReadingContext: ValuesReadingContext,
|
||||
private val readingContext: ReadingContext,
|
||||
labelText: String? = null,
|
||||
private val validator: SettingValidator<V>? = null,
|
||||
private val onValueUpdate: (V) -> Unit = {}
|
||||
) : DynamicComponent(valuesReadingContext), ErrorAwareComponent, FocusableComponent, Disposable {
|
||||
) : DynamicComponent(readingContext), ErrorAwareComponent, FocusableComponent, Disposable {
|
||||
private val validationIndicator by lazy(LazyThreadSafetyMode.NONE) {
|
||||
if (validator != null)
|
||||
IdeaBasedComponentValidator(this, getValidatorTarget())
|
||||
@@ -70,7 +69,7 @@ abstract class UIComponent<V : Any>(
|
||||
fun validate(value: V) {
|
||||
if (validator == null) return
|
||||
if (validationIndicator == null) return
|
||||
validationIndicator?.updateValidationState(validator.validate(valuesReadingContext, value))
|
||||
validationIndicator?.updateValidationState(validator.validate(readingContext, value))
|
||||
}
|
||||
|
||||
override fun focusOn() {
|
||||
@@ -78,11 +77,11 @@ abstract class UIComponent<V : Any>(
|
||||
}
|
||||
|
||||
override fun findComponentWithError(error: ValidationResult.ValidationError): FocusableComponent? = takeIf {
|
||||
getUiValue()?.let { validator?.validate?.invoke(valuesReadingContext, it)?.isSpecificError(error) } == true
|
||||
getUiValue()?.let { validator?.validate?.invoke(readingContext, it)?.isSpecificError(error) } == true
|
||||
}
|
||||
}
|
||||
|
||||
fun <V : Any> ValuesReadingContext.valueForSetting(
|
||||
fun <V : Any> ReadingContext.valueForSetting(
|
||||
uiComponent: UIComponent<V>,
|
||||
setting: Setting<V, SettingType<V>>
|
||||
): V? = setting.savedOrDefaultValue ?: uiComponent.getUiValue()
|
||||
+5
-10
@@ -6,31 +6,26 @@ import icons.OpenapiIcons
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.DropDownSettingType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components.DropDownComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components.valueForSetting
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.panel
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.UIComponentDelegatingSettingComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator
|
||||
import java.awt.BorderLayout
|
||||
|
||||
|
||||
class BuildSystemTypeSettingComponent(
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
readingContext: ReadingContext
|
||||
) : UIComponentDelegatingSettingComponent<BuildSystemType, DropDownSettingType<BuildSystemType>>(
|
||||
BuildSystemPlugin::type.reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val uiComponent: DropDownComponent<BuildSystemType> = DropDownComponent(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
setting.type.values,
|
||||
labelText = "Build System",
|
||||
filter = { value -> setting.type.filter(valuesReadingContext, reference, value) },
|
||||
filter = { value -> setting.type.filter(readingContext, reference, value) },
|
||||
validator = setting.validator,
|
||||
iconProvider = BuildSystemType::icon,
|
||||
onValueUpdate = { value = it }
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
@@ -22,19 +22,19 @@ class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.v
|
||||
}
|
||||
}
|
||||
|
||||
class BuildSystemSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
SubStep(valuesReadingContext) {
|
||||
private val buildSystemSetting = BuildSystemTypeSettingComponent(valuesReadingContext).asSubComponent()
|
||||
class BuildSystemSubStep(readingContext: ReadingContext) :
|
||||
SubStep(readingContext) {
|
||||
private val buildSystemSetting = BuildSystemTypeSettingComponent(readingContext).asSubComponent()
|
||||
|
||||
override fun buildContent(): JComponent = panel {
|
||||
add(buildSystemSetting.component, BorderLayout.CENTER)
|
||||
}
|
||||
}
|
||||
|
||||
class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
SubStep(valuesReadingContext) {
|
||||
class TemplatesSubStep(readingContext: ReadingContext) :
|
||||
SubStep(readingContext) {
|
||||
private val projectTemplateSettingComponent =
|
||||
ProjectTemplateSettingComponent(valuesReadingContext) { projectTemplate ->
|
||||
ProjectTemplateSettingComponent(readingContext) { projectTemplate ->
|
||||
templateDescriptionComponent.setTemplate(projectTemplate)
|
||||
}.asSubComponent()
|
||||
|
||||
@@ -57,7 +57,7 @@ class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
}
|
||||
read {
|
||||
allModules().forEach { module ->
|
||||
module.apply { initDefaultValuesForSettings(valuesReadingContext.context) }
|
||||
module.apply { initDefaultValuesForSettings(readingContext.context) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class TemplatesSubStep(valuesReadingContext: ValuesReadingContext) :
|
||||
module.subModules.forEach(::addModule)
|
||||
}
|
||||
|
||||
valuesReadingContext.context.settingContext[KotlinPlugin::modules.reference]
|
||||
readingContext.context.settingContext[KotlinPlugin::modules.reference]
|
||||
?.forEach(::addModule)
|
||||
|
||||
return modules
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.DropDownSettingType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectTemplates.ProjectTemplatesPlugin
|
||||
@@ -13,11 +13,11 @@ import javax.swing.BorderFactory
|
||||
import javax.swing.JComponent
|
||||
|
||||
class ProjectTemplateSettingComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
private val onSelected: (ProjectTemplate) -> Unit
|
||||
) : SettingComponent<ProjectTemplate, DropDownSettingType<ProjectTemplate>>(
|
||||
ProjectTemplatesPlugin::template.reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val validationIndicator: ValidationIndicator? get() = null
|
||||
|
||||
|
||||
+6
-7
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep
|
||||
|
||||
import com.intellij.ui.components.JBTabbedPane
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.StringValidators
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.getConfiguratorSettings
|
||||
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module.Companion.ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.DynamicComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.FocusableComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components.TextFieldComponent
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.panel
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingsList
|
||||
@@ -20,15 +19,15 @@ import java.awt.BorderLayout
|
||||
import javax.swing.JComponent
|
||||
|
||||
class ModuleSettingsComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
uiEditorUsagesStats: UiEditorUsageStats
|
||||
) : DynamicComponent(valuesReadingContext) {
|
||||
) : DynamicComponent(readingContext) {
|
||||
private val validateModuleName =
|
||||
StringValidators.shouldNotBeBlank("Module name") and
|
||||
StringValidators.shouldBeValidIdentifier("Module Name", ALLOWED_SPECIAL_CHARS_IN_MODULE_NAMES)
|
||||
|
||||
private val moduleConfiguratorSettingsList = SettingsList(emptyList(), valuesReadingContext).asSubComponent()
|
||||
private val templateComponent = TemplatesComponent(valuesReadingContext, uiEditorUsagesStats).asSubComponent()
|
||||
private val moduleConfiguratorSettingsList = SettingsList(emptyList(), readingContext).asSubComponent()
|
||||
private val templateComponent = TemplatesComponent(readingContext, uiEditorUsagesStats).asSubComponent()
|
||||
|
||||
private val tabPanel = JBTabbedPane().apply {
|
||||
add("Template", templateComponent.component)
|
||||
@@ -43,7 +42,7 @@ class ModuleSettingsComponent(
|
||||
}
|
||||
|
||||
private val nameField = TextFieldComponent(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
labelText = "Name",
|
||||
onValueUpdate = { value ->
|
||||
module?.name = value
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep
|
||||
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
@@ -35,13 +35,13 @@ class SecondStepWizardComponent(
|
||||
|
||||
|
||||
class ModulesEditorSubStep(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
uiEditorUsagesStats: UiEditorUsageStats,
|
||||
onNodeSelected: (data: DisplayableSettingItem?) -> Unit,
|
||||
selectSettingWithError: (ValidationResult.ValidationError) -> Unit
|
||||
) : SubStep(valuesReadingContext) {
|
||||
) : SubStep(readingContext) {
|
||||
private val moduleSettingComponent = ModulesEditorComponent(
|
||||
valuesReadingContext,
|
||||
readingContext,
|
||||
uiEditorUsagesStats,
|
||||
onNodeSelected,
|
||||
selectSettingWithError
|
||||
@@ -63,7 +63,7 @@ class ModuleSettingsSubStep(
|
||||
uiEditorUsagesStats: UiEditorUsageStats
|
||||
) : SubStep(wizard.valuesReadingContext) {
|
||||
private val sourcesetSettingsComponent = SourcesetSettingsComponent(wizard.valuesReadingContext).asSubComponent()
|
||||
private val moduleSettingsComponent = ModuleSettingsComponent(valuesReadingContext, uiEditorUsagesStats).asSubComponent()
|
||||
private val moduleSettingsComponent = ModuleSettingsComponent(readingContext, uiEditorUsagesStats).asSubComponent()
|
||||
private val nothingSelectedComponent = NothingSelectedComponent().asSubComponent()
|
||||
|
||||
private val panel = panel {
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ import com.intellij.openapi.ui.DialogWrapper
|
||||
import com.intellij.ui.ColoredListCellRenderer
|
||||
import com.intellij.ui.SimpleTextAttributes
|
||||
import com.intellij.ui.ToolbarDecorator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.AndroidSinglePlatformModuleConfigurator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.IOSSinglePlatformModuleConfigurator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
@@ -18,8 +18,8 @@ import java.awt.Dimension
|
||||
import javax.swing.JComponent
|
||||
|
||||
class SourcesetDependenciesSettingsComponent(
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
) : DynamicComponent(valuesReadingContext) {
|
||||
readingContext: ReadingContext
|
||||
) : DynamicComponent(readingContext) {
|
||||
private val sourcesetDependenciesList = SourcesetDependenciesList()
|
||||
|
||||
private val toolbarDecorator: ToolbarDecorator = ToolbarDecorator.createDecorator(sourcesetDependenciesList).apply {
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep
|
||||
|
||||
import com.intellij.ui.components.JBTabbedPane
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Sourceset
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.DynamicComponent
|
||||
|
||||
class SourcesetSettingsComponent(valuesReadingContext: ValuesReadingContext) : DynamicComponent(valuesReadingContext) {
|
||||
private val dependenciesComponent = SourcesetDependenciesSettingsComponent(valuesReadingContext).asSubComponent()
|
||||
class SourcesetSettingsComponent(readingContext: ReadingContext) : DynamicComponent(readingContext) {
|
||||
private val dependenciesComponent = SourcesetDependenciesSettingsComponent(readingContext).asSubComponent()
|
||||
|
||||
override val component = JBTabbedPane().apply {
|
||||
add("Dependencies", dependenciesComponent.component)
|
||||
|
||||
+11
-11
@@ -9,7 +9,7 @@ import com.intellij.util.ui.StatusText
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.kotlin.idea.KotlinIcons
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.moduleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
@@ -26,17 +26,17 @@ import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
|
||||
class TemplatesComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
uiEditorUsagesStats: UiEditorUsageStats
|
||||
) : DynamicComponent(valuesReadingContext), ErrorAwareComponent {
|
||||
) : DynamicComponent(readingContext), ErrorAwareComponent {
|
||||
private val chooseTemplateComponent: ChooseTemplateComponent =
|
||||
ChooseTemplateComponent(valuesReadingContext) { template ->
|
||||
ChooseTemplateComponent(readingContext) { template ->
|
||||
uiEditorUsagesStats.moduleTemplatesSet++
|
||||
module?.template = template
|
||||
switchState(template)
|
||||
}
|
||||
|
||||
private val templateSettingsComponent = TemplateSettingsComponent(valuesReadingContext) {
|
||||
private val templateSettingsComponent = TemplateSettingsComponent(readingContext) {
|
||||
if (MessagesEx.showOkCancelDialog(
|
||||
component,
|
||||
"Do you want to remove selected template from module",
|
||||
@@ -84,9 +84,9 @@ class TemplatesComponent(
|
||||
}
|
||||
|
||||
class ChooseTemplateComponent(
|
||||
private val valuesReadingContext: ValuesReadingContext,
|
||||
private val readingContext: ReadingContext,
|
||||
private val onTemplateChosen: (Template) -> Unit
|
||||
) : DynamicComponent(valuesReadingContext) {
|
||||
) : DynamicComponent(readingContext) {
|
||||
private enum class State(val text: String) {
|
||||
MODULE_SELECTED_AND_TEMPLATES_AVAILABLE("You can configure a template for selected module"),
|
||||
MODULE_SELECTED_AND_NO_TEMPLATES_AVAILABLE("No templates available for selected module"),
|
||||
@@ -105,7 +105,7 @@ class ChooseTemplateComponent(
|
||||
}
|
||||
|
||||
private val allTemplates
|
||||
get() = with(valuesReadingContext) {
|
||||
get() = with(readingContext) {
|
||||
TemplatesPlugin::templates.propertyValue
|
||||
}
|
||||
|
||||
@@ -247,9 +247,9 @@ class TemplateDescriptionComponent(
|
||||
}
|
||||
|
||||
private class TemplateSettingsComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
removeTemplate: () -> Unit
|
||||
) : DynamicComponent(valuesReadingContext), ErrorAwareComponent {
|
||||
) : DynamicComponent(readingContext), ErrorAwareComponent {
|
||||
private val templateDescriptionComponent = TemplateDescriptionComponent(
|
||||
needRemoveButton = true,
|
||||
nonDefaultBackgroundColor = UIUtil.getEditorPaneBackground(),
|
||||
@@ -258,7 +258,7 @@ private class TemplateSettingsComponent(
|
||||
component.bordered(needTopEmptyBorder = false, needBottomEmptyBorder = false)
|
||||
}
|
||||
|
||||
private val settings = SettingsList(emptyList(), valuesReadingContext).apply {
|
||||
private val settings = SettingsList(emptyList(), readingContext).apply {
|
||||
component.bordered()
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEdi
|
||||
import com.intellij.ui.JBColor
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ListSettingType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
@@ -19,11 +19,11 @@ import javax.swing.JComponent
|
||||
|
||||
|
||||
class ModulesEditorComponent(
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
uiEditorUsagesStats: UiEditorUsageStats,
|
||||
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit,
|
||||
selectSettingWithError: (ValidationResult.ValidationError) -> Unit
|
||||
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, valuesReadingContext) {
|
||||
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, readingContext) {
|
||||
private val tree: ModulesEditorTree =
|
||||
ModulesEditorTree(
|
||||
onSelected = { oneEntrySelected(it) },
|
||||
@@ -41,7 +41,7 @@ class ModulesEditorComponent(
|
||||
}
|
||||
)
|
||||
|
||||
private val model = TargetsModel(tree, ::value, valuesReadingContext, uiEditorUsagesStats)
|
||||
private val model = TargetsModel(tree, ::value, readingContext, uiEditorUsagesStats)
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
|
||||
+3
-4
@@ -1,8 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor
|
||||
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
@@ -13,7 +12,7 @@ import kotlin.reflect.KMutableProperty0
|
||||
class TargetsModel(
|
||||
private val tree: ModulesEditorTree,
|
||||
private val value: KMutableProperty0<List<Module>?>,
|
||||
private val valuesReadingContext: ValuesReadingContext,
|
||||
private val readingContext: ReadingContext,
|
||||
private val uiEditorUsagesStats: UiEditorUsageStats
|
||||
) {
|
||||
private val root get() = tree.model.root as DefaultMutableTreeNode
|
||||
@@ -65,7 +64,7 @@ class TargetsModel(
|
||||
|
||||
fun add(module: Module) {
|
||||
uiEditorUsagesStats.modulesCreated++
|
||||
with(valuesReadingContext) {
|
||||
with(readingContext) {
|
||||
module.apply { initDefaultValuesForSettings(context) }
|
||||
}
|
||||
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
|
||||
|
||||
+22
-22
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting
|
||||
|
||||
import com.intellij.openapi.ui.ComboBox
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
||||
@@ -19,32 +19,32 @@ object DefaultSettingComponent {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <V : Any, T : SettingType<V>> create(
|
||||
setting: SettingReference<V, T>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
readingContext: ReadingContext
|
||||
): SettingComponent<V, T> = when (setting.type) {
|
||||
VersionSettingType::class ->
|
||||
VersionSettingComponent(
|
||||
setting as SettingReference<Version, VersionSettingType>,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) as SettingComponent<V, T>
|
||||
BooleanSettingType::class ->
|
||||
BooleanSettingComponent(
|
||||
setting as SettingReference<Boolean, BooleanSettingType>,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) as SettingComponent<V, T>
|
||||
DropDownSettingType::class ->
|
||||
DropdownSettingComponent(
|
||||
setting as SettingReference<DisplayableSettingItem, DropDownSettingType<DisplayableSettingItem>>,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) as SettingComponent<V, T>
|
||||
StringSettingType::class ->
|
||||
StringSettingComponent(
|
||||
setting as SettingReference<String, StringSettingType>,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) as SettingComponent<V, T>
|
||||
PathSettingType::class ->
|
||||
PathSettingComponent(
|
||||
setting as SettingReference<Path, PathSettingType>,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) as SettingComponent<V, T>
|
||||
else -> TODO(setting.type.qualifiedName!!)
|
||||
}
|
||||
@@ -52,8 +52,8 @@ object DefaultSettingComponent {
|
||||
|
||||
class VersionSettingComponent(
|
||||
reference: SettingReference<Version, VersionSettingType>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
) : SettingComponent<Version, VersionSettingType>(reference, valuesReadingContext) {
|
||||
readingContext: ReadingContext
|
||||
) : SettingComponent<Version, VersionSettingType>(reference, readingContext) {
|
||||
private val settingLabel = label(setting.title)
|
||||
private val comboBox = ComboBox<Version>().apply {
|
||||
addItemListener { e ->
|
||||
@@ -90,17 +90,17 @@ class VersionSettingComponent(
|
||||
|
||||
class DropdownSettingComponent(
|
||||
reference: SettingReference<DisplayableSettingItem, DropDownSettingType<DisplayableSettingItem>>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
readingContext: ReadingContext
|
||||
) : UIComponentDelegatingSettingComponent<DisplayableSettingItem, DropDownSettingType<DisplayableSettingItem>>(
|
||||
reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val uiComponent = DropDownComponent(
|
||||
valuesReadingContext = valuesReadingContext,
|
||||
readingContext = readingContext,
|
||||
initialValues = setting.type.values,
|
||||
validator = setting.validator,
|
||||
filter = { value ->
|
||||
setting.type.filter(valuesReadingContext, reference, value)
|
||||
setting.type.filter(readingContext, reference, value)
|
||||
},
|
||||
labelText = setting.title,
|
||||
onValueUpdate = { newValue -> value = newValue }
|
||||
@@ -109,13 +109,13 @@ class DropdownSettingComponent(
|
||||
|
||||
class BooleanSettingComponent(
|
||||
reference: SettingReference<Boolean, BooleanSettingType>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
readingContext: ReadingContext
|
||||
) : UIComponentDelegatingSettingComponent<Boolean, BooleanSettingType>(
|
||||
reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val uiComponent = CheckboxComponent(
|
||||
valuesReadingContext = valuesReadingContext,
|
||||
readingContext = readingContext,
|
||||
labelText = setting.title,
|
||||
initialValue = null,
|
||||
validator = setting.validator,
|
||||
@@ -125,14 +125,14 @@ class BooleanSettingComponent(
|
||||
|
||||
class StringSettingComponent(
|
||||
reference: SettingReference<String, StringSettingType>,
|
||||
valuesReadingContext: ValuesReadingContext,
|
||||
readingContext: ReadingContext,
|
||||
showLabel: Boolean = true
|
||||
) : UIComponentDelegatingSettingComponent<String, StringSettingType>(
|
||||
reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val uiComponent = TextFieldComponent(
|
||||
valuesReadingContext = valuesReadingContext,
|
||||
readingContext = readingContext,
|
||||
initialValue = null,
|
||||
labelText = if (showLabel) setting.title else null,
|
||||
validator = setting.validator,
|
||||
@@ -142,13 +142,13 @@ class StringSettingComponent(
|
||||
|
||||
class PathSettingComponent(
|
||||
reference: SettingReference<Path, PathSettingType>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
readingContext: ReadingContext
|
||||
) : UIComponentDelegatingSettingComponent<Path, PathSettingType>(
|
||||
reference,
|
||||
valuesReadingContext
|
||||
readingContext
|
||||
) {
|
||||
override val uiComponent = PathFieldComponent(
|
||||
valuesReadingContext = valuesReadingContext,
|
||||
readingContext = readingContext,
|
||||
labelText = setting.title,
|
||||
validator = settingValidator { path -> setting.validator.validate(this, path) },
|
||||
onValueUpdate = { newValue -> value = newValue }
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.Displayable
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.DynamicComponent
|
||||
@@ -8,8 +8,8 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.FocusableComponent
|
||||
|
||||
abstract class SettingComponent<V : Any, T: SettingType<V>>(
|
||||
val reference: SettingReference<V, T>,
|
||||
val valuesReadingContext: ValuesReadingContext
|
||||
) : DynamicComponent(valuesReadingContext), Displayable, FocusableComponent {
|
||||
val readingContext: ReadingContext
|
||||
) : DynamicComponent(readingContext), Displayable, FocusableComponent {
|
||||
var value: V?
|
||||
get() = reference.value
|
||||
set(value) {
|
||||
@@ -17,7 +17,7 @@ abstract class SettingComponent<V : Any, T: SettingType<V>>(
|
||||
}
|
||||
|
||||
val setting: Setting<V, T>
|
||||
get() = with(valuesReadingContext.context) {
|
||||
get() = with(readingContext.context) {
|
||||
with(reference) { getSetting() }
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ abstract class SettingComponent<V : Any, T: SettingType<V>>(
|
||||
}
|
||||
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
component.isVisible = setting.isActive(valuesReadingContext)
|
||||
component.isVisible = setting.isActive(readingContext)
|
||||
updateValidationState()
|
||||
}
|
||||
|
||||
private fun updateValidationState() {
|
||||
val value = value
|
||||
if (validationIndicator != null && value != null) {
|
||||
validationIndicator!!.updateValidationState(setting.validator.validate(valuesReadingContext, value))
|
||||
validationIndicator!!.updateValidationState(setting.validator.validate(readingContext, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting
|
||||
|
||||
import com.intellij.ui.components.panels.VerticalLayout
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.isSpecificError
|
||||
@@ -16,8 +16,8 @@ interface ErrorAwareComponent {
|
||||
|
||||
class SettingsList(
|
||||
settings: List<SettingReference<*, *>>,
|
||||
private val valuesReadingContext: ValuesReadingContext
|
||||
) : DynamicComponent(valuesReadingContext), ErrorAwareComponent {
|
||||
private val readingContext: ReadingContext
|
||||
) : DynamicComponent(readingContext), ErrorAwareComponent {
|
||||
private val panel = PanelWithStatusText(VerticalLayout(5), "This module has no settings to configure")
|
||||
|
||||
var settingComponents: List<SettingComponent<*, *>> = emptyList()
|
||||
@@ -38,7 +38,7 @@ class SettingsList(
|
||||
panel.isStatusTextVisible = settings.isEmpty()
|
||||
panel.removeAll()
|
||||
settingComponents = settings.map { setting ->
|
||||
DefaultSettingComponent.create(setting, valuesReadingContext)
|
||||
DefaultSettingComponent.create(setting, readingContext)
|
||||
}
|
||||
settingComponents.forEach { setting -> setting.onInit(); panel.add(setting.component) }
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class SettingsList(
|
||||
override fun findComponentWithError(error: ValidationResult.ValidationError) =
|
||||
settingComponents.firstOrNull { component ->
|
||||
val value = component.value ?: return@firstOrNull false
|
||||
val result = component.setting.validator.validate(valuesReadingContext, value)
|
||||
val result = component.setting.validator.validate(readingContext, value)
|
||||
result isSpecificError error
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.components.UIComponent
|
||||
@@ -14,8 +14,8 @@ import javax.swing.JComponent
|
||||
|
||||
abstract class UIComponentDelegatingSettingComponent<V : Any, T : SettingType<V>>(
|
||||
reference: SettingReference<V, T>,
|
||||
valuesReadingContext: ValuesReadingContext
|
||||
) : SettingComponent<V, T>(reference, valuesReadingContext) {
|
||||
readingContext: ReadingContext
|
||||
) : SettingComponent<V, T>(reference, readingContext) {
|
||||
abstract val uiComponent: UIComponent<V>
|
||||
|
||||
// As there is one in UIComponent
|
||||
|
||||
-1
@@ -2,7 +2,6 @@ package org.jetbrains.kotlin.tools.projectWizard
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.EntitiesOwnerDescriptor
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Parser
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
|
||||
+5
-5
@@ -5,14 +5,14 @@ import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingType
|
||||
|
||||
|
||||
sealed class CheckerRule {
|
||||
abstract fun check(context: ValuesReadingContext): Boolean
|
||||
abstract fun check(context: ReadingContext): Boolean
|
||||
}
|
||||
|
||||
data class RuleBySettingValue(
|
||||
val settingReference: SettingReference<Any, SettingType<Any>>,
|
||||
val expectedValue: Any
|
||||
) : CheckerRule() {
|
||||
override fun check(context: ValuesReadingContext): Boolean = with(context) {
|
||||
override fun check(context: ReadingContext): Boolean = with(context) {
|
||||
settingReference.notRequiredSettingValue() == expectedValue
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,11 @@ data class OrRule(
|
||||
val left: CheckerRule,
|
||||
val right: CheckerRule
|
||||
) : CheckerRule() {
|
||||
override fun check(context: ValuesReadingContext): Boolean = left.check(context) || right.check(context)
|
||||
override fun check(context: ReadingContext): Boolean = left.check(context) || right.check(context)
|
||||
}
|
||||
|
||||
data class Checker(val rules: List<CheckerRule>) {
|
||||
fun check(context: ValuesReadingContext) =
|
||||
fun check(context: ReadingContext) =
|
||||
rules.all { rule -> rule.check(context) }
|
||||
|
||||
class Builder {
|
||||
@@ -64,5 +64,5 @@ interface ContextOwner {
|
||||
interface ActivityCheckerOwner {
|
||||
val activityChecker: Checker
|
||||
|
||||
fun isActive(valuesReadingContext: ValuesReadingContext) = activityChecker.check(valuesReadingContext)
|
||||
fun isActive(readingContext: ReadingContext) = activityChecker.check(readingContext)
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.service.SettingSavingWizard
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
open class ValuesReadingContext(
|
||||
open class ReadingContext(
|
||||
val context: Context,
|
||||
private val servicesManager: ServicesManager,
|
||||
val isUnitTestMode: Boolean
|
||||
+3
-3
@@ -5,15 +5,15 @@ import org.jetbrains.kotlin.tools.projectWizard.core.entity.Task1
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.Task1Reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
|
||||
|
||||
class TaskRunningContext(
|
||||
class WritingContext(
|
||||
context: Context,
|
||||
servicesManager: ServicesManager,
|
||||
isUnitTestMode: Boolean
|
||||
) : ValuesReadingContext(context, servicesManager, isUnitTestMode) {
|
||||
) : ReadingContext(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>
|
||||
return task.action(this@TaskRunningContext, value)
|
||||
return task.action(this@WritingContext, value)
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> PropertyReference<T>.update(
|
||||
+3
-3
@@ -131,7 +131,7 @@ class SettingContext(val onUpdated: (SettingReference<*, *>) -> Unit) {
|
||||
onUpdated(reference)
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.initPluginSettings(settings: List<PluginSetting<*, *>>) {
|
||||
fun ReadingContext.initPluginSettings(settings: List<PluginSetting<*, *>>) {
|
||||
for (setting in settings) {
|
||||
setting.savedOrDefaultValue?.let { values[setting.path] = it }
|
||||
}
|
||||
@@ -215,7 +215,7 @@ abstract class SettingBuilder<V : Any, T : SettingType<V>>(
|
||||
this.validator = this.validator and validator
|
||||
}
|
||||
|
||||
fun validate(validator: ValuesReadingContext.(V) -> ValidationResult) {
|
||||
fun validate(validator: ReadingContext.(V) -> ValidationResult) {
|
||||
this.validator = this.validator and settingValidator(validator)
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ class DropDownSettingType<V : DisplayableSettingItem>(
|
||||
}
|
||||
|
||||
typealias DropDownSettingTypeFilter <V> =
|
||||
ValuesReadingContext.(SettingReference<V, DropDownSettingType<V>>, V) -> Boolean
|
||||
ReadingContext.(SettingReference<V, DropDownSettingType<V>>, V) -> Boolean
|
||||
|
||||
|
||||
class ValueSettingType<V : Any>(
|
||||
|
||||
+6
-6
@@ -3,20 +3,20 @@ package org.jetbrains.kotlin.tools.projectWizard.core.entity
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Failure
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValidationError
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
|
||||
inline class SettingValidator<V>(val validate: ValuesReadingContext.(V) -> ValidationResult) {
|
||||
inline class SettingValidator<V>(val validate: ReadingContext.(V) -> ValidationResult) {
|
||||
infix fun and(other: SettingValidator<V>) = SettingValidator<V> { value ->
|
||||
validate(value) and other.validate(this, value)
|
||||
}
|
||||
|
||||
operator fun ValuesReadingContext.invoke(value: V) = validate(value)
|
||||
operator fun ReadingContext.invoke(value: V) = validate(value)
|
||||
}
|
||||
|
||||
fun <V> settingValidator(validator: ValuesReadingContext.(V) -> ValidationResult) =
|
||||
fun <V> settingValidator(validator: ReadingContext.(V) -> ValidationResult) =
|
||||
SettingValidator(validator)
|
||||
|
||||
fun <V> inValidatorContext(validator: ValuesReadingContext.(V) -> SettingValidator<V>) =
|
||||
fun <V> inValidatorContext(validator: ReadingContext.(V) -> SettingValidator<V>) =
|
||||
SettingValidator<V> { value ->
|
||||
validator(value).validate(this, value)
|
||||
}
|
||||
@@ -96,7 +96,7 @@ interface Validatable<out V> {
|
||||
val validator: SettingValidator<@UnsafeVariance V>
|
||||
}
|
||||
|
||||
fun <V, Q : Validatable<Q>> ValuesReadingContext.validateList(list: List<Q>) = settingValidator<V> {
|
||||
fun <V, Q : Validatable<Q>> ReadingContext.validateList(list: List<Q>) = settingValidator<V> {
|
||||
list.fold(ValidationResult.OK as ValidationResult) { result, value ->
|
||||
result and value.validator.validate(this, value).withTarget(value)
|
||||
}
|
||||
|
||||
+6
-6
@@ -14,12 +14,12 @@ sealed class Task : EntityBase()
|
||||
|
||||
data class Task1<A, B : Any>(
|
||||
override val path: String,
|
||||
val action: TaskRunningContext.(A) -> TaskResult<B>
|
||||
val action: WritingContext.(A) -> TaskResult<B>
|
||||
) : Task() {
|
||||
class Builder<A, B : Any>(private val name: String) {
|
||||
private var action: TaskRunningContext.(A) -> TaskResult<B> = { Failure() }
|
||||
private var action: WritingContext.(A) -> TaskResult<B> = { Failure() }
|
||||
|
||||
fun withAction(action: TaskRunningContext.(A) -> TaskResult<B>) {
|
||||
fun withAction(action: WritingContext.(A) -> TaskResult<B>) {
|
||||
this.action = action
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ data class Task1<A, B : Any>(
|
||||
|
||||
data class PipelineTask(
|
||||
override val path: String,
|
||||
val action: TaskRunningContext.() -> TaskResult<Unit>,
|
||||
val action: WritingContext.() -> TaskResult<Unit>,
|
||||
val before: List<PipelineTaskReference>,
|
||||
val after: List<PipelineTaskReference>,
|
||||
val phase: GenerationPhase,
|
||||
@@ -49,7 +49,7 @@ data class PipelineTask(
|
||||
private val name: String,
|
||||
private val phase: GenerationPhase
|
||||
) {
|
||||
private var action: TaskRunningContext.() -> TaskResult<Unit> = { UNIT_SUCCESS }
|
||||
private var action: WritingContext.() -> TaskResult<Unit> = { UNIT_SUCCESS }
|
||||
private val before = mutableListOf<PipelineTaskReference>()
|
||||
private val after = mutableListOf<PipelineTaskReference>()
|
||||
|
||||
@@ -57,7 +57,7 @@ data class PipelineTask(
|
||||
|
||||
var title: String? = null
|
||||
|
||||
fun withAction(action: TaskRunningContext.() -> TaskResult<Unit>) {
|
||||
fun withAction(action: WritingContext.() -> TaskResult<Unit>) {
|
||||
this.action = action
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.core.service
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
|
||||
interface BuildSystemAvailabilityWizardService : WizardService {
|
||||
fun isAvailable(buildSystemType: BuildSystemType): Boolean
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.isBuildSystemAvailable(buildSystemType: BuildSystemType) =
|
||||
fun ReadingContext.isBuildSystemAvailable(buildSystemType: BuildSystemType) =
|
||||
service<BuildSystemAvailabilityWizardService>().isAvailable(buildSystemType)
|
||||
|
||||
class BuildSystemAvailabilityWizardServiceImpl : BuildSystemAvailabilityWizardService, IdeaIndependentWizardService {
|
||||
|
||||
+3
-3
@@ -6,12 +6,12 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.core.service
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.WizardRunConfiguration
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
|
||||
interface RunConfigurationsService : WizardService {
|
||||
fun ValuesReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>)
|
||||
fun ReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>)
|
||||
}
|
||||
|
||||
class RunConfigurationsServiceImpl : RunConfigurationsService, IdeaIndependentWizardService {
|
||||
override fun ValuesReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>) = Unit
|
||||
override fun ReadingContext.addRunConfigurations(configurations: List<WizardRunConfiguration>) = Unit
|
||||
}
|
||||
+3
-4
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.BuildScrip
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.RawGradleIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.library.MavenArtifact
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.AndroidPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle.GradlePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleConfigurationData
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
@@ -44,7 +43,7 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
}
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
override fun ReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
) =
|
||||
@@ -73,7 +72,7 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
).map(::BuildScriptDependencyIR)
|
||||
}
|
||||
|
||||
override fun TaskRunningContext.runArbitraryTask(
|
||||
override fun WritingContext.runArbitraryTask(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module,
|
||||
modulePath: Path
|
||||
@@ -88,7 +87,7 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
)
|
||||
}
|
||||
|
||||
override fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
override fun ReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
buildList {
|
||||
+ArtifactBasedLibraryDependencyIR(
|
||||
MavenArtifact(DefaultRepository.GOOGLE, "androidx.appcompat", "appcompat"),
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystemPluginIR
|
||||
@@ -35,7 +35,7 @@ object JsSingleplatformModuleConfigurator : JSConfigurator, ModuleConfiguratorWi
|
||||
version = configurationData.kotlinVersion
|
||||
)
|
||||
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
override fun ReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> = buildList {
|
||||
|
||||
+4
-4
@@ -177,7 +177,7 @@ val ModuleConfigurator.settings
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.allSettingsOfModuleConfigurator(moduleConfigurator: ModuleConfigurator) = when (moduleConfigurator) {
|
||||
fun ReadingContext.allSettingsOfModuleConfigurator(moduleConfigurator: ModuleConfigurator) = when (moduleConfigurator) {
|
||||
is ModuleConfiguratorWithSettings -> buildList<Setting<Any, SettingType<Any>>> {
|
||||
+moduleConfigurator.getConfiguratorSettings()
|
||||
+moduleConfigurator.getPluginSettings().map { it.pluginSetting }
|
||||
@@ -201,13 +201,13 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
val suggestedModuleName: String? get() = null
|
||||
val canContainSubModules: Boolean get() = false
|
||||
|
||||
fun ValuesReadingContext.createBuildFileIRs(
|
||||
fun ReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
fun ReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
||||
@@ -217,7 +217,7 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
||||
null
|
||||
|
||||
fun TaskRunningContext.runArbitraryTask(
|
||||
fun WritingContext.runArbitraryTask(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module,
|
||||
modulePath: Path
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSetting
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.safeAs
|
||||
@@ -37,7 +37,7 @@ abstract class ModuleConfiguratorWithTests : ModuleConfiguratorWithSettings() {
|
||||
|
||||
abstract fun defaultTestFramework(): KotlinTestFramework
|
||||
|
||||
override fun ValuesReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
override fun ReadingContext.createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
withSettingsOf(module) {
|
||||
testFramework.reference.settingValue.dependencyNames.map { dependencyName ->
|
||||
KotlinArbitraryDependencyIR(
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.CreateGradleValueIR
|
||||
@@ -34,7 +34,7 @@ object NativeForCurrentSystemTarget : NativeTargetConfigurator, SingleCoexistenc
|
||||
override val text = "For Current System"
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> {
|
||||
override fun ReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> {
|
||||
val moduleName = module.name
|
||||
val variableName = "${moduleName}Target"
|
||||
|
||||
@@ -74,7 +74,7 @@ object NativeForCurrentSystemTarget : NativeTargetConfigurator, SingleCoexistenc
|
||||
}
|
||||
}
|
||||
|
||||
override fun ValuesReadingContext.createBuildFileIRs(
|
||||
override fun ReadingContext.createBuildFileIRs(
|
||||
configurationData: ModuleConfigurationData,
|
||||
module: Module
|
||||
): List<BuildSystemIR> = buildList {
|
||||
|
||||
+7
-8
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.*
|
||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemT
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.buildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.isGradle
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleSubType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||
|
||||
@@ -20,8 +19,8 @@ interface TargetConfigurator : ModuleConfiguratorWithModuleType {
|
||||
|
||||
fun canCoexistsWith(other: List<TargetConfigurator>): Boolean = true
|
||||
|
||||
fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR>
|
||||
fun ValuesReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
||||
fun ReadingContext.createTargetIrs(module: Module): List<BuildSystemIR>
|
||||
fun ReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = emptyList()
|
||||
}
|
||||
|
||||
abstract class TargetConfiguratorWithTests : ModuleConfiguratorWithTests(), TargetConfigurator
|
||||
@@ -40,7 +39,7 @@ interface SimpleTargetConfigurator : TargetConfigurator {
|
||||
override val suggestedModuleName: String? get() = moduleSubType.name
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(moduleSubType),
|
||||
createInnerTargetIrs(module)
|
||||
@@ -64,7 +63,7 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator, ModuleConfiguratorWit
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
|
||||
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(ModuleSubType.js),
|
||||
buildList {
|
||||
@@ -82,7 +81,7 @@ object JsNodeTargetConfigurator : JsTargetConfigurator {
|
||||
override val suggestedModuleName = "nodeJs"
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ReadingContext.createTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
+DefaultTargetConfigurationIR(
|
||||
module.createTargetAccessIr(ModuleSubType.js),
|
||||
buildList {
|
||||
@@ -110,7 +109,7 @@ object JvmTargetConfigurator : JvmModuleConfigurator(),
|
||||
|
||||
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JUNIT4
|
||||
|
||||
override fun ValuesReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
override fun ReadingContext.createInnerTargetIrs(module: Module): List<BuildSystemIR> = buildList {
|
||||
val targetVersionValue = withSettingsOf(module) { targetJvmVersion.reference.settingValue.value }
|
||||
when {
|
||||
buildSystemType.isGradle -> {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ValuesReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.ReadingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSetting
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.safeAs
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
@@ -84,7 +84,7 @@ object JvmSinglePlatformModuleConfigurator : JvmModuleConfigurator(),
|
||||
)
|
||||
|
||||
|
||||
override fun ValuesReadingContext.createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
override fun ReadingContext.createBuildFileIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
buildList {
|
||||
+GradleImportIR("org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
|
||||
|
||||
+3
-3
@@ -37,14 +37,14 @@ class StructurePlugin(context: Context) : Plugin(context) {
|
||||
}
|
||||
}
|
||||
|
||||
val ValuesReadingContext.projectPath
|
||||
val ReadingContext.projectPath
|
||||
get() = StructurePlugin::projectPath.reference.settingValue
|
||||
|
||||
val ValuesReadingContext.projectName
|
||||
val ReadingContext.projectName
|
||||
get() = StructurePlugin::name.reference.settingValue
|
||||
|
||||
|
||||
fun TaskRunningContext.pomIR() = PomIR(
|
||||
fun WritingContext.pomIR() = PomIR(
|
||||
artifactId = StructurePlugin::artifactId.reference.settingValue,
|
||||
groupId = StructurePlugin::groupId.reference.settingValue,
|
||||
version = Version.fromString(StructurePlugin::version.reference.settingValue)
|
||||
|
||||
+3
-5
@@ -15,12 +15,10 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ProjectKind
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.BuildFilePrinter
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.printBuildFile
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Repository
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.updateBuildFiles
|
||||
import java.nio.file.Path
|
||||
|
||||
abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
|
||||
val type by enumSetting<BuildSystemType>("Build System", GenerationPhase.FIRST_STEP) {
|
||||
@@ -127,12 +125,12 @@ val BuildSystemType.isGradle
|
||||
get() = this == BuildSystemType.GradleGroovyDsl
|
||||
|| this == BuildSystemType.GradleKotlinDsl
|
||||
|
||||
val TaskRunningContext.allModules
|
||||
val WritingContext.allModules
|
||||
get() = BuildSystemPlugin::buildFiles.propertyValue.flatMap { buildFile ->
|
||||
buildFile.modules.modules
|
||||
}
|
||||
|
||||
val TaskRunningContext.allModulesPaths
|
||||
val WritingContext.allModulesPaths
|
||||
get() = BuildSystemPlugin::buildFiles.propertyValue.flatMap { buildFile ->
|
||||
val paths = when (val structure = buildFile.modules) {
|
||||
is MultiplatformModulesStructureIR -> listOf(buildFile.directoryPath)
|
||||
@@ -147,6 +145,6 @@ val TaskRunningContext.allModulesPaths
|
||||
}
|
||||
|
||||
|
||||
val ValuesReadingContext.buildSystemType: BuildSystemType
|
||||
val ReadingContext.buildSystemType: BuildSystemType
|
||||
get() = BuildSystemPlugin::type.reference.settingValue
|
||||
|
||||
|
||||
+1
-4
@@ -3,11 +3,9 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildFileIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.RepositoryIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.SettingsGradleFileIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.render
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.withIrs
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.*
|
||||
@@ -17,7 +15,6 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.printBuildFile
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.DefaultRepository
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Repositories
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.FileTemplate
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.FileTemplateDescriptor
|
||||
@@ -143,7 +140,7 @@ abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
|
||||
}
|
||||
}
|
||||
|
||||
val ValuesReadingContext.settingsGradleBuildFileData
|
||||
val ReadingContext.settingsGradleBuildFileData
|
||||
get() = when (buildSystemType) {
|
||||
BuildSystemType.GradleKotlinDsl ->
|
||||
BuildFileData(
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.buildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.pomIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectPath
|
||||
@@ -98,7 +97,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
||||
}
|
||||
|
||||
|
||||
private fun TaskRunningContext.createBuildFiles(modules: List<Module>): TaskResult<List<BuildFileIR>> =
|
||||
private fun WritingContext.createBuildFiles(modules: List<Module>): TaskResult<List<BuildFileIR>> =
|
||||
with(
|
||||
ModulesToIRsConverter(
|
||||
ModuleConfigurationData(
|
||||
|
||||
+10
-10
@@ -17,7 +17,7 @@ data class ModuleConfigurationData(
|
||||
val kotlinVersion: Version,
|
||||
val buildSystemType: BuildSystemType,
|
||||
val pomIr: PomIR,
|
||||
val taskRunningContext: TaskRunningContext
|
||||
val writingContext: WritingContext
|
||||
) {
|
||||
val allModules = rootModules.withAllSubModules()
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class ModulesToIRsConverter(
|
||||
else -> rootPath / module.name
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
fun ReadingContext.createBuildFiles(): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
val needExplicitRootBuildFile = !needFlattening
|
||||
val parentModuleHasTransitivelySpecifiedKotlinVersion = allModules.any { modules ->
|
||||
modules.configurator == AndroidSinglePlatformModuleConfigurator
|
||||
@@ -82,7 +82,7 @@ class ModulesToIRsConverter(
|
||||
}
|
||||
|
||||
|
||||
private fun ValuesReadingContext.createBuildFileForModule(
|
||||
private fun ReadingContext.createBuildFileForModule(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
): TaskResult<List<BuildFileIR>> = when (module.kind) {
|
||||
@@ -91,12 +91,12 @@ class ModulesToIRsConverter(
|
||||
else -> Success(emptyList())
|
||||
}
|
||||
|
||||
private fun ValuesReadingContext.createSinglePlatformModule(
|
||||
private fun ReadingContext.createSinglePlatformModule(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
val modulePath = calculatePathForModule(module, state.parentPath)
|
||||
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
writingContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
val configurator = module.configurator
|
||||
val dependenciesIRs = buildList<BuildSystemIR> {
|
||||
+module.sourcesets.flatMap { sourceset ->
|
||||
@@ -149,12 +149,12 @@ class ModulesToIRsConverter(
|
||||
}.map { it.flatten() + buildFileIr }
|
||||
}
|
||||
|
||||
private fun ValuesReadingContext.createMultiplatformModule(
|
||||
private fun ReadingContext.createMultiplatformModule(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
): TaskResult<List<BuildFileIR>> = with(data) {
|
||||
val modulePath = calculatePathForModule(module, state.parentPath)
|
||||
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
writingContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
val targetIrs = module.subModules.flatMap { subModule ->
|
||||
with(subModule.configurator as TargetConfigurator) { createTargetIrs(subModule) }
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class ModulesToIRsConverter(
|
||||
).asSingletonList().asSuccess()
|
||||
}
|
||||
|
||||
private fun ValuesReadingContext.createTargetSourceset(target: Module, modulePath: Path): MultiplatformModuleIR {
|
||||
private fun ReadingContext.createTargetSourceset(target: Module, modulePath: Path): MultiplatformModuleIR {
|
||||
val sourcesetss = target.sourcesets.map { sourceset ->
|
||||
val sourcesetName = target.name + sourceset.sourcesetType.name.capitalize()
|
||||
val sourcesetIrs = buildList<BuildSystemIR> {
|
||||
@@ -215,7 +215,7 @@ class ModulesToIRsConverter(
|
||||
)
|
||||
}
|
||||
|
||||
private fun TaskRunningContext.mutateProjectStructureByModuleConfigurator(
|
||||
private fun WritingContext.mutateProjectStructureByModuleConfigurator(
|
||||
module: Module,
|
||||
modulePath: Path
|
||||
): TaskResult<Unit> = with(module.configurator) {
|
||||
@@ -223,7 +223,7 @@ class ModulesToIRsConverter(
|
||||
runArbitraryTask(data, module, modulePath)
|
||||
}
|
||||
|
||||
private fun ValuesReadingContext.createBuildFileIRs(
|
||||
private fun ReadingContext.createBuildFileIRs(
|
||||
module: Module,
|
||||
state: ModulesToIrsState
|
||||
) = buildList<BuildSystemIR> {
|
||||
|
||||
+2
-3
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectName
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.projectPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.updateBuildFiles
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.transformers.interceptors.InterceptionPoint
|
||||
@@ -106,7 +105,7 @@ class TemplatesPlugin(context: Context) : Plugin(context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun TaskRunningContext.applyFileTemplatesFromSourceset(
|
||||
private fun WritingContext.applyFileTemplatesFromSourceset(
|
||||
module: ModuleIR,
|
||||
templateEngine: TemplateEngine,
|
||||
interceptionPointSettings: Map<InterceptionPoint<Any>, Any>
|
||||
@@ -129,7 +128,7 @@ class TemplatesPlugin(context: Context) : Plugin(context) {
|
||||
}.sequenceIgnore()
|
||||
}
|
||||
|
||||
private fun TaskRunningContext.defaultSettings(moduleIR: ModuleIR) = mapOf(
|
||||
private fun WritingContext.defaultSettings(moduleIR: ModuleIR) = mapOf(
|
||||
"projectName" to projectName,
|
||||
"moduleName" to moduleIR.name
|
||||
)
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ class Module(
|
||||
else -> "Module"
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.initDefaultValuesForSettings(context: Context) {
|
||||
fun ReadingContext.initDefaultValuesForSettings(context: Context) {
|
||||
configurator.safeAs<ModuleConfiguratorWithSettings>()?.initDefaultValuesFor(this@Module, context)
|
||||
template?.apply { initDefaultValuesFor(this@Module, context) }
|
||||
}
|
||||
|
||||
+4
-8
@@ -4,15 +4,11 @@ import org.jetbrains.kotlin.tools.projectWizard.GeneratedIdentificator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.Identificator
|
||||
import org.jetbrains.kotlin.tools.projectWizard.IdentificatorOwner
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.WritingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildFileIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.Template
|
||||
import org.jetbrains.kotlin.tools.projectWizard.templates.withSettingsOf
|
||||
|
||||
inline class ModulePath(val parts: List<String>) {
|
||||
fun asString(separator: String = ".") = parts.joinToString(separator)
|
||||
@@ -71,15 +67,15 @@ enum class SourcesetType: DisplayableSettingItem {
|
||||
}
|
||||
|
||||
|
||||
fun TaskRunningContext.updateBuildFiles(action: (BuildFileIR) -> TaskResult<BuildFileIR>): TaskResult<Unit> =
|
||||
fun WritingContext.updateBuildFiles(action: (BuildFileIR) -> TaskResult<BuildFileIR>): TaskResult<Unit> =
|
||||
BuildSystemPlugin::buildFiles.update { buildFiles ->
|
||||
buildFiles.mapSequence(action)
|
||||
}
|
||||
|
||||
fun TaskRunningContext.updateModules(action: (ModuleIR) -> TaskResult<ModuleIR>): TaskResult<Unit> =
|
||||
fun WritingContext.updateModules(action: (ModuleIR) -> TaskResult<ModuleIR>): TaskResult<Unit> =
|
||||
updateBuildFiles { buildFile ->
|
||||
buildFile.withModulesUpdated { action(it) }
|
||||
}
|
||||
|
||||
fun TaskRunningContext.forEachModule(action: (ModuleIR) -> TaskResult<Unit>): TaskResult<Unit> =
|
||||
fun WritingContext.forEachModule(action: (ModuleIR) -> TaskResult<Unit>): TaskResult<Unit> =
|
||||
updateModules { moduleIR -> action(moduleIR).map { moduleIR } }
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.templates
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.WritingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.asPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.multiplatform.TargetConfigurationIR
|
||||
@@ -17,7 +17,7 @@ class ConsoleJvmApplicationTemplate : Template() {
|
||||
""".trimIndent()
|
||||
override val moduleTypes: Set<ModuleType> = setOf(ModuleType.jvm)
|
||||
|
||||
override fun TaskRunningContext.getIrsToAddToBuildFile(
|
||||
override fun WritingContext.getIrsToAddToBuildFile(
|
||||
module: ModuleIR
|
||||
) = buildList<BuildSystemIR> {
|
||||
+runTaskIrs("MainKt")
|
||||
@@ -26,7 +26,7 @@ class ConsoleJvmApplicationTemplate : Template() {
|
||||
override fun updateTargetIr(module: ModuleIR, targetConfigurationIR: TargetConfigurationIR): TargetConfigurationIR =
|
||||
targetConfigurationIR.addWithJavaIntoJvmTarget()
|
||||
|
||||
override fun TaskRunningContext.getFileTemplates(module: ModuleIR) =
|
||||
override fun WritingContext.getFileTemplates(module: ModuleIR) =
|
||||
buildList<FileTemplateDescriptorWithPath> {
|
||||
+(FileTemplateDescriptor("$id/main.kt.vm", "main.kt".asPath()) asSrcOf SourcesetType.main)
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.templates
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.WritingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.asPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSetting
|
||||
@@ -28,7 +28,7 @@ class KtorServerTemplate : Template() {
|
||||
override val moduleTypes: Set<ModuleType> = setOf(ModuleType.jvm)
|
||||
override val id: String = "ktorServer"
|
||||
|
||||
override fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> =
|
||||
override fun WritingContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> =
|
||||
withSettingsOf(module.originalModule) {
|
||||
buildList {
|
||||
+ktorArtifactDependency(serverEngine.reference.settingValue.dependencyName)
|
||||
@@ -41,7 +41,7 @@ class KtorServerTemplate : Template() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun TaskRunningContext.getIrsToAddToBuildFile(module: ModuleIR): List<BuildSystemIR> = buildList {
|
||||
override fun WritingContext.getIrsToAddToBuildFile(module: ModuleIR): List<BuildSystemIR> = buildList {
|
||||
+RepositoryIR(Repositories.KTOR_BINTRAY)
|
||||
+RepositoryIR(DefaultRepository.JCENTER)
|
||||
+runTaskIrs(mainClass = "ServerKt")
|
||||
@@ -50,7 +50,7 @@ class KtorServerTemplate : Template() {
|
||||
override fun updateTargetIr(module: ModuleIR, targetConfigurationIR: TargetConfigurationIR): TargetConfigurationIR =
|
||||
targetConfigurationIR.addWithJavaIntoJvmTarget()
|
||||
|
||||
override fun TaskRunningContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = listOf(
|
||||
override fun WritingContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = listOf(
|
||||
FileTemplateDescriptor("$id/server.kt.vm", "server.kt".asPath()) asSrcOf SourcesetType.main
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.templates
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.WritingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.asPath
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.buildList
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
|
||||
@@ -24,7 +24,7 @@ class NativeConsoleApplicationTemplate : Template() {
|
||||
override fun updateTargetIr(module: ModuleIR, targetConfigurationIR: TargetConfigurationIR): TargetConfigurationIR =
|
||||
targetConfigurationIR.withIrs(NativeTargetInternalIR("main"))
|
||||
|
||||
override fun TaskRunningContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = buildList {
|
||||
override fun WritingContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = buildList {
|
||||
+(FileTemplateDescriptor("$id/main.kt.vm", "main.kt".asPath()) asSrcOf SourcesetType.main)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -42,7 +42,7 @@ class SimpleJsClientTemplate : Template() {
|
||||
|
||||
override val settings: List<TemplateSetting<*, *>> = listOf(renderEngine)
|
||||
|
||||
override fun ValuesReadingContext.createRunConfigurations(module: ModuleIR): List<WizardRunConfiguration> = buildList {
|
||||
override fun ReadingContext.createRunConfigurations(module: ModuleIR): List<WizardRunConfiguration> = buildList {
|
||||
if (module.originalModule.kind == ModuleKind.singleplatformJs) {
|
||||
+WizardGradleRunConfiguration(
|
||||
"BrowserDevelopmentRun in continuous mode",
|
||||
@@ -57,7 +57,7 @@ class SimpleJsClientTemplate : Template() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = withSettingsOf(module.originalModule) {
|
||||
override fun WritingContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = withSettingsOf(module.originalModule) {
|
||||
buildList {
|
||||
+ArtifactBasedLibraryDependencyIR(
|
||||
MavenArtifact(DefaultRepository.JCENTER, "org.jetbrains.kotlinx", "kotlinx-html-js"),
|
||||
@@ -81,7 +81,7 @@ class SimpleJsClientTemplate : Template() {
|
||||
}
|
||||
|
||||
|
||||
override fun TaskRunningContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> =
|
||||
override fun WritingContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> =
|
||||
withSettingsOf(module.originalModule) {
|
||||
buildList {
|
||||
val hasKtorServNeighbourTarget = module.safeAs<MultiplatformModuleIR>()
|
||||
@@ -200,7 +200,7 @@ class SimpleJsClientTemplate : Template() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun TaskRunningContext.getIrsToAddToBuildFile(module: ModuleIR): List<BuildSystemIR> = buildList {
|
||||
override fun WritingContext.getIrsToAddToBuildFile(module: ModuleIR): List<BuildSystemIR> = buildList {
|
||||
+RepositoryIR(DefaultRepository.JCENTER)
|
||||
if (module is MultiplatformModuleIR) {
|
||||
+GradleImportIR("org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack")
|
||||
|
||||
+9
-9
@@ -71,7 +71,7 @@ abstract class Template : SettingsOwner {
|
||||
open val settings: List<TemplateSetting<*, *>> = emptyList()
|
||||
open val interceptionPoints: List<InterceptionPoint<Any>> = emptyList()
|
||||
|
||||
fun ValuesReadingContext.initDefaultValuesFor(module: Module, context: Context) {
|
||||
fun ReadingContext.initDefaultValuesFor(module: Module, context: Context) {
|
||||
withSettingsOf(module) {
|
||||
settings.forEach { setting ->
|
||||
val defaultValue = setting.savedOrDefaultValue ?: return@forEach
|
||||
@@ -80,10 +80,10 @@ abstract class Template : SettingsOwner {
|
||||
}
|
||||
}
|
||||
|
||||
open fun TaskRunningContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = emptyList()
|
||||
open fun WritingContext.getRequiredLibraries(module: ModuleIR): List<DependencyIR> = emptyList()
|
||||
|
||||
//TODO: use setting reading context
|
||||
open fun TaskRunningContext.getIrsToAddToBuildFile(
|
||||
open fun WritingContext.getIrsToAddToBuildFile(
|
||||
module: ModuleIR
|
||||
): List<BuildSystemIR> = emptyList()
|
||||
|
||||
@@ -92,13 +92,13 @@ abstract class Template : SettingsOwner {
|
||||
targetConfigurationIR: TargetConfigurationIR
|
||||
): TargetConfigurationIR = targetConfigurationIR
|
||||
|
||||
open fun TaskRunningContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = emptyList()
|
||||
open fun WritingContext.getFileTemplates(module: ModuleIR): List<FileTemplateDescriptorWithPath> = emptyList()
|
||||
|
||||
open fun createInterceptors(module: ModuleIR): List<TemplateInterceptor> = emptyList()
|
||||
|
||||
open fun ValuesReadingContext.createRunConfigurations(module: ModuleIR): List<WizardRunConfiguration> = emptyList()
|
||||
open fun ReadingContext.createRunConfigurations(module: ModuleIR): List<WizardRunConfiguration> = emptyList()
|
||||
|
||||
fun TaskRunningContext.applyToSourceset(
|
||||
fun WritingContext.applyToSourceset(
|
||||
module: ModuleIR
|
||||
): TaskResult<TemplateApplicationResult> {
|
||||
val librariesToAdd = getRequiredLibraries(module)
|
||||
@@ -118,7 +118,7 @@ abstract class Template : SettingsOwner {
|
||||
return result.asSuccess()
|
||||
}
|
||||
|
||||
fun TaskRunningContext.settingsAsMap(module: Module): Map<String, Any> =
|
||||
fun WritingContext.settingsAsMap(module: Module): Map<String, Any> =
|
||||
withSettingsOf(module) {
|
||||
settings.associate { setting ->
|
||||
setting.path to setting.reference.settingValue
|
||||
@@ -126,7 +126,7 @@ abstract class Template : SettingsOwner {
|
||||
} + createDefaultSettings()
|
||||
|
||||
|
||||
private fun TaskRunningContext.createDefaultSettings() = mapOf(
|
||||
private fun WritingContext.createDefaultSettings() = mapOf(
|
||||
"projectName" to StructurePlugin::name.settingValue.capitalize()
|
||||
)
|
||||
|
||||
@@ -252,7 +252,7 @@ fun Template.settings(module: Module) = withSettingsOf(module) {
|
||||
settings.map { it.reference }
|
||||
}
|
||||
|
||||
fun TaskRunningContext.applyTemplateToModule(
|
||||
fun WritingContext.applyTemplateToModule(
|
||||
template: Template?,
|
||||
module: ModuleIR
|
||||
): TaskResult<TemplateApplicationResult> = when (template) {
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import org.apache.velocity.runtime.RuntimeConstants
|
||||
import org.apache.velocity.runtime.RuntimeServices
|
||||
import org.apache.velocity.runtime.log.LogChute
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.WritingContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.div
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileFormattingService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
|
||||
@@ -16,7 +16,7 @@ import java.io.StringWriter
|
||||
interface TemplateEngine {
|
||||
fun renderTemplate(template: FileTemplateDescriptor, data: Map<String, Any?>): String
|
||||
|
||||
fun TaskRunningContext.writeTemplate(template: FileTemplate): TaskResult<Unit> {
|
||||
fun WritingContext.writeTemplate(template: FileTemplate): TaskResult<Unit> {
|
||||
val formatter = service<FileFormattingService>()
|
||||
val text = renderTemplate(template.descriptor, template.data).let { text ->
|
||||
formatter.formatFile(text, template.descriptor.relativePath.fileName.toString())
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
|
||||
abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: ServicesManager, private val isUnitTestMode: Boolean) {
|
||||
val context = Context(createPlugins, EventManager())
|
||||
val valuesReadingContext = ValuesReadingContext(context, servicesManager, isUnitTestMode)
|
||||
val valuesReadingContext = ReadingContext(context, servicesManager, isUnitTestMode)
|
||||
protected val plugins = context.plugins
|
||||
protected val pluginSettings = plugins.flatMap { it.declaredSettings }.distinctBy { it.path }
|
||||
|
||||
@@ -20,7 +20,7 @@ abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: Servic
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun ValuesReadingContext.validate(phases: Set<GenerationPhase>): TaskResult<Unit> =
|
||||
fun ReadingContext.validate(phases: Set<GenerationPhase>): TaskResult<Unit> =
|
||||
context.settingContext.allPluginSettings.map { setting ->
|
||||
val value = context.settingContext.pluginSettingValue(setting) ?: return@map ValidationResult.OK
|
||||
when (setting.neededAtPhase) {
|
||||
@@ -29,7 +29,7 @@ abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: Servic
|
||||
}
|
||||
}.fold(ValidationResult.OK, ValidationResult::and).toResult()
|
||||
|
||||
private fun ValuesReadingContext.saveSettingValues(phases: Set<GenerationPhase>) {
|
||||
private fun ReadingContext.saveSettingValues(phases: Set<GenerationPhase>) {
|
||||
for (setting in pluginSettings) {
|
||||
if (setting.neededAtPhase !in phases) continue
|
||||
if (!setting.isSavable) continue
|
||||
@@ -47,7 +47,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), isUnitTestMode)
|
||||
val taskRunningContext = WritingContext(context, servicesManager.withServices(services), isUnitTestMode)
|
||||
taskRunningContext.validate(phases).ensure()
|
||||
taskRunningContext.saveSettingValues(phases)
|
||||
val (tasksSorted) = context.sortTasks().map { tasks ->
|
||||
|
||||
Reference in New Issue
Block a user