use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.
the class SonarLintEngineManager method getConnectedEngine.
public synchronized ConnectedSonarLintEngine getConnectedEngine(SonarLintProjectNotifications notifications, String serverId, String projectKey) throws InvalidBindingException {
Preconditions.checkNotNull(notifications, "notifications");
Preconditions.checkNotNull(serverId, "serverId");
Preconditions.checkNotNull(projectKey, "projectKey");
if (!configuredStorageIds.contains(serverId)) {
notifications.notifyServerIdInvalid();
throw new InvalidBindingException("Invalid server name: " + serverId);
}
ConnectedSonarLintEngine engine = getConnectedEngine(serverId);
checkConnectedEngineStatus(engine, notifications, serverId, projectKey);
return engine;
}
use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.
the class SonarLintEngineManager method disposeComponent.
@Override
public void disposeComponent() {
for (ConnectedSonarLintEngine e : engines.values()) {
e.stop(false);
}
engines.clear();
if (standalone != null) {
standalone.stop();
standalone = null;
}
}
use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.
the class UpdateChecker method checkForUpdate.
void checkForUpdate() {
ConnectedSonarLintEngine engine;
try {
engine = projectBindingManager.getConnectedEngine();
} catch (Exception e) {
// happens if project is not bound, binding is invalid, storages are not updated, ...
log.log("Couldn't get a connected engine to check for update: " + e.getMessage(), LogOutput.Level.DEBUG);
return;
}
try {
List<String> changelog = new ArrayList<>();
ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(projectBindingManager.getSonarQubeServer());
log.log("Check for updates from server '" + projectBindingManager.getSonarQubeServer().getName() + "'...", LogOutput.Level.INFO);
boolean hasGlobalUpdates = checkForGlobalUpdates(changelog, engine, serverConfiguration);
log.log("Check for updates from server '" + projectBindingManager.getSonarQubeServer().getName() + "' for project '" + projectSettings.getProjectKey() + "'...", LogOutput.Level.INFO);
checkForProjectUpdates(changelog, engine, serverConfiguration);
if (!changelog.isEmpty()) {
changelog.forEach(line -> log.log(" - " + line, LogOutput.Level.INFO));
notifications.notifyServerHasUpdates(projectSettings.getServerId(), engine, projectBindingManager.getSonarQubeServer(), !hasGlobalUpdates);
}
} catch (Exception e) {
log.log("There was an error while checking for updates: " + e.getMessage(), LogOutput.Level.WARN);
}
}
use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.
the class ServerIssueUpdaterTest method testDownloadAllServerIssues.
@Test
public void testDownloadAllServerIssues() throws InvalidBindingException {
List<VirtualFile> files = new LinkedList<>();
for (int i = 0; i < 10; i++) {
VirtualFile file = mock(VirtualFile.class);
String filename = "MyFile" + i + ".txt";
when(file.getPath()).thenReturn(FileUtil.toSystemIndependentName(projectBaseDir.resolve(filename).toString()));
files.add(file);
}
ServerIssue serverIssue = mock(ServerIssue.class);
// mock creation of engine / server
ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
when(bindingManager.getConnectedEngine()).thenReturn(engine);
SonarQubeServer server = mock(SonarQubeServer.class);
when(server.getHostUrl()).thenReturn("http://dummyserver:9000");
when(bindingManager.getSonarQubeServer()).thenReturn(server);
// mock issues fetched
when(engine.getServerIssues(eq(PROJECT_KEY), anyString())).thenReturn(Collections.singletonList(serverIssue));
// run
settings.setBindingEnabled(true);
updater.initComponent();
updater.fetchAndMatchServerIssues(files, indicator, false);
verify(issueManager, timeout(3000).times(10)).matchWithServerIssues(any(VirtualFile.class), argThat(issues -> issues.size() == 1));
verify(engine).downloadServerIssues(any(ServerConfiguration.class), eq(PROJECT_KEY));
verify(bindingManager).getConnectedEngine();
verify(console, never()).error(anyString());
verify(console, never()).error(anyString(), any(Throwable.class));
}
use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine in project sonarlint-intellij by SonarSource.
the class ServerIssueUpdaterTest method testServerIssueTracking.
@Test
public void testServerIssueTracking() throws InvalidBindingException {
VirtualFile file = mock(VirtualFile.class);
ServerIssue serverIssue = mock(ServerIssue.class);
String filename = "MyFile.txt";
when(file.getPath()).thenReturn(FileUtil.toSystemIndependentName(projectBaseDir.resolve(filename).toString()));
// mock creation of engine / server
ConnectedSonarLintEngine engine = mock(ConnectedSonarLintEngine.class);
when(bindingManager.getConnectedEngine()).thenReturn(engine);
SonarQubeServer server = mock(SonarQubeServer.class);
when(server.getHostUrl()).thenReturn("http://dummyserver:9000");
when(bindingManager.getSonarQubeServer()).thenReturn(server);
// mock issues downloaded
when(engine.downloadServerIssues(any(ServerConfiguration.class), eq(PROJECT_KEY), eq(filename))).thenReturn(Collections.singletonList(serverIssue));
// run
settings.setBindingEnabled(true);
updater.initComponent();
updater.fetchAndMatchServerIssues(Collections.singletonList(file), indicator, false);
verify(issueManager, timeout(3000).times(1)).matchWithServerIssues(eq(file), argThat(issues -> issues.size() == 1));
verify(bindingManager).getConnectedEngine();
verify(console, never()).error(anyString());
verify(console, never()).error(anyString(), any(Throwable.class));
}
Aggregations