User: kyle wood Date: 04 Aug 24 03:15 Revision: 5a17d89a42ed3fb3c4a834b203dd5e9bfe183594 Summary: Merge branch '2024.1' into 2024.2 TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9551&personal=false Index: build.gradle.kts =================================================================== --- build.gradle.kts (revision b3e691e5a3176c07bd7a7001da12454287d63fb3) +++ build.gradle.kts (revision 5a17d89a42ed3fb3c4a834b203dd5e9bfe183594) @@ -124,7 +124,6 @@ implementation(libs.mixinExtras.expressions) testLibs(libs.mixinExtras.common) - implementation("org.ow2.asm:asm-util:9.3") // Kotlin implementation(kotlin("stdlib-jdk8")) @@ -305,11 +304,10 @@ tasks.test { dependsOn(tasks.jar, testLibs) useJUnitPlatform() - doFirst { + - testLibs.resolvedConfiguration.resolvedArtifacts.forEach { - systemProperty("testLibs.${it.name}", it.file.absolutePath) - } + testLibs.resolvedConfiguration.resolvedArtifacts.forEach { + systemProperty("testLibs.${it.name}", it.file.absolutePath) + } - } systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true") systemProperty("java.awt.headless", "true") Index: gradle/libs.versions.toml =================================================================== --- gradle/libs.versions.toml (revision b3e691e5a3176c07bd7a7001da12454287d63fb3) +++ gradle/libs.versions.toml (revision 5a17d89a42ed3fb3c4a834b203dd5e9bfe183594) @@ -26,6 +26,7 @@ asm = { module = "org.ow2.asm:asm", version.ref = "asm" } asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" } asm-analysis = { module = "org.ow2.asm:asm-analysis", version.ref = "asm" } +asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" } fuel = { module = "com.github.kittinunf.fuel:fuel", version.ref = "fuel" } fuel-coroutines = { module = "com.github.kittinunf.fuel:fuel-coroutines", version.ref = "fuel" } @@ -45,5 +46,5 @@ [bundles] coroutines = ["coroutines-swing"] -asm = ["asm", "asm-tree", "asm-analysis"] +asm = ["asm", "asm-tree", "asm-analysis", "asm-util"] fuel = ["fuel", "fuel-coroutines"] Index: src/main/kotlin/creator/custom/CustomPlatformStep.kt =================================================================== --- src/main/kotlin/creator/custom/CustomPlatformStep.kt (revision b3e691e5a3176c07bd7a7001da12454287d63fb3) +++ src/main/kotlin/creator/custom/CustomPlatformStep.kt (revision 5a17d89a42ed3fb3c4a834b203dd5e9bfe183594) @@ -32,13 +32,16 @@ import com.demonwav.mcdev.creator.modalityState import com.demonwav.mcdev.util.toTypedArray import com.demonwav.mcdev.util.virtualFileOrError +import com.intellij.codeInsight.CodeInsightSettings import com.intellij.codeInsight.actions.ReformatCodeProcessor import com.intellij.ide.projectView.ProjectView import com.intellij.ide.wizard.AbstractNewProjectWizardStep import com.intellij.ide.wizard.GitNewProjectWizardData import com.intellij.ide.wizard.NewProjectWizardBaseData import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.application.EDT import com.intellij.openapi.application.WriteAction +import com.intellij.openapi.application.asContextElement import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.ControlFlowException import com.intellij.openapi.diagnostic.getOrLogException @@ -47,11 +50,9 @@ import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.observable.util.transform -import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.progress.ProgressManager -import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager @@ -76,6 +77,11 @@ import kotlin.collections.set import kotlin.io.path.createDirectories import kotlin.io.path.writeText +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancel +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext /** * The step to select a custom template repo. @@ -84,6 +90,8 @@ parent: NewProjectWizardStep, ) : AbstractNewProjectWizardStep(parent) { + val creatorScope = TemplateService.instance.scope("MinecraftDev Creator") + val creatorUiScope = TemplateService.instance.scope("MinecraftDev Creator UI") val templateRepos = MinecraftSettings.instance.creatorTemplateRepos val templateRepoProperty = propertyGraph.property( @@ -108,17 +116,25 @@ val templateProvidersText2Property = propertyGraph.property("") lateinit var templateProvidersProcessIcon: Cell - val templateLoadingProperty = propertyGraph.property(true) + val templateLoadingProperty = propertyGraph.property(false) val templateLoadingTextProperty = propertyGraph.property("") val templateLoadingText2Property = propertyGraph.property("") lateinit var templatePropertiesProcessIcon: Cell lateinit var noTemplatesAvailable: Cell - var templateLoadingIndicator: ProgressIndicator? = null + var templateLoadingJob: Job? = null private var hasTemplateErrors: Boolean = true private var properties = mutableMapOf>() + private var creatorContext = CreatorContext(propertyGraph, properties, context, creatorScope) + init { + Disposer.register(context.disposable) { + creatorScope.cancel("The creator got disposed") + creatorUiScope.cancel("The creator got disposed") + } + } + override fun setupUI(builder: Panel) { lateinit var templatePropertyPlaceholder: Placeholder @@ -130,16 +146,12 @@ builder.row { templateProvidersProcessIcon = cell(AsyncProcessIcon("TemplateProviders init")) - .visibleIf(templateProvidersLoadingProperty) label(MCDevBundle("creator.step.generic.init_template_providers.message")) - .visibleIf(templateProvidersLoadingProperty) label("") .bindText(templateProvidersTextProperty) - .visibleIf(templateProvidersLoadingProperty) label("") .bindText(templateProvidersText2Property) - .visibleIf(templateProvidersLoadingProperty) - } + }.visibleIf(templateProvidersLoadingProperty) templateRepoProperty.afterChange { templateRepo -> templatePropertyPlaceholder.component = null @@ -217,100 +229,69 @@ private fun initTemplates() { selectedTemplate = EmptyLoadedTemplate - val task = object : Task.Backgroundable( - context.project, - MCDevBundle("creator.step.generic.init_template_providers.message"), - true, - ALWAYS_BACKGROUND, - ) { + templateRepoProperty.set(templateRepos.first()) - override fun run(indicator: ProgressIndicator) { - if (project?.isDisposed == true) { - return - } + val indicator = CreatorProgressIndicator( + templateProvidersLoadingProperty, + templateProvidersTextProperty, + templateProvidersText2Property + ) - application.invokeAndWait({ - ProgressManager.checkCanceled() + templateProvidersTextProperty.set(MCDevBundle("creator.step.generic.init_template_providers.message")) - templateProvidersLoadingProperty.set(true) + templateProvidersLoadingProperty.set(true) - VirtualFileManager.getInstance().syncRefresh() - }, context.modalityState) + val dialogCoroutineContext = context.modalityState.asContextElement() + val uiContext = dialogCoroutineContext + Dispatchers.EDT + creatorUiScope.launch(dialogCoroutineContext) { + withContext(uiContext) { + application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() } + } + - for ((providerKey, repos) in templateRepos.groupBy { it.provider }) { + for ((providerKey, repos) in templateRepos.groupBy { it.provider }) { - ProgressManager.checkCanceled() - val provider = TemplateProvider.get(providerKey) - ?: continue - indicator.text = provider.label - runCatching { provider.init(indicator, repos) } - .getOrLogException(logger()) - } + val provider = TemplateProvider.get(providerKey) + ?: continue + indicator.text = provider.label + runCatching { provider.init(indicator, repos) } + .getOrLogException(logger()) + } - ProgressManager.checkCanceled() - application.invokeAndWait({ - ProgressManager.checkCanceled() + withContext(uiContext) { - templateProvidersLoadingProperty.set(false) - // Force refresh to trigger template loading - templateRepoProperty.set(templateRepo) + templateProvidersLoadingProperty.set(false) + // Force refresh to trigger template loading + templateRepoProperty.set(templateRepo) - }, context.modalityState) } } - - val indicator = CreatorProgressIndicator( - templateProvidersLoadingProperty, - templateProvidersTextProperty, - templateProvidersText2Property - ) - ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator) } - private fun loadTemplatesInBackground(provider: () -> Collection) { + private fun loadTemplatesInBackground(provider: suspend () -> Collection) { selectedTemplate = EmptyLoadedTemplate - val task = object : Task.Backgroundable( - context.project, - MCDevBundle("creator.step.generic.load_template.message"), - true, - ALWAYS_BACKGROUND, - ) { + templateLoadingTextProperty.set(MCDevBundle("creator.step.generic.load_template.message")) + templateLoadingProperty.set(true) - override fun run(indicator: ProgressIndicator) { - if (project?.isDisposed == true) { - return + val dialogCoroutineContext = context.modalityState.asContextElement() + val uiContext = dialogCoroutineContext + Dispatchers.EDT + templateLoadingJob?.cancel("Another template has been selected") + templateLoadingJob = creatorUiScope.launch(dialogCoroutineContext) { + withContext(uiContext) { + application.runWriteAction { VirtualFileManager.getInstance().syncRefresh() } - } + } - application.invokeAndWait({ - ProgressManager.checkCanceled() - templateLoadingProperty.set(true) - VirtualFileManager.getInstance().syncRefresh() - }, context.modalityState) - - ProgressManager.checkCanceled() - val newTemplates = runCatching { provider() } - .getOrLogException(logger()) - ?: emptyList() + val newTemplates = runCatching { provider() } + .getOrLogException(logger()) + ?: emptyList() - ProgressManager.checkCanceled() - application.invokeAndWait({ - ProgressManager.checkCanceled() + withContext(uiContext) { - templateLoadingProperty.set(false) - noTemplatesAvailable.visible(newTemplates.isEmpty()) - availableTemplates = newTemplates + templateLoadingProperty.set(false) + noTemplatesAvailable.visible(newTemplates.isEmpty()) + availableTemplates = newTemplates - }, context.modalityState) } } - - templateLoadingIndicator?.cancel() - - val indicator = CreatorProgressIndicator( - templateLoadingProperty, - templateLoadingTextProperty, - templateLoadingText2Property - ) - templateLoadingIndicator = indicator - ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator) } private fun createOptionsPanelInBackground(template: LoadedTemplate, placeholder: Placeholder) { properties = mutableMapOf() + creatorContext = creatorContext.copy(properties = properties) if (!template.isValid) { return @@ -320,8 +301,7 @@ ?: return thisLogger().error("Could not find wizard base data") properties["PROJECT_NAME"] = ExternalCreatorProperty( - graph = propertyGraph, - properties = properties, + context = creatorContext, graphProperty = baseData.nameProperty, valueType = String::class.java ) @@ -421,7 +401,7 @@ reporter.fatal("Duplicate property name ${descriptor.name}") } - val prop = CreatorPropertyFactory.createFromType(descriptor.type, descriptor, propertyGraph, properties) + val prop = CreatorPropertyFactory.createFromType(descriptor.type, descriptor, creatorContext) if (prop == null) { reporter.fatal("Unknown template property type ${descriptor.type}") } @@ -434,7 +414,7 @@ return null } - val factory = Consumer { panel -> prop.buildUi(panel, context) } + val factory = Consumer { panel -> prop.buildUi(panel) } val order = descriptor.order ?: 0 return factory to order } @@ -554,8 +534,19 @@ val psiFiles = files.asSequence() .filter { (desc, _) -> desc.reformat != false } .mapNotNull { (_, file) -> psiManager.findFile(file) } - ReformatCodeProcessor(project, psiFiles.toTypedArray(), null, false).run() + + val processor = ReformatCodeProcessor(project, psiFiles.toTypedArray(), null, false) + psiFiles.forEach(processor::setDoNotKeepLineBreaks) + + val insightSettings = CodeInsightSettings.getInstance() + val oldSecondReformat = insightSettings.ENABLE_SECOND_REFORMAT + insightSettings.ENABLE_SECOND_REFORMAT = true + try { + processor.run() + } finally { + insightSettings.ENABLE_SECOND_REFORMAT = oldSecondReformat - } + } + } private fun openFilesInEditor( project: Project, Index: src/main/kotlin/util/HttpConnectionFactory.kt =================================================================== --- src/main/kotlin/util/HttpConnectionFactory.kt (revision b3e691e5a3176c07bd7a7001da12454287d63fb3) +++ src/main/kotlin/util/HttpConnectionFactory.kt (revision 5a17d89a42ed3fb3c4a834b203dd5e9bfe183594) @@ -22,10 +22,10 @@ import com.intellij.util.net.HttpConnectionUtils import java.net.HttpURLConnection -import java.net.URL +import java.net.URI sealed class HttpConnectionFactory { - open fun openHttpConnection(url: String) = URL(url).openConnection() as HttpURLConnection + open fun openHttpConnection(url: String) = URI.create(url).toURL().openConnection() as HttpURLConnection } object ProxyHttpConnectionFactory : HttpConnectionFactory() {