Skip to content

Commit 57774ac

Browse files
committed
fix: corrected incompatibilities (#749)
* removed call to ExtensionPointName.create (#749) * made instantiation of PresentationFactory compatible (#749) * removed TriConsumer from commons to make build compatible (#749) * removed deprecated UtilKt.isNull0rEmpty(Collection)(#749) * removed deprecated EdtInvocationManager.isEventDispatchThread(#749) * replaced deprecated StructureTreeModel.invalidate()(#749) Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 66de7f5 commit 57774ac

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jetBrainsToken=invalid
77
jetBrainsChannel=stable
88
intellijPluginVersion=1.16.1
99
kotlinJvmPluginVersion=1.8.0
10-
intellijCommonVersion=1.9.4
10+
intellijCommonVersion=1.9.5-SNAPSHOT
1111
telemetryPluginVersion=1.1.0.52
1212
kotlin.stdlib.default.dependency = false
1313
kotlinVersion=1.6.21

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/ResourceFile.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ import com.intellij.openapi.util.io.FileUtil
2020
import com.intellij.openapi.util.io.FileUtilRt
2121
import com.intellij.openapi.vfs.VfsUtil
2222
import com.intellij.openapi.vfs.VirtualFile
23-
import com.intellij.util.ui.EdtInvocationManager
23+
import com.intellij.util.ui.EDT
2424
import com.redhat.devtools.intellij.common.editor.AllowNonProjectEditing
2525
import com.redhat.devtools.intellij.common.utils.UIHelper
2626
import com.redhat.devtools.intellij.kubernetes.model.Notification
2727
import com.redhat.devtools.intellij.kubernetes.model.util.trimWithEllipsis
2828
import io.fabric8.kubernetes.api.model.HasMetadata
2929
import io.fabric8.kubernetes.client.utils.Serialization
30+
import org.apache.commons.io.FileUtils
31+
import org.jetbrains.yaml.YAMLFileType
3032
import java.io.IOException
3133
import java.nio.charset.StandardCharsets
3234
import java.nio.file.Files
3335
import java.nio.file.Path
3436
import java.nio.file.Paths
3537
import java.util.function.Supplier
36-
import org.apache.commons.io.FileUtils
37-
import org.jetbrains.yaml.YAMLFileType
3838

3939
/**
4040
* Helper that offers operations on the [VirtualFile] for a [ResourceEditor]
@@ -135,7 +135,7 @@ open class ResourceFile protected constructor(
135135
* When invoking synchronous refresh from a thread other than the event dispatch thread,
136136
* the current thread must NOT be in a read action, otherwise a deadlock may occur
137137
*/
138-
if (EdtInvocationManager.getInstance().isEventDispatchThread) {
138+
if (EDT.isCurrentThreadEdt()) {
139139
executeReadAction {
140140
virtualFile.refresh(false, false)
141141
}

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/inlay/Base64Presentations.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
@file:Suppress("UnstableApiUsage")
1212
package com.redhat.devtools.intellij.kubernetes.editor.inlay
1313

14+
import PresentationFactoryBuilder
1415
import com.intellij.codeInsight.hints.InlayHintsSink
1516
import com.intellij.codeInsight.hints.presentation.InlayPresentation
16-
import com.intellij.codeInsight.hints.presentation.PresentationFactory
1717
import com.intellij.openapi.command.WriteCommandAction
1818
import com.intellij.openapi.editor.Editor
19-
import com.intellij.openapi.editor.impl.EditorImpl
2019
import com.intellij.openapi.project.Project
2120
import com.intellij.psi.PsiElement
2221
import com.redhat.devtools.intellij.common.validation.KubernetesResourceInfo
2322
import com.redhat.devtools.intellij.kubernetes.balloon.StringInputBalloon
23+
import com.redhat.devtools.intellij.kubernetes.editor.inlay.Base64Presentations.InlayPresentationsFactory
24+
import com.redhat.devtools.intellij.kubernetes.editor.inlay.Base64Presentations.create
2425
import com.redhat.devtools.intellij.kubernetes.editor.util.getBinaryData
2526
import com.redhat.devtools.intellij.kubernetes.editor.util.getData
2627
import com.redhat.devtools.intellij.kubernetes.editor.util.isKubernetesResource
@@ -94,7 +95,7 @@ object Base64Presentations {
9495
}
9596

9697
private fun create(text: String, onClick: (event: MouseEvent) -> Unit, editor: Editor): InlayPresentation? {
97-
val factory = PresentationFactory(editor as EditorImpl)
98+
val factory = PresentationFactoryBuilder.build(editor) ?: return null
9899
val trimmed = trimWithEllipsis(text, INLAY_HINT_MAX_WIDTH) ?: return null
99100
val textPresentation = factory.smallText(trimmed)
100101
val hoverPresentation = factory.referenceOnHover(textPresentation) { event, _ ->
@@ -129,7 +130,7 @@ object Base64Presentations {
129130
}
130131

131132
private fun create(bytes: ByteArray, editor: Editor): InlayPresentation? {
132-
val factory = PresentationFactory(editor as EditorImpl)
133+
val factory = PresentationFactoryBuilder.build(editor) ?: return null
133134
val hex = toHexString(bytes) ?: return null
134135
val trimmed = trimWithEllipsis(hex, INLAY_HINT_MAX_WIDTH) ?: return null
135136
return factory.roundWithBackground(factory.smallText(trimmed))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
import com.intellij.codeInsight.hints.presentation.PresentationFactory
12+
import com.intellij.openapi.editor.Editor
13+
14+
/**
15+
* A factory that creates a [PresentationFactory]. This class bridges the difference in API between
16+
* <= IC-2022.3 and above.
17+
*/
18+
object PresentationFactoryBuilder {
19+
fun build(editor: Editor): PresentationFactory? {
20+
try {
21+
val constructor = PresentationFactory::class.java.constructors.firstOrNull() ?: return null
22+
// IC-2022.3: PresentationFactory(EditorImpl), > IC-2022.3: PresentationFactory(Editor)
23+
return constructor.newInstance(editor) as PresentationFactory?
24+
} catch (e: Exception) {
25+
return null
26+
}
27+
}
28+
}

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.intellij.openapi.fileEditor.FileEditor
1414
import com.intellij.openapi.project.Project
1515
import com.intellij.openapi.util.Key
1616
import com.intellij.ui.EditorNotificationPanel
17-
import com.intellij.util.containers.isNullOrEmpty
1817
import com.redhat.devtools.intellij.kubernetes.editor.Different
1918
import com.redhat.devtools.intellij.kubernetes.editor.EditorResource
2019
import com.redhat.devtools.intellij.kubernetes.editor.hideNotification
@@ -67,10 +66,10 @@ class PushNotification(private val editor: FileEditor, private val project: Proj
6766

6867
private fun createText(toCreate: Collection<EditorResource>?, toUpdate: Collection<EditorResource>?): String {
6968
return StringBuilder().apply {
70-
if (false == toCreate?.isNullOrEmpty()) {
69+
if (false == toCreate?.isEmpty()) {
7170
append("Push to create ${toKindAndNames(toCreate.map { editorResource -> editorResource.getResource() })}")
7271
}
73-
if (false == toUpdate?.isNullOrEmpty()) {
72+
if (false == toUpdate?.isEmpty()) {
7473
if (isNotEmpty()) {
7574
append(", ")
7675
} else {

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.intellij.openapi.fileEditor.FileEditor
1414
import com.intellij.openapi.project.Project
1515
import com.intellij.openapi.util.Key
1616
import com.intellij.ui.EditorNotificationPanel
17-
import com.intellij.util.containers.isNullOrEmpty
1817
import com.redhat.devtools.intellij.kubernetes.editor.EditorResource
1918
import com.redhat.devtools.intellij.kubernetes.editor.FILTER_PUSHED
2019
import com.redhat.devtools.intellij.kubernetes.editor.Pushed
@@ -62,16 +61,16 @@ class PushedNotification(private val editor: FileEditor, private val project: Pr
6261

6362
private fun createText(created: List<EditorResource>?, updated: List<EditorResource>?): String {
6463
return StringBuilder().apply {
65-
if (!created.isNullOrEmpty()) {
64+
if (false == created?.isEmpty()) {
6665
append("Created ${toKindAndNames(created?.map { editorResource -> editorResource.getResource() })} ")
6766
}
68-
if (!updated.isNullOrEmpty()) {
67+
if (false == updated?.isEmpty()) {
6968
if (isNotEmpty()) {
7069
append(", updated")
7170
} else {
7271
append("Updated")
7372
}
74-
append(" ${toKindAndNames(updated?.map { editorResource -> editorResource.getResource() })}")
73+
append(" ${toKindAndNames(updated.map { editorResource -> editorResource.getResource() })}")
7574
}
7675
append(" on cluster.")
7776
}

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/context/ActiveContext.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ abstract class ActiveContext<N : HasMetadata, C : KubernetesClient>(
7575
protected abstract val namespaceKind : ResourceKind<N>
7676

7777
private val extensionName: ExtensionPointName<IResourceOperatorFactory<HasMetadata, KubernetesClient, IResourceOperator<HasMetadata>>> =
78-
ExtensionPointName.create("com.redhat.devtools.intellij.kubernetes.resourceOperators")
78+
ExtensionPointName("com.redhat.devtools.intellij.kubernetes.resourceOperators")
7979

8080
protected open val nonNamespacedOperators: MutableMap<ResourceKind<out HasMetadata>, INonNamespacedResourceOperator<*, *>> by lazy {
8181
getAllResourceOperators(INonNamespacedResourceOperator::class.java)

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/TreeStructure.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ open class TreeStructure(
4545
private val project: Project,
4646
private val model: IResourceModel,
4747
private val extensionPoint: ExtensionPointName<ITreeStructureContributionFactory> =
48-
ExtensionPointName.create("com.redhat.devtools.intellij.kubernetes.structureContribution"))
48+
ExtensionPointName("com.redhat.devtools.intellij.kubernetes.structureContribution"))
4949
: AbstractTreeStructure(), MultiParentTreeStructure {
5050

5151
private val contributions by lazy {

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/TreeUpdater.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class TreeUpdater(
129129
}
130130

131131
private fun invalidateRoot() {
132-
treeModel.invalidate()
132+
treeModel.invalidateAsync()
133133
}
134134

135135
private fun getPotentialParentNodes(element: Any): Collection<TreeNode> {

src/test/kotlin/com/redhat/devtools/intellij/kubernetes/tree/TreeUpdaterTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class TreeUpdaterTest {
242242
// when
243243
updater.modified(resourceModel)
244244
// then
245-
verify(treeModel).invalidate()
245+
verify(treeModel).invalidateAsync()
246246
}
247247

248248
@Test

0 commit comments

Comments
 (0)