Skip to content

Commit

Permalink
fix: trigger scan on startup for non-code
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed Apr 16, 2024
1 parent b532c4c commit ae662fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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 @@ -116,7 +116,7 @@ class SnykPostStartupActivity : ProjectActivity {
}

if (settings.scanOnSave && isSnykCodeLSEnabled()) {
getSnykTaskQueueService(project)?.scan()
getSnykTaskQueueService(project)?.scanOnSave()
}

ExtensionPointsUtil.controllerManager.extensionList.forEach {
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ class SnykTaskQueueService(val project: Project) {
})
}

fun scanOnSave() {
taskQueue.run(object : Task.Backgroundable(project, "Snyk: initializing...", true) {
override fun run(indicator: ProgressIndicator) {
if (!confirmScanningAndSetWorkspaceTrustedStateIfNeeded(project)) return

ApplicationManager.getApplication().invokeAndWait {
FileDocumentManager.getInstance().saveAllDocuments()
}
indicator.checkCanceled()
waitUntilCliDownloadedIfNeeded()
indicator.checkCanceled()

// We don't want a Snyk Code scan to be triggered because it gets triggered via the LS
if (settings.ossScanEnable) {
scheduleOssScan()
}
if (isIacEnabled() && settings.iacScanEnabled) {
scheduleIacScan()
}
if (isContainerEnabled() && settings.containerScanEnabled) {
scheduleContainerScan()
}
}
})
}

fun waitUntilCliDownloadedIfNeeded() {
downloadLatestRelease()
do {
Expand Down

0 comments on commit ae662fe

Please sign in to comment.