Skip to content

Commit

Permalink
fix: project closing problem because of not canceling the wait for do…
Browse files Browse the repository at this point in the history
…wnload
  • Loading branch information
bastiandoetsch committed Feb 8, 2024
1 parent 2edd277 commit 33ebe82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()) {
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SnykTaskQueueServiceTest : LightPlatformTestCase() {

assertTrue(snykTaskQueueService.getTaskQueue().isEmpty)

snykTaskQueueService.downloadLatestRelease()
snykTaskQueueService.downloadLatestRelease(indicator)
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()

assertTrue(snykTaskQueueService.getTaskQueue().isEmpty)
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 33ebe82

Please sign in to comment.