From 2916b889c04c6d916d76863551c125d4a22c5aab Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Fri, 22 Sep 2023 14:00:10 +0200 Subject: [PATCH] fix: SnykToolWindowPanelIntegTest --- .../ui/toolwindow/SnykTreeCellRenderer.kt | 25 +++++++++++++------ src/main/kotlin/snyk/iac/IacIssuesForFile.kt | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykTreeCellRenderer.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykTreeCellRenderer.kt index 76d94bc2e..4abc07b77 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykTreeCellRenderer.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykTreeCellRenderer.kt @@ -19,7 +19,11 @@ import io.snyk.plugin.ui.getDisabledIcon import io.snyk.plugin.ui.snykCodeAvailabilityPostfix import io.snyk.plugin.ui.toolwindow.nodes.leaf.SuggestionTreeNode import io.snyk.plugin.ui.toolwindow.nodes.leaf.VulnerabilityTreeNode -import io.snyk.plugin.ui.toolwindow.nodes.root.* +import io.snyk.plugin.ui.toolwindow.nodes.root.RootContainerIssuesTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootIacIssuesTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootOssTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootQualityIssuesTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootSecurityIssuesTreeNode import io.snyk.plugin.ui.toolwindow.nodes.secondlevel.ErrorTreeNode import io.snyk.plugin.ui.toolwindow.nodes.secondlevel.FileTreeNode import io.snyk.plugin.ui.toolwindow.nodes.secondlevel.SnykCodeFileTreeNode @@ -66,9 +70,13 @@ class SnykTreeCellRenderer : ColoredTreeCellRenderer() { is FileTreeNode -> { val fileVulns = value.userObject as OssVulnerabilitiesForFile nodeIcon = PackageManagerIconProvider.getIcon(fileVulns.packageManager.lowercase(Locale.getDefault())) - toolTipText = GotoFileCellRenderer.getRelativePath( - fileVulns.virtualFile, value.project - ) + fileVulns.sanitizedTargetFile + ProductType.OSS.getCountText(value.childCount) + val relativePath = fileVulns.virtualFile?.let { + GotoFileCellRenderer.getRelativePath( + fileVulns.virtualFile, value.project + ) + } ?: "" + toolTipText = + relativePath + fileVulns.sanitizedTargetFile + ProductType.OSS.getCountText(value.childCount) text = toolTipText.letIf(toolTipText.length > MAX_FILE_TREE_NODE_LENGTH) { "..." + it.substring( @@ -126,9 +134,12 @@ class SnykTreeCellRenderer : ColoredTreeCellRenderer() { nodeIcon = PackageManagerIconProvider.getIcon( iacVulnerabilitiesForFile.packageManager.lowercase(Locale.getDefault()) ) - toolTipText = GotoFileCellRenderer.getRelativePath( - iacVulnerabilitiesForFile.virtualFile, value.project - ) + ProductType.IAC.getCountText(value.childCount) + val relativePath = iacVulnerabilitiesForFile.virtualFile?.let { + GotoFileCellRenderer.getRelativePath( + iacVulnerabilitiesForFile.virtualFile, value.project + ) + } ?: iacVulnerabilitiesForFile.targetFilePath + toolTipText = relativePath + ProductType.IAC.getCountText(value.childCount) text = toolTipText.letIf(toolTipText.length > MAX_FILE_TREE_NODE_LENGTH) { "..." + it.substring( diff --git a/src/main/kotlin/snyk/iac/IacIssuesForFile.kt b/src/main/kotlin/snyk/iac/IacIssuesForFile.kt index 4d13766df..a0cb7b370 100644 --- a/src/main/kotlin/snyk/iac/IacIssuesForFile.kt +++ b/src/main/kotlin/snyk/iac/IacIssuesForFile.kt @@ -13,7 +13,7 @@ data class IacIssuesForFile( val ignored: Boolean get() = infrastructureAsCodeIssues.all { it.ignored } val uniqueCount: Int get() = infrastructureAsCodeIssues.groupBy { it.id }.size - val virtualFile: VirtualFile = LocalFileSystem.getInstance().findFileByPath(this.targetFilePath)!! + val virtualFile: VirtualFile? = LocalFileSystem.getInstance().findFileByPath(this.targetFilePath) } /* Real json Example: src/integTest/resources/iac-test-results/infrastructure-as-code-goof.json */