Skip to content

Commit

Permalink
SLI-1816 Interrupting the branch matching computation should not caus…
Browse files Browse the repository at this point in the history
…e an error
  • Loading branch information
eray-felek-sonarsource committed Jan 28, 2025
1 parent 5e24821 commit 005948c
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -624,31 +624,37 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate {
allBranchesNames: Set<String>,
cancelChecker: SonarLintCancelChecker,
): String? {
val repositoriesEPs = VcsRepoProvider.EP_NAME.extensionList
val repositories = BackendService.findModule(configurationScopeId)?.let { module ->
matchSonarModule(module, repositoriesEPs)
} ?: run {
BackendService.findProject(configurationScopeId)?.let { project ->
matchSonarProject(project, repositoriesEPs)
}
} ?: return null
val repo = repositories.first()

val project = BackendService.findModule(configurationScopeId)?.project
?: BackendService.findProject(configurationScopeId) ?: return null
val resultFuture = CompletableFuture<String>()
ProgressManager.getInstance().run(object : Task.Backgroundable(
project,
"Matching project branch…",
true,
PerformInBackgroundOption.ALWAYS_BACKGROUND
) {
override fun run(indicator: ProgressIndicator) {
val result = repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName
resultFuture.complete(result)
}
})
return computeOnPooledThread(project, "Waiting for branch matching result") { resultFuture.get() }

try {
val repositoriesEPs = VcsRepoProvider.EP_NAME.extensionList
val repositories = BackendService.findModule(configurationScopeId)?.let { module ->
matchSonarModule(module, repositoriesEPs)
} ?: run {
BackendService.findProject(configurationScopeId)?.let { project ->
matchSonarProject(project, repositoriesEPs)
}
} ?: return null
val repo = repositories.first()

val resultFuture = CompletableFuture<String>()
ProgressManager.getInstance().run(object : Task.Backgroundable(
project,
"Matching project branch…",
true,
PerformInBackgroundOption.ALWAYS_BACKGROUND
) {
override fun run(indicator: ProgressIndicator) {
val result = repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName
resultFuture.complete(result)
}
})
return computeOnPooledThread(project, "Waiting for branch matching result") { resultFuture.get() }
} catch (e: InterruptedException) {
SonarLintConsole.get(project).error("Interrupted while trying to match the Sonar branch with exception: " + e.message)
return null
}
}

override fun matchProjectBranch(
Expand Down

0 comments on commit 005948c

Please sign in to comment.