Wizard: introduce ServicesManager & correctly handle disabled gradle & maven Idea plugins

This commit is contained in:
Ilya Kirillov
2019-12-12 20:22:30 +03:00
parent 9011eecfdf
commit f927fb3471
41 changed files with 361 additions and 279 deletions
@@ -5,8 +5,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PipelineTask
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PluginSettingReference
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
import org.jetbrains.kotlin.tools.projectWizard.core.service.AndroidServiceImpl
import org.jetbrains.kotlin.tools.projectWizard.core.service.Service
import org.jetbrains.kotlin.tools.projectWizard.core.service.*
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
@@ -16,9 +15,14 @@ class YamlWizard(
private val yaml: String,
private val path: String,
createPlugins: (Context) -> List<Plugin>
) : Wizard(createPlugins, listOf(AndroidServiceImpl())) {
) : Wizard(
createPlugins,
ServicesManager(Services.IDEA_INDEPENDENT_SERVICES) { services ->
services.firstOrNull { it is IdeaIndependentWizardService }
}
) {
override fun apply(
services: List<Service>,
services: List<WizardService>,
phases: Set<GenerationPhase>,
onTaskExecuting: (PipelineTask) -> Unit
): TaskResult<Unit> = computeM {
@@ -38,5 +42,5 @@ class YamlWizard(
get() = pluginSettings.mapNotNull { setting ->
val defaultValue = setting.defaultValue ?: return@mapNotNull null
PluginSettingReference(setting) to defaultValue
} .toMap()
}.toMap()
}
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.tools.projectWizard.cli
import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.kotlin.tools.projectWizard.core.ExceptionError
import org.jetbrains.kotlin.tools.projectWizard.core.div
import org.jetbrains.kotlin.tools.projectWizard.core.onFailure
@@ -20,7 +19,6 @@ import java.nio.file.Path
import java.nio.file.Paths
abstract class AbstractBuildFileGenerationTest : AbstractPluginBasedTest() {
fun doTest(directoryPath: String) {
val directory = Paths.get(directoryPath)
val testData = init(directory)
@@ -41,7 +39,7 @@ abstract class AbstractBuildFileGenerationTest : AbstractPluginBasedTest() {
buildSystem.yaml
val tempDir = Files.createTempDirectory(null)
val wizard = YamlWizard(yaml, tempDir.toString(), testData.createPlugins)
val result = wizard.apply(Services.osServices, GenerationPhase.ALL)
val result = wizard.apply(Services.IDEA_INDEPENDENT_SERVICES, GenerationPhase.ALL)
result.onFailure { errors ->
errors.forEach { error ->
if (error is ExceptionError) {
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.tools.projectWizard.core
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.full.memberProperties
@@ -3,11 +3,12 @@ package org.jetbrains.kotlin.tools.projectWizard.core
import org.jetbrains.kotlin.tools.projectWizard.core.entity.PropertyReference
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.Service
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
class TaskRunningContext(context: Context, services: List<Service>) : ValuesReadingContext(context, services) {
class TaskRunningContext(
context: Context,
servicesManager: ServicesManager
) : ValuesReadingContext(context, servicesManager) {
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>
@@ -30,4 +31,3 @@ class TaskRunningContext(context: Context, services: List<Service>) : ValuesRead
values: List<T>
): TaskResult<Unit> = update { oldValues -> success(oldValues + values) }
}
@@ -1,19 +1,17 @@
package org.jetbrains.kotlin.tools.projectWizard.core
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.core.service.Service
import org.jetbrains.kotlin.tools.projectWizard.core.service.WizardService
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.isSubclassOf
import kotlin.reflect.jvm.jvmName
@Suppress("UNCHECKED_CAST")
open class ValuesReadingContext(val context: Context, private val services: List<Service>) {
inline fun <reified S : Service> service() = serviceByClass(S::class)
open class ValuesReadingContext(val context: Context, private val servicesManager: ServicesManager) {
inline fun <reified S : WizardService> service(noinline filter: (S) -> Boolean = { true }) = serviceByClass(S::class, filter)
@Suppress("UNCHECKED_CAST")
fun <S : Service> serviceByClass(klass: KClass<S>) =
services.firstOrNull { it::class.isSubclassOf(klass) } as? S ?: error("No service ${klass.jvmName}")
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean = { true }) =
servicesManager.serviceByClass(klass, filter)
inline val <reified T : Any> PropertyReference<T>.propertyValue: T
get() = context.propertyContext[this] as T
@@ -277,7 +277,7 @@ class DropDownSettingType<V : DisplayableSettingItem>(
}
}
typealias DropDownSettingTypeFilter<V> = (SettingReference<V, DropDownSettingType<V>>, V) -> Boolean
typealias DropDownSettingTypeFilter<V> = ValuesReadingContext.(SettingReference<V, DropDownSettingType<V>>, V) -> Boolean
class ValueSettingType<V : Any>(
@@ -2,11 +2,11 @@ package org.jetbrains.kotlin.tools.projectWizard.core.service
import java.nio.file.Path
interface AndroidService : Service {
interface AndroidWizardService : WizardService {
fun isValidAndroidSdk(path: Path): Boolean
}
class AndroidServiceImpl : AndroidService {
class AndroidWizardServiceImpl : AndroidWizardService, IdeaIndependentWizardService {
//TODO use some heuristics
override fun isValidAndroidSdk(path: Path): Boolean = true
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
interface BuildSystemAvailabilityWizardService : WizardService {
fun isAvailable(buildSystemType: BuildSystemType): Boolean
}
class BuildSystemAvailabilityWizardServiceImpl : BuildSystemAvailabilityWizardService, IdeaIndependentWizardService {
override fun isAvailable(buildSystemType: BuildSystemType) = true
}
@@ -1,12 +0,0 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
import java.nio.file.Path
interface BuildSystemService : Service {
fun importProject(
path: Path,
modulesIrs: List<ModuleIR>
): TaskResult<Unit>
}
@@ -0,0 +1,7 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
interface BuildSystemWizardService : WizardService {
fun isSuitableFor(buildSystemType: BuildSystemType): Boolean
}
@@ -1,29 +1,22 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.core.computeM
import org.jetbrains.kotlin.tools.projectWizard.core.safe
import java.nio.file.Files
import java.nio.file.Path
interface FileSystemService : Service {
interface FileSystemWizardService : WizardService {
fun createFile(path: Path, text: String): TaskResult<Unit>
fun createDirectory(path: Path): TaskResult<Unit>
object DUMMY : FileSystemService {
override fun createFile(path: Path, text: String): TaskResult<Unit> = UNIT_SUCCESS
override fun createDirectory(path: Path): TaskResult<Unit> = UNIT_SUCCESS
}
}
class OsFileSystemService : FileSystemService {
class OsFileSystemWizardService : FileSystemWizardService, IdeaIndependentWizardService {
override fun createFile(path: Path, text: String) = computeM {
createDirectory(path.parent).ensure()
safe { Files.createFile(path.normalize()).toFile().writeText(text) }
}
override fun createDirectory(path: Path) = safe {
@Suppress("NAME_SHADOWING") val path = path.normalize()
if (Files.notExists(path)) {
@@ -1,14 +0,0 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
import java.nio.file.Path
interface GradleService : BuildSystemService
class OsGradleIntegration : GradleService {
override fun importProject(
path: Path,
modulesIrs: List<ModuleIR>
) = UNIT_SUCCESS
}
@@ -1,14 +0,0 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
import java.nio.file.Path
interface JpsService : BuildSystemService
class OsJpsService : JpsService {
override fun importProject(
path: Path,
modulesIrs: List<ModuleIR>
) = UNIT_SUCCESS
}
@@ -1,14 +0,0 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
import java.nio.file.Path
interface MavenService : BuildSystemService
class OsMavenService : MavenService {
override fun importProject(
path: Path,
modulesIrs: List<ModuleIR>
) = UNIT_SUCCESS
}
@@ -0,0 +1,16 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
import org.jetbrains.kotlin.tools.projectWizard.core.UNIT_SUCCESS
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.ModuleIR
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
import java.nio.file.Path
interface ProjectImportingWizardService : BuildSystemWizardService {
fun importProject(path: Path, modulesIrs: List<ModuleIR>): TaskResult<Unit>
}
class ProjectImportingWizardServiceImpl : ProjectImportingWizardService, IdeaIndependentWizardService {
override fun isSuitableFor(buildSystemType: BuildSystemType): Boolean = true
override fun importProject(path: Path, modulesIrs: List<ModuleIR>) = UNIT_SUCCESS
}
@@ -1,13 +0,0 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
interface Service
object Services {
val osServices = listOf(
OsGradleIntegration(),
OsMavenService(),
OsFileSystemService(),
OsJpsService(),
AndroidServiceImpl()
)
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.tools.projectWizard.core.service
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf
class ServicesManager(private val services: List<WizardService>, private val serviceSelector: (List<WizardService>) -> WizardService?) {
@Suppress("UNCHECKED_CAST")
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean): S? =
services.filter { service ->
service::class.isSubclassOf(klass) && filter(service as S)
}.let(serviceSelector) as? S
fun withServices(services: List<WizardService>) =
ServicesManager(this.services + services, serviceSelector)
}
@@ -0,0 +1,15 @@
package org.jetbrains.kotlin.tools.projectWizard.core.service
interface WizardService
interface IdeaIndependentWizardService : WizardService
object Services {
val IDEA_INDEPENDENT_SERVICES: List<IdeaIndependentWizardService> = listOf(
ProjectImportingWizardServiceImpl(),
OsFileSystemWizardService(),
AndroidWizardServiceImpl(),
BuildSystemAvailabilityWizardServiceImpl()
)
}
@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ModuleConfiguratorSetting
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
import org.jetbrains.kotlin.tools.projectWizard.core.service.AndroidService
import org.jetbrains.kotlin.tools.projectWizard.core.service.AndroidWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.AndroidConfigIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.BuildScriptDependencyIR
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
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.pomIR
import org.jetbrains.kotlin.tools.projectWizard.plugins.templates.TemplatesPlugin
import org.jetbrains.kotlin.tools.projectWizard.settings.JavaPackage
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.DefaultRepository
@@ -38,7 +37,7 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
validate { path ->
ValidationResult.create(
service<AndroidService>().isValidAndroidSdk(
service<AndroidWizardService>()!!.isValidAndroidSdk(
path
),
"Path should point to valid Android SDK location"
@@ -5,7 +5,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.Plugin
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
import org.jetbrains.kotlin.tools.projectWizard.core.pathParser
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.PomIR
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
@@ -31,7 +31,7 @@ class StructurePlugin(context: Context) : Plugin(context) {
val createProjectDir by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
withAction {
service<FileSystemService>().createDirectory(StructurePlugin::projectPath.reference.settingValue)
service<FileSystemWizardService>()!!.createDirectory(StructurePlugin::projectPath.reference.settingValue)
}
}
}
@@ -3,8 +3,9 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
import org.jetbrains.kotlin.tools.projectWizard.core.service.BuildSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.BuildSystemAvailabilityWizardService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import org.jetbrains.kotlin.tools.projectWizard.core.service.ProjectImportingWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildFileIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.MultiplatformModulesStructureIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.render
@@ -16,13 +17,17 @@ 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.settings.DisplayableSettingItem
import kotlin.reflect.KClass
abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
val type by enumSetting<BuildSystemType>("Build System", GenerationPhase.FIRST_STEP) {
filter = { _, type ->
val service = service<BuildSystemAvailabilityWizardService>()!!
service.isAvailable(type)
}
validate { buildSystemType ->
if (!buildSystemType.isGradle
&& KotlinPlugin::projectKind.settingValue() == ProjectKind.Multiplatform
&& KotlinPlugin::projectKind.reference.notRequiredSettingValue == ProjectKind.Multiplatform
) {
ValidationResult.ValidationError("Multiplatform project cannot be generated using ${buildSystemType.text}")
} else ValidationResult.OK
@@ -36,7 +41,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
val createModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(StructurePlugin::createProjectDir)
withAction {
val fileSystem = service<FileSystemService>()
val fileSystem = service<FileSystemWizardService>()!!
val data = BuildSystemPlugin::buildSystemData.propertyValue.first { it.type == buildSystemType }
val buildFileData = data.buildFileData ?: return@withAction UNIT_SUCCESS
BuildSystemPlugin::buildFiles.propertyValue.mapSequenceIgnore { buildFile ->
@@ -52,7 +57,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
runAfter(BuildSystemPlugin::createModules)
withAction {
val data = BuildSystemPlugin::buildSystemData.propertyValue.first { it.type == buildSystemType }
serviceByClass(data.buildSystemServiceClass)
service<ProjectImportingWizardService> { service -> service.isSuitableFor(data.type) }!!
.importProject(StructurePlugin::projectPath.reference.settingValue, allModules)
}
}
@@ -61,14 +66,13 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
runBefore(BuildSystemPlugin::createModules)
activityChecker = Checker.ALWAYS_AVAILABLE
withAction {
BuildSystemPlugin::buildSystemData.update { Success(it + data) }
BuildSystemPlugin::buildSystemData.addValues(data)
}
}
}
data class BuildSystemData(
val type: BuildSystemType,
val buildSystemServiceClass: KClass<out BuildSystemService>,
val buildFileData: BuildFileData?
)
@@ -1,7 +1,6 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.service.JpsService
class JpsPlugin(context: Context) : BuildSystemPlugin(context) {
override val title: String = "IDEA"
@@ -9,7 +8,6 @@ class JpsPlugin(context: Context) : BuildSystemPlugin(context) {
val addBuildSystemData by addBuildSystemData(
BuildSystemData(
type = BuildSystemType.Jps,
buildSystemServiceClass = JpsService::class,
buildFileData = null
)
)
@@ -4,7 +4,6 @@ import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.asSuccess
import org.jetbrains.kotlin.tools.projectWizard.core.checker
import org.jetbrains.kotlin.tools.projectWizard.core.entity.reference
import org.jetbrains.kotlin.tools.projectWizard.core.service.MavenService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.RootFileModuleStructureIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.ModulesDependencyMavenIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.withIrs
@@ -42,7 +41,6 @@ class MavenPlugin(context: Context) : BuildSystemPlugin(context) {
val addBuildSystemData by addBuildSystemData(
BuildSystemData(
type = BuildSystemType.Maven,
buildSystemServiceClass = MavenService::class,
buildFileData = BuildFileData(
createPrinter = { MavenPrinter() },
buildFileName = "pom.xml"
@@ -1,15 +1,10 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.checker
import org.jetbrains.kotlin.tools.projectWizard.core.service.GradleService
import org.jetbrains.kotlin.tools.projectWizard.core.service.MavenService
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildFileData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemData
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.printer.GradlePrinter
import org.jetbrains.kotlin.tools.projectWizard.plugins.printer.MavenPrinter
class GroovyDslPlugin(context: Context) : GradlePlugin(context) {
override val title: String = "Gradle (Groovy DSL)"
@@ -17,7 +12,6 @@ class GroovyDslPlugin(context: Context) : GradlePlugin(context) {
val addBuildSystemData by addBuildSystemData(
BuildSystemData(
type = BuildSystemType.GradleGroovyDsl,
buildSystemServiceClass = GradleService::class,
buildFileData = BuildFileData(
createPrinter = { GradlePrinter(GradlePrinter.GradleDsl.GROOVY) },
buildFileName = "build.gradle"
@@ -1,11 +1,8 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.gradle
import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.checker
import org.jetbrains.kotlin.tools.projectWizard.core.service.GradleService
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildFileData
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemData
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.printer.GradlePrinter
@@ -15,7 +12,6 @@ class KotlinDslPlugin(context: Context) : GradlePlugin(context) {
val addBuildSystemData by addBuildSystemData(
BuildSystemData(
type = BuildSystemType.GradleKotlinDsl,
buildSystemServiceClass = GradleService::class,
buildFileData = BuildFileData(
createPrinter = { GradlePrinter(GradlePrinter.GradleDsl.KOTLIN) },
buildFileName = "build.gradle.kts"
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
@@ -82,9 +82,10 @@ class KotlinPlugin(context: Context) : Plugin(context) {
val createSourcesetDirectories by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
runAfter(KotlinPlugin::createModules)
withAction {
fun Path.createKotlinAndResourceDirectories() =
service<FileSystemService>().createDirectory(this / Defaults.KOTLIN_DIR) andThen
service<FileSystemService>().createDirectory(this / Defaults.RESOURCES_DIR)
fun Path.createKotlinAndResourceDirectories() = with(service<FileSystemWizardService>()!!) {
createDirectory(this@createKotlinAndResourceDirectories / Defaults.KOTLIN_DIR) andThen
createDirectory(this@createKotlinAndResourceDirectories / Defaults.RESOURCES_DIR)
}
forEachModule { moduleIR ->
when (moduleIR) {
@@ -4,11 +4,10 @@ import org.jetbrains.kotlin.tools.projectWizard.Identificator
import org.jetbrains.kotlin.tools.projectWizard.SettingsOwner
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.DependencyIR
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.SourcesetIR
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.ModuleConfigurator
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
@@ -79,7 +78,7 @@ abstract class Template : SettingsOwner {
templateEngine: TemplateEngine,
sourceset: SourcesetIR
): TaskResult<TemplateApplicationResult> {
val fileSystemService = service<FileSystemService>()
val fileSystemService = service<FileSystemWizardService>()!!
val allSettings = createDefaultSettings() + settingsAsMap(sourceset.original)
@@ -8,7 +8,7 @@ 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.div
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemService
import org.jetbrains.kotlin.tools.projectWizard.core.service.FileSystemWizardService
import java.io.StringWriter
@@ -17,7 +17,7 @@ interface TemplateEngine {
fun TaskRunningContext.writeTemplate(template: FileTemplate): TaskResult<Unit> {
val text = renderTemplate(template.descriptor, template.data)
return service<FileSystemService>().createFile(template.rootPath / template.descriptor.relativePath, text)
return service<FileSystemWizardService>()!!.createFile(template.rootPath / template.descriptor.relativePath, text)
}
}
@@ -2,12 +2,13 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard
import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
import org.jetbrains.kotlin.tools.projectWizard.core.service.Service
import org.jetbrains.kotlin.tools.projectWizard.core.service.WizardService
import org.jetbrains.kotlin.tools.projectWizard.core.service.ServicesManager
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
abstract class Wizard(createPlugins: PluginsCreator, initialServices: List<Service>) {
abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: ServicesManager) {
val context = Context(createPlugins, EventManager())
val valuesReadingContext = ValuesReadingContext(context, initialServices)
val valuesReadingContext = ValuesReadingContext(context, servicesManager)
protected val plugins = context.plugins
protected val pluginSettings = plugins.flatMap { it.declaredSettings }.distinctBy { it.path }
@@ -28,12 +29,12 @@ abstract class Wizard(createPlugins: PluginsCreator, initialServices: List<Servi
}.fold(ValidationResult.OK, ValidationResult::and).toResult()
open fun apply(
services: List<Service>,
services: List<WizardService>,
phases: Set<GenerationPhase>,
onTaskExecuting: (PipelineTask) -> Unit = {}
): TaskResult<Unit> = computeM {
context.checkAllRequiredSettingPresent(phases).ensure()
val taskRunningContext = TaskRunningContext(context, services)
val taskRunningContext = TaskRunningContext(context, servicesManager.withServices(services))
taskRunningContext.validate(phases).ensure()
val (tasksSorted) = context.sortTasks().map { tasks ->
tasks.groupBy { it.phase }.toList().sortedBy { it.first }.flatMap { it.second }