diff --git a/src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt b/src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt index 3fa6c1cd8..16a2cb5b6 100644 --- a/src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt +++ b/src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt @@ -21,7 +21,6 @@ package com.demonwav.mcdev.creator.custom import com.demonwav.mcdev.asset.MCDevBundle -import com.demonwav.mcdev.asset.MCDevBundle.invoke import com.demonwav.mcdev.creator.custom.finalizers.CreatorFinalizer import com.demonwav.mcdev.creator.custom.providers.EmptyLoadedTemplate import com.demonwav.mcdev.creator.custom.providers.LoadedTemplate @@ -56,12 +55,10 @@ import com.intellij.ui.dsl.builder.panel import com.intellij.util.application import java.nio.file.Path import java.util.function.Consumer -import kotlin.collections.mapNotNull -import kotlin.collections.orEmpty -import kotlin.collections.set import kotlin.io.path.createDirectories import kotlin.io.path.writeText import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch interface ExternalTemplatePropertyProvider { @@ -287,7 +284,7 @@ class CreatorTemplateProcessor( } } - val finalizeAction = { + val finalizeAction = suspend { WriteAction.runAndWait { LocalFileSystem.getInstance().refresh(false) // Apparently a module root is required for the reformat to work @@ -305,7 +302,7 @@ class CreatorTemplateProcessor( if (context.wizardContext.isCreatingNewProject) { TemplateService.instance.registerFinalizerAction(project, finalizeAction) } else { - application.executeOnPooledThread { finalizeAction() } + context.scope.launch { finalizeAction() } } } diff --git a/src/main/kotlin/creator/custom/finalizers/CreatorFinalizer.kt b/src/main/kotlin/creator/custom/finalizers/CreatorFinalizer.kt index 1c52d25f6..48afc8b40 100644 --- a/src/main/kotlin/creator/custom/finalizers/CreatorFinalizer.kt +++ b/src/main/kotlin/creator/custom/finalizers/CreatorFinalizer.kt @@ -38,7 +38,7 @@ interface CreatorFinalizer { fun validate(reporter: TemplateValidationReporter, properties: Map) = Unit - fun execute( + suspend fun execute( context: WizardContext, project: Project, properties: Map, @@ -83,7 +83,7 @@ interface CreatorFinalizer { } } - fun executeAll( + suspend fun executeAll( context: WizardContext, project: Project, finalizers: List>, diff --git a/src/main/kotlin/creator/custom/finalizers/GitAddAllFinalizer.kt b/src/main/kotlin/creator/custom/finalizers/GitAddAllFinalizer.kt index e2ebd6863..f639c9d20 100644 --- a/src/main/kotlin/creator/custom/finalizers/GitAddAllFinalizer.kt +++ b/src/main/kotlin/creator/custom/finalizers/GitAddAllFinalizer.kt @@ -27,7 +27,7 @@ import com.intellij.openapi.project.Project class GitAddAllFinalizer : CreatorFinalizer { - override fun execute( + override suspend fun execute( context: WizardContext, project: Project, properties: Map, diff --git a/src/main/kotlin/creator/custom/finalizers/ImportGradleProjectFinalizer.kt b/src/main/kotlin/creator/custom/finalizers/ImportGradleProjectFinalizer.kt index 2115dc3b8..ae4edc97c 100644 --- a/src/main/kotlin/creator/custom/finalizers/ImportGradleProjectFinalizer.kt +++ b/src/main/kotlin/creator/custom/finalizers/ImportGradleProjectFinalizer.kt @@ -28,7 +28,7 @@ import org.jetbrains.plugins.gradle.service.project.open.linkAndRefreshGradlePro class ImportGradleProjectFinalizer : CreatorFinalizer { - override fun execute( + override suspend fun execute( context: WizardContext, project: Project, properties: Map, diff --git a/src/main/kotlin/creator/custom/finalizers/ImportMavenProjectFinalizer.kt b/src/main/kotlin/creator/custom/finalizers/ImportMavenProjectFinalizer.kt index 88ce4cae9..2f5ea3f8f 100644 --- a/src/main/kotlin/creator/custom/finalizers/ImportMavenProjectFinalizer.kt +++ b/src/main/kotlin/creator/custom/finalizers/ImportMavenProjectFinalizer.kt @@ -25,13 +25,12 @@ import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VfsUtil import java.nio.file.Path -import kotlinx.coroutines.runBlocking import org.jetbrains.idea.maven.buildtool.MavenSyncSpec import org.jetbrains.idea.maven.project.MavenProjectsManager class ImportMavenProjectFinalizer : CreatorFinalizer { - override fun execute( + override suspend fun execute( context: WizardContext, project: Project, properties: Map, @@ -44,9 +43,7 @@ class ImportMavenProjectFinalizer : CreatorFinalizer { thisLogger().info("Invoking import on EDT pomFile = ${pomFile.path}") val projectsManager = MavenProjectsManager.getInstance(project) projectsManager.addManagedFiles(listOf(pomFile)) - runBlocking { - projectsManager.updateAllMavenProjects(MavenSyncSpec.incremental("ImportMavenProjectFinalizer", false)) - } + projectsManager.updateAllMavenProjects(MavenSyncSpec.incremental("ImportMavenProjectFinalizer", false)) thisLogger().info("Import finished") } diff --git a/src/main/kotlin/creator/custom/finalizers/RunGradleTasksFinalizer.kt b/src/main/kotlin/creator/custom/finalizers/RunGradleTasksFinalizer.kt index 210920426..c5021613f 100644 --- a/src/main/kotlin/creator/custom/finalizers/RunGradleTasksFinalizer.kt +++ b/src/main/kotlin/creator/custom/finalizers/RunGradleTasksFinalizer.kt @@ -39,7 +39,7 @@ class RunGradleTasksFinalizer : CreatorFinalizer { } } - override fun execute( + override suspend fun execute( context: WizardContext, project: Project, properties: Map,