From 3092f8d49abd9c2f4c4584bf43647ca9dc886f75 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 16 Dec 2020 13:06:37 +0100 Subject: [PATCH] Do not enable notifications if disabled --- .../engine/connected/ConnectedEngineFacade.java | 4 ++++ .../core/internal/jobs/ProjectStorageUpdateJob.java | 12 ++++++------ .../eclipse/ui/internal/SonarLintUiPlugin.java | 10 +++++++--- .../binding/wizard/project/ProjectBindingWizard.java | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/engine/connected/ConnectedEngineFacade.java b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/engine/connected/ConnectedEngineFacade.java index fa42b7bb6..de79fa899 100644 --- a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/engine/connected/ConnectedEngineFacade.java +++ b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/engine/connected/ConnectedEngineFacade.java @@ -633,4 +633,8 @@ public List downloadServerIssues(ProjectBinding projectBinding, Str public List getServerIssues(ProjectBinding projectBinding, String filePath) { return withEngine(engine -> engine.getServerIssues(projectBinding, filePath)).orElse(emptyList()); } + + public ProjectBinding calculatePathPrefixes(String projectKey, List ideFilePaths) { + return withEngine(engine -> engine.calculatePathPrefixes(projectKey, ideFilePaths)).orElse(new ProjectBinding(projectKey, "", "")); + } } diff --git a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/jobs/ProjectStorageUpdateJob.java b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/jobs/ProjectStorageUpdateJob.java index cc9f9cdbf..a13e7d543 100644 --- a/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/jobs/ProjectStorageUpdateJob.java +++ b/org.sonarlint.eclipse.core/src/org/sonarlint/eclipse/core/internal/jobs/ProjectStorageUpdateJob.java @@ -29,23 +29,23 @@ public class ProjectStorageUpdateJob extends Job { - private final String serverId; + private final String connectionId; private final String projectKey; - public ProjectStorageUpdateJob(String serverId, String projectKey) { - super("Update SonarLint binding data for project '" + projectKey + "' on '" + serverId + "'"); - this.serverId = serverId; + public ProjectStorageUpdateJob(String connectionId, String projectKey) { + super("Update SonarLint binding data for project '" + projectKey + "' on '" + connectionId + "'"); + this.connectionId = connectionId; this.projectKey = projectKey; } @Override protected IStatus run(IProgressMonitor monitor) { try { - Optional server = SonarLintCorePlugin.getServersManager().findById(serverId); + Optional server = SonarLintCorePlugin.getServersManager().findById(connectionId); server.ifPresent(s -> s.updateProjectStorage(projectKey, monitor)); return Status.OK_STATUS; } catch (Exception e) { - return new Status(IStatus.ERROR, SonarLintCorePlugin.PLUGIN_ID, "Unable to update SonarLint binding data for project '" + projectKey + "' on '" + serverId + "'", e); + return new Status(IStatus.ERROR, SonarLintCorePlugin.PLUGIN_ID, "Unable to update SonarLint binding data for project '" + projectKey + "' on '" + connectionId + "'", e); } } } diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/SonarLintUiPlugin.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/SonarLintUiPlugin.java index 5a93341e3..11e42c93e 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/SonarLintUiPlugin.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/SonarLintUiPlugin.java @@ -297,9 +297,13 @@ public static void startupAsync() { public static void subscribeToNotifications(ISonarLintProject project) { SonarLintCorePlugin.getServersManager() .resolveBinding(project) - .ifPresent(binding -> SonarLintCorePlugin.getInstance() - .notificationsManager() - .subscribe(project, getDefault().listenerFactory().create(binding.getEngineFacade()))); + .ifPresent(binding -> { + if (!binding.getEngineFacade().areNotificationsDisabled()) { + SonarLintCorePlugin.getInstance() + .notificationsManager() + .subscribe(project, getDefault().listenerFactory().create(binding.getEngineFacade())); + } + }); } public static void unsubscribeToNotifications(ISonarLintProject project) { diff --git a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/wizard/project/ProjectBindingWizard.java b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/wizard/project/ProjectBindingWizard.java index 42a4bc99f..3a6885ca9 100644 --- a/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/wizard/project/ProjectBindingWizard.java +++ b/org.sonarlint.eclipse.ui/src/org/sonarlint/eclipse/ui/internal/binding/wizard/project/ProjectBindingWizard.java @@ -191,6 +191,7 @@ public boolean performFinish() { String oldServerId = projectConfig.getProjectBinding().map(EclipseProjectBinding::connectionId).orElse(null); String oldProjectKey = projectConfig.getProjectBinding().map(EclipseProjectBinding::projectKey).orElse(null); if (!Objects.equals(serverId, oldServerId) || !Objects.equals(projectKey, oldProjectKey)) { + // We can ignore path prefixes for now, they will be update by the ProjectStorageUpdateJob projectConfig.setProjectBinding(new EclipseProjectBinding(serverId, projectKey, "", "")); changed = true; }