Skip to content

Commit

Permalink
chore: cleanup old OSS functionality [IDE-609] (#586)
Browse files Browse the repository at this point in the history
* chore: cleanup after release

* fix: compile errors

* fix: more cleanup

* fix: more compile error fixing

* fix: SnykControllerImplTest

* fix: remove old annotators from plugin.xml
  • Loading branch information
bastiandoetsch authored Aug 30, 2024
1 parent 8139591 commit 58266b6
Show file tree
Hide file tree
Showing 43 changed files with 164 additions and 1,709 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/io/snyk/plugin/SnykPostStartupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SnykPostStartupActivity : ProjectActivity {
settings.lastTimeFeedbackRequestShown = Date.from(Instant.now())
}

if (isContainerEnabled()) {
if (settings.containerScanEnabled) {
getKubernetesImageCache(project)?.cacheKubernetesFileFromProject()
}

Expand Down
12 changes: 0 additions & 12 deletions src/main/kotlin/io/snyk/plugin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ import snyk.container.ContainerService
import snyk.container.KubernetesImageCache
import snyk.errorHandler.SentryErrorReporter
import snyk.iac.IacScanService
import snyk.oss.OssService
import snyk.oss.OssTextRangeFinder
import java.io.File
import java.io.FileNotFoundException
import java.net.URI
Expand All @@ -72,8 +70,6 @@ import javax.swing.JComponent

private val logger = Logger.getInstance("#io.snyk.plugin.UtilsKt")

fun getOssService(project: Project): OssService? = project.serviceIfNotDisposed()

fun getIacService(project: Project): IacScanService? = project.serviceIfNotDisposed()

fun getKubernetesImageCache(project: Project): KubernetesImageCache? = project.serviceIfNotDisposed()
Expand Down Expand Up @@ -110,8 +106,6 @@ fun isCliInstalled(): Boolean = ApplicationManager.getApplication().isUnitTestMo

fun pluginSettings(): SnykApplicationSettingsStateService = getApplicationService()

fun getOssTextRangeFinderService(): OssTextRangeFinder = getApplicationService()

fun getPluginPath() = PathManager.getPluginsPath() + "/snyk-intellij-plugin"

fun isProjectSettingsAvailable(project: Project?) = nonNull(project) && !project!!.isDefault
Expand Down Expand Up @@ -224,14 +218,8 @@ fun controlExternalProcessWithProgressIndicator(
checkCancelled.invoke()
}

fun isIacEnabled(): Boolean = true

fun isContainerEnabled(): Boolean = true

fun isFileListenerEnabled(): Boolean = pluginSettings().fileListenerEnabled

fun isSnykOSSLSEnabled(): Boolean = true // TODO: cleanup usage

fun isSnykIaCLSEnabled(): Boolean = false


Expand Down
17 changes: 0 additions & 17 deletions src/main/kotlin/io/snyk/plugin/analytics/AnalyticsScanListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import snyk.common.lsp.LanguageServerWrapper
import snyk.common.lsp.commands.ScanDoneEvent
import snyk.container.ContainerResult
import snyk.iac.IacResult
import snyk.oss.OssResult

@Service(Service.Level.PROJECT)
class AnalyticsScanListener(val project: Project) {
Expand Down Expand Up @@ -45,18 +44,6 @@ class AnalyticsScanListener(val project: Project) {
start = System.currentTimeMillis()
}

override fun scanningOssFinished(ossResult: OssResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Open Source",
ossResult.criticalSeveritiesCount(),
ossResult.highSeveritiesCount(),
ossResult.mediumSeveritiesCount(),
ossResult.lowSeveritiesCount()
)
LanguageServerWrapper.getInstance().sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningIacFinished(iacResult: IacResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
Expand All @@ -81,10 +68,6 @@ class AnalyticsScanListener(val project: Project) {
LanguageServerWrapper.getInstance().sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningOssError(snykError: SnykError) {
// do nothing
}

override fun scanningIacError(snykError: SnykError) {
// do nothing
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/io/snyk/plugin/events/SnykScanListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.intellij.util.messages.Topic
import snyk.common.SnykError
import snyk.container.ContainerResult
import snyk.iac.IacResult
import snyk.oss.OssResult

interface SnykScanListener {
companion object {
Expand All @@ -14,12 +13,8 @@ interface SnykScanListener {

fun scanningStarted()

fun scanningOssFinished(ossResult: OssResult)

fun scanningIacFinished(iacResult: IacResult)

fun scanningOssError(snykError: SnykError)

fun scanningIacError(snykError: SnykError)

fun scanningContainerFinished(containerResult: ContainerResult)
Expand Down
87 changes: 23 additions & 64 deletions src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ import io.snyk.plugin.events.SnykSettingsListener
import io.snyk.plugin.events.SnykTaskQueueListener
import io.snyk.plugin.getContainerService
import io.snyk.plugin.getIacService
import io.snyk.plugin.getOssService
import io.snyk.plugin.getSnykCachedResults
import io.snyk.plugin.getSnykCliDownloaderService
import io.snyk.plugin.getSnykToolWindowPanel
import io.snyk.plugin.getSyncPublisher
import io.snyk.plugin.isCliDownloading
import io.snyk.plugin.isCliInstalled
import io.snyk.plugin.isContainerEnabled
import io.snyk.plugin.isIacEnabled
import io.snyk.plugin.isOssRunning
import io.snyk.plugin.isSnykCodeRunning
import io.snyk.plugin.isSnykIaCLSEnabled
import io.snyk.plugin.isSnykOSSLSEnabled
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.refreshAnnotationsForOpenFiles
import io.snyk.plugin.ui.SnykBalloonNotificationHelper
Expand Down Expand Up @@ -69,29 +65,29 @@ class SnykTaskQueueService(val project: Project) {
fun getTaskQueue() = taskQueue

fun connectProjectToLanguageServer(project: Project) {
// subscribe to the settings changed topic
// subscribe to the settings changed topic
val languageServerWrapper = LanguageServerWrapper.getInstance()
getSnykToolWindowPanel(project)?.let {
project.messageBus.connect(it)
.subscribe(
SnykSettingsListener.SNYK_SETTINGS_TOPIC,
object : SnykSettingsListener {
override fun settingsChanged() {
languageServerWrapper.updateConfiguration()
}
project.messageBus.connect(it)
.subscribe(
SnykSettingsListener.SNYK_SETTINGS_TOPIC,
object : SnykSettingsListener {
override fun settingsChanged() {
languageServerWrapper.updateConfiguration()
}
)
}
)
}
// Try to connect project for up to 30s
for (tries in 1..300) {
if (!languageServerWrapper.isInitialized) {
Thread.sleep(100)
continue
}
// Try to connect project for up to 30s
for (tries in 1..300) {
if (!languageServerWrapper.isInitialized) {
Thread.sleep(100)
continue
}

languageServerWrapper.addContentRoots(project)
break
}
languageServerWrapper.addContentRoots(project)
break
}
}

fun scan(isStartup: Boolean) {
Expand All @@ -106,22 +102,16 @@ class SnykTaskQueueService(val project: Project) {
waitUntilCliDownloadedIfNeeded()
indicator.checkCanceled()

if (settings.snykCodeSecurityIssuesScanEnable || settings.snykCodeQualityIssuesScanEnable || isSnykOSSLSEnabled()) {
if (!isStartup) {
LanguageServerWrapper.getInstance().sendScanCommand(project)
}
}
if (settings.ossScanEnable) {
if (!isSnykOSSLSEnabled()) {
scheduleOssScan()
}
if (!isStartup) {
LanguageServerWrapper.getInstance().sendScanCommand(project)
}
if (isIacEnabled() && settings.iacScanEnabled) {

if (settings.iacScanEnabled) {
if (!isSnykIaCLSEnabled()) {
scheduleIacScan()
}
}
if (isContainerEnabled() && settings.containerScanEnabled) {
if (settings.containerScanEnabled) {
scheduleContainerScan()
}
}
Expand Down Expand Up @@ -173,37 +163,6 @@ class SnykTaskQueueService(val project: Project) {
})
}

private fun scheduleOssScan() {
taskQueue.run(object : Task.Backgroundable(project, "Snyk Open Source is scanning", true) {
override fun run(indicator: ProgressIndicator) {
if (!isCliInstalled()) return
val snykCachedResults = getSnykCachedResults(project) ?: return
if (snykCachedResults.currentOssResults != null) return

ossScanProgressIndicator = indicator
scanPublisher?.scanningStarted()

val ossResult = try {
getOssService(project)?.scan()
} finally {
ossScanProgressIndicator = null
}
if (ossResult == null || project.isDisposed) return

if (indicator.isCanceled) {
taskQueuePublisher?.stopped(wasOssRunning = true)
} else {
if (ossResult.isSuccessful()) {
scanPublisher?.scanningOssFinished(ossResult)
} else {
ossResult.getFirstError()?.let { scanPublisher?.scanningOssError(it) }
}
}
invokeLater { refreshAnnotationsForOpenFiles(project) }
}
})
}

private fun scheduleIacScan() {
taskQueueIac.run(object : Task.Backgroundable(project, "Snyk Infrastructure as Code is scanning", true) {
override fun run(indicator: ProgressIndicator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.ToggleAction
import io.snyk.plugin.events.SnykResultsFilteringListener
import io.snyk.plugin.getSyncPublisher
import io.snyk.plugin.isContainerEnabled
import io.snyk.plugin.isIacEnabled
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.showSettings
import io.snyk.plugin.ui.SnykBalloonNotificationHelper
Expand Down Expand Up @@ -36,8 +34,8 @@ class SnykTreeScanTypeFilterActionGroup : ActionGroup() {
createOssScanAction(),
createSecurityIssuesScanAction(),
createQualityIssuesScanAction(),
if (isIacEnabled()) createIacScanAction() else null,
if (isContainerEnabled()) createContainerScanAction() else null
createIacScanAction(),
createContainerScanAction()
).toTypedArray()

private fun createScanFilteringAction(
Expand Down
28 changes: 23 additions & 5 deletions src/main/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.SimpleToolWindowPanel
import com.intellij.ui.PopupHandler
import io.snyk.plugin.SnykFile
import io.snyk.plugin.events.SnykScanListener
import io.snyk.plugin.events.SnykScanListenerLS
import io.snyk.plugin.events.SnykTaskQueueListener
import io.snyk.plugin.getSnykToolWindowPanel
import io.snyk.plugin.ui.expandTreeNodeRecursively
import snyk.common.SnykError
import snyk.common.lsp.ScanIssue
import snyk.common.lsp.SnykScanParams
import snyk.container.ContainerResult
import snyk.iac.IacResult
import snyk.oss.OssResult
import javax.swing.JTree
import javax.swing.tree.DefaultMutableTreeNode

Expand Down Expand Up @@ -69,19 +72,34 @@ class SnykToolWindow(private val project: Project) : SimpleToolWindowPanel(false

override fun scanningStarted() = updateActionsPresentation()

override fun scanningOssFinished(ossResult: OssResult) = updateActionsPresentation()

override fun scanningIacFinished(iacResult: IacResult) = updateActionsPresentation()

override fun scanningOssError(snykError: SnykError) = updateActionsPresentation()

override fun scanningIacError(snykError: SnykError) = updateActionsPresentation()

override fun scanningContainerFinished(containerResult: ContainerResult) = updateActionsPresentation()

override fun scanningContainerError(snykError: SnykError) = updateActionsPresentation()
})

project.messageBus.connect(this)
.subscribe(SnykScanListenerLS.SNYK_SCAN_TOPIC, object : SnykScanListenerLS {
override fun scanningSnykCodeFinished() {
updateActionsPresentation()
}

override fun scanningOssFinished() {
updateActionsPresentation()
}

override fun scanningError(snykScan: SnykScanParams) {
updateActionsPresentation()
}

override fun onPublishDiagnostics(product: String, snykFile: SnykFile, issueList: List<ScanIssue>) =
Unit
})


project.messageBus.connect(this)
.subscribe(SnykTaskQueueListener.TASK_QUEUE_TOPIC, object : SnykTaskQueueListener {
override fun stopped(
Expand Down
Loading

0 comments on commit 58266b6

Please sign in to comment.