Skip to content

Commit

Permalink
fix: corrected incompatibilities (redhat-developer#749)
Browse files Browse the repository at this point in the history
* removed call to ExtensionPointName.create (redhat-developer#749)
* made instantiation of PresentationFactory compatible (redhat-developer#749)
* removed TriConsumer from commons to make build compatible (redhat-developer#749)
* removed deprecated UtilKt.isNull0rEmpty(Collection)(redhat-developer#749)
* removed deprecated EdtInvocationManager.isEventDispatchThread(redhat-developer#749)
* replaced deprecated StructureTreeModel.invalidate()(redhat-developer#749)

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Apr 17, 2024
1 parent 66de7f5 commit 118f625
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jetBrainsToken=invalid
jetBrainsChannel=stable
intellijPluginVersion=1.16.1
kotlinJvmPluginVersion=1.8.0
intellijCommonVersion=1.9.4
intellijCommonVersion=1.9.5-SNAPSHOT
telemetryPluginVersion=1.1.0.52
kotlin.stdlib.default.dependency = false
kotlinVersion=1.6.21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.ui.EdtInvocationManager
import com.intellij.util.ui.EDT
import com.redhat.devtools.intellij.common.editor.AllowNonProjectEditing
import com.redhat.devtools.intellij.common.utils.UIHelper
import com.redhat.devtools.intellij.kubernetes.model.Notification
import com.redhat.devtools.intellij.kubernetes.model.util.trimWithEllipsis
import io.fabric8.kubernetes.api.model.HasMetadata
import io.fabric8.kubernetes.client.utils.Serialization
import org.apache.commons.io.FileUtils
import org.jetbrains.yaml.YAMLFileType
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.Supplier
import org.apache.commons.io.FileUtils
import org.jetbrains.yaml.YAMLFileType

/**
* Helper that offers operations on the [VirtualFile] for a [ResourceEditor]
Expand Down Expand Up @@ -135,7 +135,7 @@ open class ResourceFile protected constructor(
* When invoking synchronous refresh from a thread other than the event dispatch thread,
* the current thread must NOT be in a read action, otherwise a deadlock may occur
*/
if (EdtInvocationManager.getInstance().isEventDispatchThread) {
if (EDT.isCurrentThreadEdt()) {
executeReadAction {
virtualFile.refresh(false, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
@file:Suppress("UnstableApiUsage")
package com.redhat.devtools.intellij.kubernetes.editor.inlay

import PresentationFactoryBuilder
import com.intellij.codeInsight.hints.InlayHintsSink
import com.intellij.codeInsight.hints.presentation.InlayPresentation
import com.intellij.codeInsight.hints.presentation.PresentationFactory
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.redhat.devtools.intellij.common.validation.KubernetesResourceInfo
import com.redhat.devtools.intellij.kubernetes.balloon.StringInputBalloon
import com.redhat.devtools.intellij.kubernetes.editor.inlay.Base64Presentations.InlayPresentationsFactory
import com.redhat.devtools.intellij.kubernetes.editor.inlay.Base64Presentations.create
import com.redhat.devtools.intellij.kubernetes.editor.util.getBinaryData
import com.redhat.devtools.intellij.kubernetes.editor.util.getData
import com.redhat.devtools.intellij.kubernetes.editor.util.isKubernetesResource
Expand Down Expand Up @@ -94,7 +95,7 @@ object Base64Presentations {
}

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

private fun create(bytes: ByteArray, editor: Editor): InlayPresentation? {
val factory = PresentationFactory(editor as EditorImpl)
val factory = PresentationFactoryBuilder.build(editor) ?: return null
val hex = toHexString(bytes) ?: return null
val trimmed = trimWithEllipsis(hex, INLAY_HINT_MAX_WIDTH) ?: return null
return factory.roundWithBackground(factory.smallText(trimmed))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
import com.intellij.codeInsight.hints.presentation.PresentationFactory
import com.intellij.openapi.editor.Editor

/**
* A factory that creates a [PresentationFactory]. This class bridges the difference in API between
* <= IC-2022.3 and above.
*/
object PresentationFactoryBuilder {
fun build(editor: Editor): PresentationFactory? {
try {
val constructor = PresentationFactory::class.java.constructors.firstOrNull() ?: return null
// IC-2022.3: PresentationFactory(EditorImpl), > IC-2022.3: PresentationFactory(Editor)
return constructor.newInstance(editor) as PresentationFactory?
} catch (e: Exception) {
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.ui.EditorNotificationPanel
import com.intellij.util.containers.isNullOrEmpty
import com.redhat.devtools.intellij.kubernetes.editor.Different
import com.redhat.devtools.intellij.kubernetes.editor.EditorResource
import com.redhat.devtools.intellij.kubernetes.editor.hideNotification
Expand Down Expand Up @@ -67,10 +66,10 @@ class PushNotification(private val editor: FileEditor, private val project: Proj

private fun createText(toCreate: Collection<EditorResource>?, toUpdate: Collection<EditorResource>?): String {
return StringBuilder().apply {
if (false == toCreate?.isNullOrEmpty()) {
if (false == toCreate?.isEmpty()) {
append("Push to create ${toKindAndNames(toCreate.map { editorResource -> editorResource.getResource() })}")
}
if (false == toUpdate?.isNullOrEmpty()) {
if (false == toUpdate?.isEmpty()) {
if (isNotEmpty()) {
append(", ")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.ui.EditorNotificationPanel
import com.intellij.util.containers.isNullOrEmpty
import com.redhat.devtools.intellij.kubernetes.editor.EditorResource
import com.redhat.devtools.intellij.kubernetes.editor.FILTER_PUSHED
import com.redhat.devtools.intellij.kubernetes.editor.Pushed
Expand Down Expand Up @@ -62,16 +61,16 @@ class PushedNotification(private val editor: FileEditor, private val project: Pr

private fun createText(created: List<EditorResource>?, updated: List<EditorResource>?): String {
return StringBuilder().apply {
if (!created.isNullOrEmpty()) {
if (false == created?.isEmpty()) {
append("Created ${toKindAndNames(created?.map { editorResource -> editorResource.getResource() })} ")
}
if (!updated.isNullOrEmpty()) {
if (false == updated?.isEmpty()) {
if (isNotEmpty()) {
append(", updated")
} else {
append("Updated")
}
append(" ${toKindAndNames(updated?.map { editorResource -> editorResource.getResource() })}")
append(" ${toKindAndNames(updated.map { editorResource -> editorResource.getResource() })}")
}
append(" on cluster.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class ActiveContext<N : HasMetadata, C : KubernetesClient>(
protected abstract val namespaceKind : ResourceKind<N>

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

protected open val nonNamespacedOperators: MutableMap<ResourceKind<out HasMetadata>, INonNamespacedResourceOperator<*, *>> by lazy {
getAllResourceOperators(INonNamespacedResourceOperator::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class TreeStructure(
private val project: Project,
private val model: IResourceModel,
private val extensionPoint: ExtensionPointName<ITreeStructureContributionFactory> =
ExtensionPointName.create("com.redhat.devtools.intellij.kubernetes.structureContribution"))
ExtensionPointName("com.redhat.devtools.intellij.kubernetes.structureContribution"))
: AbstractTreeStructure(), MultiParentTreeStructure {

private val contributions by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TreeUpdater(
}

private fun invalidateRoot() {
treeModel.invalidate()
treeModel.invalidateAsync()
}

private fun getPotentialParentNodes(element: Any): Collection<TreeNode> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class TreeUpdaterTest {
// when
updater.modified(resourceModel)
// then
verify(treeModel).invalidate()
verify(treeModel).invalidateAsync()
}

@Test
Expand Down

0 comments on commit 118f625

Please sign in to comment.