From a49dbc59a629a55f1a6e2a1ccb91a67e6ee9f026 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Tue, 14 Nov 2023 10:27:08 +0100 Subject: [PATCH] handle null file configs (when removed) when notified of changes this change is required by the change in ConfigWatcher at https://github.com/redhat-developer/intellij-common/pull/202 Signed-off-by: Andre Dietisheim --- gradle.properties | 2 +- .../devtools/intellij/kubernetes/model/AllContexts.kt | 5 +++-- .../intellij/kubernetes/model/AllContextsTest.kt | 11 ++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6613acdc2..bcaa15b17 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ sinceIdeaBuild=232 projectVersion=1.2.1-SNAPSHOT jetBrainsToken=invalid jetBrainsChannel=stable -intellijPluginVersion=1.15.0 +intellijPluginVersion=1.16.0 intellijCommonVersion=1.9.3-SNAPSHOT telemetryPluginVersion=1.0.0.44 kotlin.stdlib.default.dependency = false diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt index 9eddc46f2..d3440bf58 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt @@ -245,12 +245,13 @@ open class AllContexts( * The latter gets closed/recreated whenever the context changes in * [com.redhat.devtools.intellij.kubernetes.model.client.KubeConfigAdapter]. */ - val watcher = ConfigWatcher(path) { _, config -> onKubeConfigChanged(config) } + val watcher = ConfigWatcher(path) { _, config: io.fabric8.kubernetes.api.model.Config? -> onKubeConfigChanged(config) } runAsync(watcher::run) } - protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config) { + protected open fun onKubeConfigChanged(fileConfig: io.fabric8.kubernetes.api.model.Config?) { synchronized(this) { + fileConfig ?: return val client = client.get() ?: return val clientConfig = client.config.configuration if (ConfigHelper.areEqual(fileConfig, clientConfig)) { diff --git a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt index aaf9aaa87..e3ede0a1a 100644 --- a/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt +++ b/src/test/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContextsTest.kt @@ -398,6 +398,15 @@ class AllContextsTest { verify(modelChange, never()).fireCurrentNamespaceChanged(anyOrNull(), anyOrNull()) } + @Test + fun `#onKubeConfigChanged() should NOT fire if new config is null`() { + // given + // when + allContexts.onKubeConfigChanged(null) + // then + verify(modelChange, never()).fireAllContextsChanged() + } + @Test fun `#onKubeConfigChanged() should NOT fire if existing config and given config are equal`() { // given @@ -550,7 +559,7 @@ class AllContextsTest { } /** override with public method so that it can be tested**/ - public override fun onKubeConfigChanged(fileConfig: Config) { + public override fun onKubeConfigChanged(fileConfig: Config?) { super.onKubeConfigChanged(fileConfig) }