Wizard: move downloading Kotlin version phase to the end

This commit is contained in:
Ilya Kirillov
2020-03-01 12:34:57 +03:00
parent a03510e3c0
commit a9c96a7cde
5 changed files with 27 additions and 19 deletions
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.service.IdeaServices
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.PomWizardStepComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.asHtml
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep.FirstWizardStepComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.runWithProgressBar
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.SecondStepWizardComponent
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.nio.file.Paths
@@ -211,16 +212,11 @@ class ModuleNewWizardFirstStep(wizard: IdeWizard) : WizardStep(wizard, Generatio
component.onInit()
}
private fun runPreparePhase() = ProgressManager.getInstance().runProcessWithProgressSynchronously(
{
wizard.apply(emptyList(), setOf(GenerationPhase.PREPARE)) { task ->
ProgressManager.getInstance().progressIndicator.text = task.title ?: ""
}
},
"",
true,
null
)
private fun runPreparePhase() = runWithProgressBar(title = "") {
wizard.apply(emptyList(), setOf(GenerationPhase.PREPARE)) { task ->
ProgressManager.getInstance().progressIndicator.text = task.title ?: ""
}
}
}
class ModuleNewWizardSecondStep(
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.tools.projectWizard.wizard.service
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.idea.KotlinPluginUtil
import org.jetbrains.kotlin.idea.framework.ui.ConfigureDialogWithModulesAndVersion
import org.jetbrains.kotlin.tools.projectWizard.core.TaskResult
import org.jetbrains.kotlin.tools.projectWizard.core.asNullable
@@ -15,6 +14,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.safe
import org.jetbrains.kotlin.tools.projectWizard.core.service.KotlinVersionProviderService
import org.jetbrains.kotlin.tools.projectWizard.core.service.KotlinVersionProviderServiceImpl
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.runWithProgressBar
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
@@ -23,17 +23,20 @@ import java.util.stream.Collectors
class IdeaKotlinVersionProviderService : KotlinVersionProviderService, IdeaWizardService {
override fun getKotlinVersion(): Version =
KotlinCompilerVersion.getVersion()?.let { Version.fromString(it) }
?: VersionsDownloader.getLatestEapOrStableKotlinVersion()
?: VersionsDownloader.downloadLatestEapOrStableKotlinVersion()
?: KotlinVersionProviderServiceImpl.DEFAULT
}
private object VersionsDownloader {
fun getLatestEapOrStableKotlinVersion(): Version? {
fun downloadLatestEapOrStableKotlinVersion(): Version? = runWithProgressBar("Downloading Kotlin version") {
val latestEap = EapVersionDownloader.getLatestEapVersion()
val latestStable = getLatestStableVersion()
if (latestEap == null) return latestStable
if (latestStable == null) return latestEap
return if (latestEap > latestStable) latestEap else latestStable
when {
latestEap == null -> latestStable
latestStable == null -> latestEap
latestEap > latestStable -> latestEap
else -> latestStable
}
}
private fun getLatestStableVersion() = safe {
@@ -6,10 +6,11 @@ import com.intellij.ide.plugins.newui.TagComponent
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.ui.*
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.tools.projectWizard.core.Failure
@@ -175,6 +176,14 @@ class TemplateTagUIComponent(tag: TemplateTag) : TagComponent(tag.text) {
}
}
fun <T> runWithProgressBar(title: String, action: () -> T): T =
ProgressManager.getInstance().runProcessWithProgressSynchronously(
ThrowableComputable<T, Exception> { action() },
title,
true,
null
)
object UiConstants {
const val GAP_BORDER_SIZE = 5
@@ -1,7 +1,7 @@
package org.jetbrains.kotlin.tools.projectWizard.phases
enum class GenerationPhase {
PREPARE, INIT_TEMPLATE, FIRST_STEP, SECOND_STEP, PROJECT_GENERATION, PROJECT_IMPORT
PREPARE, INIT_TEMPLATE, FIRST_STEP, SECOND_STEP, PREPARE_GENERATION, PROJECT_GENERATION, PROJECT_IMPORT
;
@@ -23,7 +23,7 @@ import java.nio.file.Path
class KotlinPlugin(context: Context) : Plugin(context) {
val version by property(KotlinVersionProviderServiceImpl.DEFAULT)
val initKotlinVersions by pipelineTask(GenerationPhase.PREPARE) {
val initKotlinVersions by pipelineTask(GenerationPhase.PREPARE_GENERATION) {
title = "Downloading list of Kotlin versions"
withAction {