diff --git a/src/main/kotlin/io/snyk/plugin/services/SnykCliAuthenticationService.kt b/src/main/kotlin/io/snyk/plugin/services/SnykCliAuthenticationService.kt index 737931bb8..c4e5c8f12 100644 --- a/src/main/kotlin/io/snyk/plugin/services/SnykCliAuthenticationService.kt +++ b/src/main/kotlin/io/snyk/plugin/services/SnykCliAuthenticationService.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.application.ModalityState import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.ide.CopyPasteManager +import com.intellij.openapi.progress.EmptyProgressIndicator import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.progress.Task @@ -54,7 +55,13 @@ class SnykCliAuthenticationService(val project: Project) { private fun downloadCliIfNeeded() { val downloadCliTask: () -> Unit = { if (!getCliFile().exists()) { - getSnykTaskQueueService(project)?.downloadLatestRelease() + val progress = + if (!ProgressManager.getInstance().hasProgressIndicator()) { + EmptyProgressIndicator() + } else { + ProgressManager.getInstance().progressIndicator + } + getSnykTaskQueueService(project)?.downloadLatestRelease(progress) } else { logger.debug("Skip CLI download, since it was already downloaded") } @@ -152,7 +159,11 @@ class AuthDialog : DialogWrapper(true) { override fun createCenterPanel(): JComponent { val centerPanel = JPanel(BorderLayout(JBUIScale.scale(5), JBUIScale.scale(5))) - val scrollPane = JBScrollPane(viewer, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) + val scrollPane = JBScrollPane( + viewer, + ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER + ) centerPanel.add(scrollPane, BorderLayout.CENTER) val progressBar = JProgressBar().apply { diff --git a/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt b/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt index f318d6ca6..bdd63e982 100644 --- a/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt +++ b/src/main/kotlin/io/snyk/plugin/services/SnykTaskQueueService.kt @@ -114,7 +114,7 @@ class SnykTaskQueueService(val project: Project) { fun waitUntilCliDownloadedIfNeeded(indicator: ProgressIndicator) { indicator.text = "Snyk waits for CLI to be downloaded..." - downloadLatestRelease() + downloadLatestRelease(indicator) do { indicator.checkCanceled() Thread.sleep(WAIT_FOR_DOWNLOAD_MILLIS) @@ -278,7 +278,7 @@ class SnykTaskQueueService(val project: Project) { }) } - fun downloadLatestRelease() { + fun downloadLatestRelease(indicator: ProgressIndicator) { // abort even before submitting a task if (!pluginSettings().manageBinariesAutomatically) { if (!isCliInstalled()) { @@ -292,7 +292,7 @@ class SnykTaskQueueService(val project: Project) { val cliDownloader = getSnykCliDownloaderService() taskQueue.run(object : Task.Backgroundable(project, "Check Snyk CLI presence", true) { - override fun run(indicator: ProgressIndicator) { + override fun run(ignored: ProgressIndicator) { cliDownloadPublisher.checkCliExistsStarted() if (project.isDisposed) return diff --git a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt index 28030b7a2..03cdacd6b 100644 --- a/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt +++ b/src/main/kotlin/io/snyk/plugin/services/download/CliDownloader.kt @@ -47,6 +47,7 @@ class CliDownloader { val message = "Cannot create file in the configured CLI path directory ${cliFile.parent}. " + "Please either change the CLI path to a writeable directory or give the " + "current directory write permissions." + indicator.cancel() throw IOException(message, e) } try { diff --git a/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt b/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt index 3f32c4f4a..76d79888f 100644 --- a/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt +++ b/src/test/kotlin/io/snyk/plugin/services/SnykTaskQueueServiceTest.kt @@ -104,7 +104,7 @@ class SnykTaskQueueServiceTest : LightPlatformTestCase() { assertTrue(snykTaskQueueService.getTaskQueue().isEmpty) - snykTaskQueueService.downloadLatestRelease() + snykTaskQueueService.downloadLatestRelease(indicator) PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() assertTrue(snykTaskQueueService.getTaskQueue().isEmpty) @@ -165,7 +165,7 @@ class SnykTaskQueueServiceTest : LightPlatformTestCase() { setProject(null) // to avoid double disposing effort in tearDown // the Task should roll out gracefully without any Exception or Error - snykTaskQueueService.downloadLatestRelease() + snykTaskQueueService.downloadLatestRelease(indicator) } fun testSastEnablementCheckInScan() {