Skip to content

Commit

Permalink
Make CreatorFinalizer#execute suspendable
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Sep 12, 2024
1 parent e4ae7da commit 2001f3c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/main/kotlin/creator/custom/CreatorTemplateProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -287,7 +284,7 @@ class CreatorTemplateProcessor(
}
}

val finalizeAction = {
val finalizeAction = suspend {
WriteAction.runAndWait<Throwable> {
LocalFileSystem.getInstance().refresh(false)
// Apparently a module root is required for the reformat to work
Expand All @@ -305,7 +302,7 @@ class CreatorTemplateProcessor(
if (context.wizardContext.isCreatingNewProject) {
TemplateService.instance.registerFinalizerAction(project, finalizeAction)
} else {
application.executeOnPooledThread { finalizeAction() }
context.scope.launch { finalizeAction() }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/creator/custom/finalizers/CreatorFinalizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface CreatorFinalizer {

fun validate(reporter: TemplateValidationReporter, properties: Map<String, Any>) = Unit

fun execute(
suspend fun execute(
context: WizardContext,
project: Project,
properties: Map<String, Any>,
Expand Down Expand Up @@ -83,7 +83,7 @@ interface CreatorFinalizer {
}
}

fun executeAll(
suspend fun executeAll(
context: WizardContext,
project: Project,
finalizers: List<Map<String, Any>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>,
Expand All @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RunGradleTasksFinalizer : CreatorFinalizer {
}
}

override fun execute(
override suspend fun execute(
context: WizardContext,
project: Project,
properties: Map<String, Any>,
Expand Down

0 comments on commit 2001f3c

Please sign in to comment.