From cc14df9e6f9fdef082620e6f175e7756ca01a75b Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 6 Apr 2018 16:30:30 +0300 Subject: [PATCH] Always remove configure notifications without additional checks in tests (KT-23399) For some reason there were ~1000 tests that were spontaneously falling (~20%) because they couldn't find some class. It was mostly Java classes. Those failures started after cff88a3f8b0fe7207fa0aaf770c4bdb6e441269f. There were group of commits about notifications right before it: b4fb0e0305b77a0caa83d34edac3253b7d8e082b..1be33b91fa85e50f5048dc5a12604debfa3c19e8 #KT-23399 Fixed --- .../ConfigureKotlinNotificationManager.kt | 31 ++++++++++++------- .../ui/KotlinConfigurationCheckerComponent.kt | 2 ++ .../ConfigureKotlinNotification.kt | 2 ++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt index 13a6b4b1344..89e39db5fd9 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinNotificationManager.kt @@ -70,19 +70,28 @@ fun checkHideNonConfiguredNotifications(project: Project) { DumbService.getInstance(project).waitForSmartMode() val moduleSourceRootMap = ModuleSourceRootMap(project) - val hideNotification = try { - val moduleSourceRootGroups = notification.notificationState.notConfiguredModules - .mapNotNull { ModuleManager.getInstance(project).findModuleByName(it) } - .map { moduleSourceRootMap.getWholeModuleGroup(it) } - moduleSourceRootGroups.none(::isNotConfiguredNotificationRequired) - } catch (e: IndexNotReadyException) { - checkInProgress.set(false) - ApplicationManager.getApplication().invokeLater { - checkHideNonConfiguredNotifications(project) - } - return@executeOnPooledThread + if (notification.notificationState.debugProjectName != project.name) { + LOG.error("Bad notification check for project: ${project.name}\n${notification.notificationState}") } + val hideNotification = + if (!ApplicationManager.getApplication().isUnitTestMode) { + try { + val moduleSourceRootGroups = notification.notificationState.notConfiguredModules + .mapNotNull { ModuleManager.getInstance(project).findModuleByName(it) } + .map { moduleSourceRootMap.getWholeModuleGroup(it) } + moduleSourceRootGroups.none(::isNotConfiguredNotificationRequired) + } catch (e: IndexNotReadyException) { + checkInProgress.set(false) + ApplicationManager.getApplication().invokeLater { + checkHideNonConfiguredNotifications(project) + } + return@executeOnPooledThread + } + } else { + true + } + if (hideNotification) { ApplicationManager.getApplication().invokeLater { ConfigureKotlinNotificationManager.expireOldNotifications(project) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt index 40bdfb40e99..0b552ca653b 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/KotlinConfigurationCheckerComponent.kt @@ -48,6 +48,8 @@ class KotlinConfigurationCheckerComponent(project: Project) : AbstractProjectCom val connection = project.messageBus.connect() connection.subscribe(ProjectTopics.PROJECT_ROOTS, object : ModuleRootListener { override fun rootsChanged(event: ModuleRootEvent?) { + if (!project.isInitialized) return + if (notificationPostponed && !isSyncing) { ApplicationManager.getApplication().executeOnPooledThread { DumbService.getInstance(myProject).waitForSmartMode() diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt index 2932de5b291..523c398a24f 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ui/notifications/ConfigureKotlinNotification.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.idea.configuration.ui.KotlinConfigurationCheckerComp import javax.swing.event.HyperlinkEvent data class ConfigureKotlinNotificationState( + val debugProjectName: String, val notificationString: String, val notConfiguredModules: Collection ) @@ -64,6 +65,7 @@ class ConfigureKotlinNotification( } return ConfigureKotlinNotificationState( + project.name, "Configure $modulesString in '${project.name}' project
$links", configurableModules.map { it.baseModule.name } )