Skip to content

Commit

Permalink
Cover additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eray-felek-sonarsource committed Sep 19, 2024
1 parent 9215cee commit 5038240
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ import org.sonarlint.intellij.analysis.AnalysisStatus
import org.sonarlint.intellij.common.util.SonarLintUtils.getService
import org.sonarlint.intellij.core.BackendService
import org.sonarlint.intellij.core.ProjectBindingManager
import org.sonarlint.intellij.util.runOnPooledThread

class RefreshTaintVulnerabilitiesAction(text: String = "Refresh") : AbstractSonarAction(text, "Refresh taint vulnerabilities for open files", AllIcons.Actions.Refresh) {
override fun isEnabled(e: AnActionEvent, project: Project, status: AnalysisStatus) = getService(project, ProjectBindingManager::class.java).isBindingValid

override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
getService(BackendService::class.java).refreshTaintVulnerabilities(project)

runOnPooledThread {
getService(BackendService::class.java).refreshTaintVulnerabilities(project)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,32 @@ public void save(SonarLintGlobalSettings settings) {
public void load(SonarLintGlobalSettings settings) {
panel.startLoading();
selectedRuleKey = null;
getService(BackendService.class).getListAllStandaloneRulesDefinitions()
.thenAcceptAsync(response -> {
allRulesStateByKey.clear();

var ruleNodes = response.getRulesByKey().values().stream()
.map(ruleDefinitionDto -> new RulesTreeNode.Rule(ruleDefinitionDto,
loadRuleActivation(settings, ruleDefinitionDto),
loadNonDefaultRuleParams(settings, ruleDefinitionDto)))
.collect(Collectors.toMap(RulesTreeNode.Rule::getKey, r -> r));

allRulesStateByKey.putAll(ruleNodes);

ModalityUiUtil.invokeLaterIfNeeded(
ModalityState.stateForComponent(panel), () -> {
applyRuleSelection();
updateModel();
panel.stopLoading();
});
})
.exceptionally(error -> {
GlobalLogOutput.get().log("Could not load rules: " + error.getMessage(), ClientLogOutput.Level.ERROR);
return null;
});
runOnPooledThread(project, () ->
getService(BackendService.class).getListAllStandaloneRulesDefinitions()
.thenAcceptAsync(response -> {
allRulesStateByKey.clear();

var ruleNodes = response.getRulesByKey().values().stream()
.map(ruleDefinitionDto -> new RulesTreeNode.Rule(ruleDefinitionDto,
loadRuleActivation(settings, ruleDefinitionDto),
loadNonDefaultRuleParams(settings, ruleDefinitionDto)))
.collect(Collectors.toMap(RulesTreeNode.Rule::getKey, r -> r));

allRulesStateByKey.putAll(ruleNodes);

ModalityUiUtil.invokeLaterIfNeeded(
ModalityState.stateForComponent(panel), () -> {
applyRuleSelection();
updateModel();
panel.stopLoading();
});
})
.exceptionally(error -> {
GlobalLogOutput.get().log("Could not load rules: " + error.getMessage(), ClientLogOutput.Level.ERROR);
return null;
})
);
}

private void restoreDefaults() {
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/org/sonarlint/intellij/core/BackendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class BackendService : Disposable {
}

private fun <T> requestFromBackend(action: (SonarLintRpcServer) -> CompletableFuture<T>): CompletableFuture<T> {
if (ApplicationManager.getApplication().isDispatchThread) {
println(action.javaClass.name)
}
return ensureBackendInitialized().thenComposeAsync(action)
}

Expand Down Expand Up @@ -507,7 +510,9 @@ class BackendService : Disposable {
)
)
}
refreshTaintVulnerabilities(project)
runOnPooledThread {
refreshTaintVulnerabilities(project)
}
}

internal fun projectClosed(project: Project) {
Expand Down Expand Up @@ -543,7 +548,9 @@ class BackendService : Disposable {
)
}
}
refreshTaintVulnerabilities(project)
runOnPooledThread {
refreshTaintVulnerabilities(project)
}
}

fun projectUnbound(project: Project) {
Expand All @@ -554,7 +561,9 @@ class BackendService : Disposable {
)
)
}
refreshTaintVulnerabilities(project)
runOnPooledThread {
refreshTaintVulnerabilities(project)
}
}

fun modulesAdded(project: Project, modules: List<Module>) {
Expand Down Expand Up @@ -800,7 +809,9 @@ class BackendService : Disposable {
)
)
)
refreshTaintVulnerabilities(project)
runOnPooledThread {
refreshTaintVulnerabilities(project)
}

rpcServer.configurationService.didAddConfigurationScopes(
DidAddConfigurationScopesParams(
Expand Down

0 comments on commit 5038240

Please sign in to comment.