Wizard: force service to always return non-null value
This commit is contained in:
+5
-4
@@ -12,10 +12,11 @@ open class ValuesReadingContext(
|
||||
private val servicesManager: ServicesManager,
|
||||
val isUnitTestMode: Boolean
|
||||
) {
|
||||
inline fun <reified S : WizardService> service(noinline filter: (S) -> Boolean = { true }) = serviceByClass(S::class, filter)
|
||||
inline fun <reified S : WizardService> service(noinline filter: (S) -> Boolean = { true }): S =
|
||||
serviceByClass(S::class, filter)
|
||||
|
||||
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean = { true }) =
|
||||
servicesManager.serviceByClass(klass, filter)
|
||||
fun <S : WizardService> serviceByClass(klass: KClass<S>, filter: (S) -> Boolean = { true }): S =
|
||||
servicesManager.serviceByClass(klass, filter) ?: error("Service ${klass.simpleName} was not found")
|
||||
|
||||
inline val <reified T : Any> PropertyReference<T>.propertyValue: T
|
||||
get() = context.propertyContext[this] as T
|
||||
@@ -44,7 +45,7 @@ open class ValuesReadingContext(
|
||||
fun <V : Any> Setting<V, SettingType<V>>.getSavedValueForSetting(): V? {
|
||||
if (!isSavable || this !is PluginSetting<*, *>) return null
|
||||
val serializer = type.serializer.safeAs<SerializerImpl<V>>() ?: return null
|
||||
val savedValue = service<SettingSavingWizardService>()!!.getSettingValue(path) ?: return null
|
||||
val savedValue = service<SettingSavingWizardService>().getSettingValue(path) ?: return null
|
||||
return serializer.fromString(savedValue)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ interface BuildSystemAvailabilityWizardService : WizardService {
|
||||
}
|
||||
|
||||
fun ValuesReadingContext.isBuildSystemAvailable(buildSystemType: BuildSystemType) =
|
||||
service<BuildSystemAvailabilityWizardService>()!!.isAvailable(buildSystemType)
|
||||
service<BuildSystemAvailabilityWizardService>().isAvailable(buildSystemType)
|
||||
|
||||
class BuildSystemAvailabilityWizardServiceImpl : BuildSystemAvailabilityWizardService, IdeaIndependentWizardService {
|
||||
override fun isAvailable(buildSystemType: BuildSystemType) = true
|
||||
|
||||
+1
@@ -19,6 +19,7 @@ class AndroidPlugin(context: Context) : Plugin(context) {
|
||||
"Android SDK Path",
|
||||
neededAtPhase = GenerationPhase.PROJECT_GENERATION
|
||||
) {
|
||||
isSavable = true
|
||||
shouldExists()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ class RunConfigurationsPlugin(context: Context) : Plugin(context) {
|
||||
runBefore(BuildSystemPlugin::importProject)
|
||||
|
||||
withAction {
|
||||
service<RunConfigurationsService>()!!.apply {
|
||||
service<RunConfigurationsService>().apply {
|
||||
addRunConfigurations(RunConfigurationsPlugin::configurations.propertyValue)
|
||||
}
|
||||
UNIT_SUCCESS
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ class StructurePlugin(context: Context) : Plugin(context) {
|
||||
|
||||
val createProjectDir by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
|
||||
withAction {
|
||||
service<FileSystemWizardService>()!!.createDirectory(StructurePlugin::projectPath.reference.settingValue)
|
||||
service<FileSystemWizardService>().createDirectory(StructurePlugin::projectPath.reference.settingValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
|
||||
val type by enumSetting<BuildSystemType>("Build System", GenerationPhase.FIRST_STEP) {
|
||||
isSavable = true
|
||||
filter = { _, type ->
|
||||
val service = service<BuildSystemAvailabilityWizardService>()!!
|
||||
val service = service<BuildSystemAvailabilityWizardService>()
|
||||
service.isAvailable(type)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ abstract class BuildSystemPlugin(context: Context) : Plugin(context) {
|
||||
val createModules by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
|
||||
runAfter(StructurePlugin::createProjectDir)
|
||||
withAction {
|
||||
val fileSystem = service<FileSystemWizardService>()!!
|
||||
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 ->
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ abstract class GradlePlugin(context: Context) : BuildSystemPlugin(context) {
|
||||
repositories
|
||||
)
|
||||
val buildFileText = createBuildFile().printBuildFile { settingsGradleIR.render(this) }
|
||||
service<FileSystemWizardService>()!!.createFile(
|
||||
service<FileSystemWizardService>().createFile(
|
||||
projectPath / buildFileName,
|
||||
buildFileText
|
||||
)
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
||||
title = "Downloading list of Kotlin versions"
|
||||
|
||||
withAction {
|
||||
val version = service<KotlinVersionProviderService>()!!.getKotlinVersion()
|
||||
val version = service<KotlinVersionProviderService>().getKotlinVersion()
|
||||
KotlinPlugin::version.update { version.asSuccess() }
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
||||
val createSourcesetDirectories by pipelineTask(GenerationPhase.PROJECT_GENERATION) {
|
||||
runAfter(KotlinPlugin::createModules)
|
||||
withAction {
|
||||
fun Path.createKotlinAndResourceDirectories() = with(service<FileSystemWizardService>()!!) {
|
||||
fun Path.createKotlinAndResourceDirectories() = with(service<FileSystemWizardService>()) {
|
||||
createDirectory(this@createKotlinAndResourceDirectories / Defaults.KOTLIN_DIR) andThen
|
||||
createDirectory(this@createKotlinAndResourceDirectories / Defaults.RESOURCES_DIR)
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@ interface TemplateEngine {
|
||||
fun renderTemplate(template: FileTemplateDescriptor, data: Map<String, Any?>): String
|
||||
|
||||
fun TaskRunningContext.writeTemplate(template: FileTemplate): TaskResult<Unit> {
|
||||
val formatter = service<FileFormattingService>()!!
|
||||
val formatter = service<FileFormattingService>()
|
||||
val text = renderTemplate(template.descriptor, template.data).let { text ->
|
||||
formatter.formatFile(text, template.descriptor.relativePath.fileName.toString())
|
||||
}
|
||||
return service<FileSystemWizardService>()!!.createFile(template.rootPath / template.descriptor.relativePath, text)
|
||||
return service<FileSystemWizardService>().createFile(template.rootPath / template.descriptor.relativePath, text)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ abstract class Wizard(createPlugins: PluginsCreator, val servicesManager: Servic
|
||||
if (setting.neededAtPhase !in phases) continue
|
||||
if (!setting.isSavable) continue
|
||||
val serializer = setting.type.serializer as? SerializerImpl<Any> ?: continue
|
||||
service<SettingSavingWizardService>()!!.saveSettingValue(
|
||||
service<SettingSavingWizardService>().saveSettingValue(
|
||||
setting.path,
|
||||
serializer.toString(setting.reference.settingValue)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user