diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 9544af09c998..0be104e3380d 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -89,7 +89,7 @@ abstract class ProjectStoreBase(final override val project: Project) : Component } final override fun loadProjectFromTemplate(defaultProject: Project) { - defaultProject.save() + runBlocking { defaultProject.stateStore.save() } val element = (defaultProject.stateStore as DefaultProjectStoreImpl).getStateCopy() ?: return LOG.runAndLogException { diff --git a/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt b/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt index f5b1d8b1e68a..1dd96a09cbe0 100644 --- a/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/DefaultProjectStoreTest.kt @@ -4,20 +4,16 @@ package com.intellij.configurationStore import com.intellij.externalDependencies.DependencyOnPlugin import com.intellij.externalDependencies.ExternalDependenciesManager import com.intellij.externalDependencies.ProjectExternalDependency -import com.intellij.openapi.application.ex.ApplicationManagerEx +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ex.PathManagerEx -import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.components.* import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.util.JDOMUtil -import com.intellij.openapi.vfs.LocalFileSystem -import com.intellij.openapi.vfs.refreshVfs import com.intellij.testFramework.* import com.intellij.testFramework.assertions.Assertions.assertThat import com.intellij.testFramework.rules.InMemoryFsRule import com.intellij.util.io.delete import com.intellij.util.io.getDirectoryTree -import com.intellij.util.io.systemIndependentPath import com.intellij.util.isEmpty import com.intellij.util.loadElement import kotlinx.coroutines.runBlocking @@ -52,7 +48,6 @@ internal class DefaultProjectStoreTest { val fsRule = InMemoryFsRule() private val tempDirManager = TemporaryDirectory() - private val requiredPlugins = listOf(DependencyOnPlugin("fake", "0", "1")) @JvmField @@ -60,22 +55,9 @@ internal class DefaultProjectStoreTest { val ruleChain = RuleChain( tempDirManager, WrapRule { - val app = ApplicationManagerEx.getApplicationEx() - val path = Paths.get(app.stateStore.storageManager.expandMacros(APP_CONFIG)) - // dream about using in memory fs per test as ICS partially does and avoid such hacks - path.refreshVfs() - - val isSaveAllowed = app.isSaveAllowed - app.isSaveAllowed = true - { - try { - app.isSaveAllowed = isSaveAllowed - } - finally { - path.delete() - val virtualFile = LocalFileSystem.getInstance().findFileByPathIfCached(path.systemIndependentPath) - runInEdtAndWait { runWriteAction { virtualFile?.delete(null) } } - } + val path = Paths.get(ApplicationManager.getApplication().stateStore.storageManager.expandMacros(APP_CONFIG)) + return@WrapRule { + path.delete() } } ) @@ -133,7 +115,8 @@ internal class DefaultProjectStoreTest { assertThat(directoryTree.trim()).isEqualTo(testData.resolve("testData1.txt")) } - @Test fun `new IPR project from default - remove workspace component configuration`() { + @Test + fun `new IPR project from default - remove workspace component configuration`() { val testData = Paths.get(PathManagerEx.getCommunityHomePath(), "platform/configuration-store-impl/testData") val element = loadElement(testData.resolve("testData1.xml")) diff --git a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt index 77168377dc26..0a88cc38094c 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt @@ -1,13 +1,17 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.laf -import com.intellij.openapi.application.invokeAndWaitIfNeed +import com.intellij.openapi.application.AppUIExecutor +import com.intellij.openapi.application.async.coroutineDispatchingContext import com.intellij.openapi.util.SystemInfo import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.ProjectRule import com.intellij.testFramework.UsefulTestCase import com.intellij.ui.UiTestRule import com.intellij.ui.changeLafIfNeed import com.intellij.ui.layout.* +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.ClassRule @@ -30,6 +34,10 @@ class LafTest { @Parameterized.Parameters(name = "{0}") fun lafNames() = listOf("Darcula", "IntelliJ") + @JvmField + @ClassRule + val appRule = ProjectRule() + @JvmField @ClassRule val uiRule = UiTestRule(Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "laf")) @@ -44,7 +52,7 @@ class LafTest { val testName = TestName() @Before - fun beforeMethod() { + fun beforeMethod() = runBlocking { if (UsefulTestCase.IS_UNDER_TEAMCITY) { assumeTrue("macOS or Windows 10 are required", SystemInfo.isMacOSMojave || SystemInfo.isWin10OrNewer) } @@ -53,14 +61,14 @@ class LafTest { } @Test - fun components() { + fun components() = runBlocking { doTest { createLafTestPanel() } } - private fun doTest(panelCreator: () -> JPanel) { - invokeAndWaitIfNeed { + private suspend fun doTest(panelCreator: () -> JPanel) { + withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) { uiRule.validate(panelCreator(), testName, lafName) } } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt index 7dce83dcf42f..99cf7bbea338 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt @@ -1,13 +1,17 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.layout -import com.intellij.openapi.application.invokeAndWaitIfNeed +import com.intellij.openapi.application.AppUIExecutor +import com.intellij.openapi.application.async.coroutineDispatchingContext import com.intellij.openapi.util.SystemInfo import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.ProjectRule import com.intellij.testFramework.UsefulTestCase import com.intellij.ui.UiTestRule import com.intellij.ui.changeLafIfNeed import com.intellij.ui.layout.migLayout.patched.* +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import org.junit.* import org.junit.Assume.assumeTrue import org.junit.rules.TestName @@ -26,6 +30,10 @@ class UiDslTest { @Parameterized.Parameters(name = "{0}") fun lafNames() = listOf("Darcula", "IntelliJ") + @JvmField + @ClassRule + val appRule = ProjectRule() + @JvmField @ClassRule val uiRule = UiTestRule(Paths.get(PlatformTestUtil.getPlatformTestDataPath(), "ui", "layout")) @@ -44,7 +52,7 @@ class UiDslTest { val testName = TestName() @Before - fun beforeMethod() { + fun beforeMethod() = runBlocking { if (UsefulTestCase.IS_UNDER_TEAMCITY) { // let's for now to see how it is going on macOS assumeTrue("macOS or Windows 10 are required", SystemInfo.isMacOSHighSierra /* || SystemInfo.isWin10OrNewer */) @@ -117,11 +125,13 @@ class UiDslTest { } private fun doTest(panelCreator: () -> JPanel) { - invokeAndWaitIfNeed { - val panel = panelCreator() - // otherwise rectangles are not set - (panel.layout as MigLayout).isDebugEnabled = true - uiRule.validate(panel, testName, lafName) + runBlocking { + withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) { + val panel = panelCreator() + // otherwise rectangles are not set + (panel.layout as MigLayout).isDebugEnabled = true + uiRule.validate(panel, testName, lafName) + } } } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt index 3e84d8924cab..a9fea97910a8 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt @@ -1,9 +1,10 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui import com.intellij.ide.ui.laf.IntelliJLaf import com.intellij.ide.ui.laf.darcula.DarculaLaf -import com.intellij.openapi.application.invokeAndWaitIfNeed +import com.intellij.openapi.application.AppUIExecutor +import com.intellij.openapi.application.async.coroutineDispatchingContext import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.text.StringUtil import com.intellij.rt.execution.junit.FileComparisonFailure @@ -20,6 +21,7 @@ import com.intellij.util.io.write import com.intellij.util.ui.TestScaleHelper import com.intellij.util.ui.UIUtil import com.intellij.util.ui.paint.ImageComparator +import kotlinx.coroutines.withContext import org.junit.rules.ExternalResource import org.junit.rules.TestName import org.junit.runners.model.MultipleFailureException @@ -65,14 +67,14 @@ open class RestoreScaleRule : ExternalResource() { } } -fun changeLafIfNeed(lafName: String) { +suspend fun changeLafIfNeed(lafName: String) { System.setProperty("idea.ui.set.password.echo.char", "true") if (UIManager.getLookAndFeel().name == lafName) { return } - invokeAndWaitIfNeed { + withContext(AppUIExecutor.onUiThread().coroutineDispatchingContext()) { UIManager.setLookAndFeel(MetalLookAndFeel()) val laf = if (lafName == "IntelliJ") IntelliJLaf() else DarculaLaf() UIManager.setLookAndFeel(laf)