User: joe Date: 16 Nov 26 03:19 Revision: ae42bb2429567fa772712f20477b4f964418e99a Summary: Hopefully fix flaky tests TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10803&personal=false Index: src/main/kotlin/facet/MinecraftFacet.kt =================================================================== --- src/main/kotlin/facet/MinecraftFacet.kt (revision 268df828bbcfbf880c77389051016bee7ac443ef) +++ src/main/kotlin/facet/MinecraftFacet.kt (revision ae42bb2429567fa772712f20477b4f964418e99a) @@ -78,10 +78,10 @@ fun refresh() { refreshWritePhase() // Refresh the project view separately to not hold the write lock - ApplicationManager.getApplication().invokeLater { + ApplicationManager.getApplication().invokeLater({ ProjectView.getInstance(module.project).refresh() + }, module.disposed) - } + } - } private fun refreshWritePhase() = runWriteActionAndWait { if (module.isDisposed) { Index: src/main/kotlin/facet/MinecraftFacetDetector.kt =================================================================== --- src/main/kotlin/facet/MinecraftFacetDetector.kt (revision 268df828bbcfbf880c77389051016bee7ac443ef) +++ src/main/kotlin/facet/MinecraftFacetDetector.kt (revision ae42bb2429567fa772712f20477b4f964418e99a) @@ -26,7 +26,6 @@ import com.demonwav.mcdev.platform.fabric.framework.FABRIC_LIBRARY_KIND import com.demonwav.mcdev.platform.minecraft.gradle.tooling.archloom.ArchitecturyModel import com.demonwav.mcdev.platform.sponge.framework.SPONGE_LIBRARY_KIND -import com.demonwav.mcdev.util.ifEmpty import com.demonwav.mcdev.util.runWriteTaskLater import com.intellij.facet.FacetManager import com.intellij.facet.impl.ui.libraries.LibrariesValidatorContextImpl @@ -109,13 +108,18 @@ var needsReimport = false moduleManager.modules.asList().forEachWithProgress { module -> - val facetManager = FacetManager.getInstance(module) - val minecraftFacet = facetManager.getFacetByType(MinecraftFacet.ID) + // The module may be disposed while this runs in the background, check under the read lock + val (minecraftFacet, platforms) = readAction { + if (module.isDisposed) { + return@readAction null + } + FacetManager.getInstance(module).getFacetByType(MinecraftFacet.ID) to autoDetectTypes(module) + } ?: return@forEachWithProgress if (minecraftFacet == null) { - checkNoFacet(module) + checkNoFacet(module, platforms) } else { - checkExistingFacet(module, minecraftFacet) + checkExistingFacet(minecraftFacet, platforms) if (ProjectReimporter.needsReimport(minecraftFacet)) { needsReimport = true } @@ -129,14 +133,10 @@ } } - private suspend fun checkNoFacet(module: Module) { - val platforms = readAction { - if (!module.isDisposed) { - autoDetectTypes(module) - } else { - emptyList() + private fun checkNoFacet(module: Module, platforms: Set) { + if (platforms.isEmpty()) { + return - } + } - }.ifEmpty { return } runWriteTaskLater { // Only add the new facet if there isn't a Minecraft facet already - double check here since this @@ -161,8 +161,10 @@ } } - private fun checkExistingFacet(module: Module, facet: MinecraftFacet) { - val platforms = autoDetectTypes(module).ifEmpty { return } + private fun checkExistingFacet(facet: MinecraftFacet, platforms: Set) { + if (platforms.isEmpty()) { + return + } val types = facet.configuration.state.autoDetectTypes types.clear()