Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #131 from bridgecrewio/BCE-38714-Remove-jetbrains-…
Browse files Browse the repository at this point in the history
…deprecated-APIs

BCE-38714 - Remove JetBrains deprecated APIs for version approval
  • Loading branch information
ChananM authored Sep 24, 2024
2 parents ea65b22 + 225f40c commit 96a8e6f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ object CheckovScanAction : AnAction(), DumbAware {
val project = actionEvent.project
if (actionEvent.presentation.icon == AllIcons.Actions.Execute) {
isExecuteState = false
update(actionEvent)
project!!.service<AnalyticsService>().fullScanButtonWasPressed()
project.service<CheckovScanService>().scanProject(project)
} else {
Expand All @@ -37,7 +36,6 @@ object CheckovScanAction : AnAction(), DumbAware {
project?.service<CheckovScanService>()?.cancelFullScan(project)
}
updateIcon()
update(actionEvent)
}

override fun update(e: AnActionEvent) {
Expand Down
85 changes: 44 additions & 41 deletions src/main/kotlin/com/bridgecrew/ui/actions/FixAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.bridgecrew.services.scan.CheckovScanService
import com.bridgecrew.settings.CheckovGlobalState
import com.bridgecrew.utils.navigateToFile
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Document
Expand All @@ -28,35 +29,36 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu

init {
DataManager.getInstance().dataContextFromFocusAsync.then { dataContext ->
val project = dataContext.getData("project") as Project
val connection = project.messageBus.connect()
val inScanMsg = "Scan in progress. Please wait for completion before retrying."
buttonInstance.isEnabled = !CheckovGlobalState.scanInProgress
connection.subscribe(CheckovScanListener.SCAN_TOPIC, object : CheckovScanListener {
override fun fileScanningStarted() {
buttonInstance.isEnabled = false
buttonInstance.toolTipText = inScanMsg
CheckovGlobalState.scanInProgress = true
}

override fun projectScanningStarted() {
buttonInstance.isEnabled = false
buttonInstance.toolTipText = inScanMsg
CheckovGlobalState.scanInProgress = true
}

override fun scanningFinished(scanSourceType: CheckovScanService.ScanSourceType) {
buttonInstance.isEnabled = true
buttonInstance.toolTipText = ""
CheckovGlobalState.scanInProgress = false
}

override fun fullScanFailed() {
buttonInstance.isEnabled = true
buttonInstance.toolTipText = ""
CheckovGlobalState.scanInProgress = false
}
})
dataContext.getData(DataKey.create<Project>("project"))?.let {
val connection = it.messageBus.connect()
val inScanMsg = "Scan in progress. Please wait for completion before retrying."
buttonInstance.isEnabled = !CheckovGlobalState.scanInProgress
connection.subscribe(CheckovScanListener.SCAN_TOPIC, object : CheckovScanListener {
override fun fileScanningStarted() {
buttonInstance.isEnabled = false
buttonInstance.toolTipText = inScanMsg
CheckovGlobalState.scanInProgress = true
}

override fun projectScanningStarted() {
buttonInstance.isEnabled = false
buttonInstance.toolTipText = inScanMsg
CheckovGlobalState.scanInProgress = true
}

override fun scanningFinished(scanSourceType: CheckovScanService.ScanSourceType) {
buttonInstance.isEnabled = true
buttonInstance.toolTipText = ""
CheckovGlobalState.scanInProgress = false
}

override fun fullScanFailed() {
buttonInstance.isEnabled = true
buttonInstance.toolTipText = ""
CheckovGlobalState.scanInProgress = false
}
})
}
}
}

Expand Down Expand Up @@ -89,12 +91,12 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu
val endOffset = document.getLineEndOffset(endLine)

DataManager.getInstance().dataContextFromFocusAsync.then { dataContext ->
val project = dataContext.getData("project") as Project

WriteCommandAction.runWriteCommandAction(project) {
document.replaceString(startOffset, endOffset, result.fixDefinition!!)
FileDocumentManager.getInstance().saveDocument(document)
navigateToFile(project, virtualFile, result.codeDiffFirstLine)
dataContext.getData(DataKey.create<Project>("project"))?.let {
WriteCommandAction.runWriteCommandAction(it) {
document.replaceString(startOffset, endOffset, result.fixDefinition!!)
FileDocumentManager.getInstance().saveDocument(document)
navigateToFile(it, virtualFile, result.codeDiffFirstLine)
}
}
}

Expand Down Expand Up @@ -131,12 +133,13 @@ class FixAction(private val buttonInstance: JButton, val result: BaseCheckovResu

private fun showSCAFixModal(fixCommand: FixCommand, isSuccess: Boolean) {
DataManager.getInstance().dataContextFromFocusAsync.then { dataContext ->
val project = dataContext.getData("project") as Project
Messages.showInfoMessage(
project,
buildModalMessage(fixCommand, isSuccess),
"SCA Fix - Additional Action Required"
)
dataContext.getData(DataKey.create<Project>("project"))?.let {
Messages.showInfoMessage(
it,
buildModalMessage(fixCommand, isSuccess),
"SCA Fix - Additional Action Required"
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bridgecrew.ui.actions
import com.bridgecrew.ui.CheckovToolWindowManagerPanel
import com.bridgecrew.utils.PANELTYPE
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import java.awt.event.ActionEvent
Expand All @@ -12,9 +13,9 @@ class FocusOnFileInTree(val filePath: String) : ActionListener {

override fun actionPerformed(e: ActionEvent?) {
DataManager.getInstance().dataContextFromFocusAsync.then { dataContext ->
val project = dataContext.getData("project") as Project
project.service<CheckovToolWindowManagerPanel>()
.loadMainPanel(PANELTYPE.CHECKOV_FILE_SCAN_FINISHED, filePath)
dataContext.getData(DataKey.create<Project>("project"))
?.service<CheckovToolWindowManagerPanel>()
?.loadMainPanel(PANELTYPE.CHECKOV_FILE_SCAN_FINISHED, filePath)
}
}
}

0 comments on commit 96a8e6f

Please sign in to comment.