@Override public AnalysisResults runAnalysis(ConnectedAnalysisConfiguration config, IssueListener issueListener, IProgressMonitor monitor) { return client.analyze(config, issueListener, null, new WrappedProgressMonitor(monitor, "Analysis")); }
private List<ServerIssue> fetchServerIssues(ServerConfiguration serverConfiguration, ConnectedSonarLintEngine engine, ProjectBinding projectBinding, String fileKey) { try { logger.debug("fetchServerIssues projectKey=" + projectBinding.projectKey() + ", fileKey=" + fileKey); return engine.downloadServerIssues(serverConfiguration, projectBinding, fileKey); } catch (DownloadException e) { logger.debug("failed to download server issues", e); return engine.getServerIssues(projectBinding, fileKey); } } }
@Override protected RuleDetails getRuleDetails(String ruleKey) { return engine.getRuleDetails(ruleKey); }
private void update() { engine.update(getServerConfiguration(server)); engine.allModulesByKey().keySet().stream() .filter(key -> key.equals(moduleKey)) .findAny() .orElseThrow(() -> new IllegalStateException("Project key '" + moduleKey + "' not found in the SonarQube server")); updateModule(); LOGGER.info("Binding updated"); }
@Override protected void doAnalysis(Map<String, String> properties, ReportFactory reportFactory, List<ClientInputFile> inputFiles, Path baseDirPath) { Date start = new Date(); ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(moduleKey, baseDirPath, baseDirPath.resolve(".sonarlint"), inputFiles, properties); IssueCollector collector = new IssueCollector(); AnalysisResults result = engine.analyze(config, collector); engine.downloadServerIssues(getServerConfiguration(server), moduleKey); Collection<Trackable> trackables = matchAndTrack(baseDirPath, collector.get()); generateReports(trackables, result, reportFactory, baseDirPath.getFileName().toString(), baseDirPath, start); }
@Override public void run() { engine.stop(false); } }.start();
Server(String id) { this.id = id; ConnectedGlobalConfiguration globalConfig = ConnectedGlobalConfiguration.builder() .setServerId(getId()) .setWorkDir(StoragePathManager.getServerWorkDir(getId())) .setStorageRoot(StoragePathManager.getServerStorageRoot()) .setLogOutput(new SonarLintAnalyzerLogOutput()) .build(); this.client = new ConnectedSonarLintEngineImpl(globalConfig); this.client.addStateListener(this); this.updateStatus = client.getGlobalStorageStatus(); if (client.getState().equals(State.UPDATED)) { reloadProjects(); } }
@Test public void connected() { ConnectedSonarLintEngine engine = factory.createEngine("id"); assertThat(engine).isNotNull(); assertThat(engine.getGlobalStorageStatus()).isNull(); engine.stop(true); verify(log, atLeastOnce()).log(anyString(), any(LogOutput.Level.class)); } }
private void setStatus(ConnectedSonarLintEngine.State state) { ConnectedSonarLintEngine.State currentState = engine.getState(); StringBuilder builder = new StringBuilder(); switch (currentState) { case NEVER_UPDATED: builder.append("never updated"); break; case UPDATED: GlobalStorageStatus storageStatus = engine.getGlobalStorageStatus(); if (storageStatus != null) { builder.append(DateUtils.toAge(storageStatus.getLastUpdateDate().getTime())); } else { builder.append("up to date"); } break; case UPDATING: builder.append("updating.."); break; case NEED_UPDATE: builder.append("needs update"); break; case UNKNOW: default: builder.append("unknown"); break; } serverStatus.setText(builder.toString()); updateServerButton.setEnabled(state != ConnectedSonarLintEngine.State.UPDATING); }
@Test public void do_nothing_if_no_updates() { StorageUpdateCheckResult result = mock(StorageUpdateCheckResult.class); when(result.needUpdate()).thenReturn(false); when(engine.checkIfProjectStorageNeedUpdate(any(ServerConfiguration.class), anyString(), isNull())).thenReturn(result); when(engine.checkIfGlobalStorageNeedUpdate(any(ServerConfiguration.class), isNull())).thenReturn(result); updateChecker.checkForUpdate(); verify(engine).checkIfGlobalStorageNeedUpdate(any(ServerConfiguration.class), isNull()); verify(engine).checkIfProjectStorageNeedUpdate(any(ServerConfiguration.class), anyString(), isNull()); verifyZeroInteractions(notifications); }
private void switchTo(@Nullable SonarQubeServer server) { if (engineListener != null) { engine.removeStateListener(engineListener); engineListener = null; engine = null; } if (server != null) { engine = serverManager.getConnectedEngine(server.getName()); engineListener = newState -> ApplicationManager.getApplication().invokeLater(() -> { // re-fetch state, as some time might have passed until it was assigned to the EDT and things might have changed if (engine == null) { return; } setStatus(engine.getState()); }); ConnectedSonarLintEngine.State state = engine.getState(); setStatus(state); engine.addStateListener(engineListener); } else { serverStatus.setText("[ no server selected ]"); updateServerButton.setEnabled(false); } }
@Override public boolean isUpdating() { return State.UPDATING == client.getState(); }
public void downloadAllServerIssues(String projectKey) { try { ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server, CONNECTION_TIMEOUT, READ_TIMEOUT); LOGGER.debug("fetchServerIssues projectKey=" + projectKey); engine.downloadServerIssues(serverConfiguration, projectKey); } catch (DownloadException e) { console.info(e.getMessage()); } }
@Test public void should_pass_checks() throws InvalidBindingException { when(connectedEngine.getState()).thenReturn(ConnectedSonarLintEngine.State.UPDATED); when(connectedEngine.getProjectStorageStatus("project1")).thenReturn(projectOk); globalSettings.setSonarQubeServers(Collections.singletonList(createServer("server1"))); manager = new SonarLintEngineManager(globalSettings, engineFactory); manager.initComponent(); assertThat(manager.getConnectedEngine(notifications, "server1", "project1")).isEqualTo(connectedEngine); verify(engineFactory, Mockito.times(1)).createEngine("server1"); verify(connectedEngine).getState(); }
public void fetchAndMatchFile(ProjectBinding projectBinding, VirtualFile virtualFile, String relativePath) { List<ServerIssue> serverIssues = engine.getServerIssues(projectBinding, relativePath); matchFile(virtualFile, serverIssues); }
@Override public void update(ServerConfig request, StreamObserver<Void> response) { try { ServerConfiguration config = transformServerConfig(request); engine.update(config, null); response.onNext(Void.newBuilder().build()); response.onCompleted(); } catch (Exception e) { LOGGER.error("update", e); response.onError(e); } }
@Override public void start(boolean forceUpdate) { GlobalStorageStatus globalStorageStatus = engine.getGlobalStorageStatus(); if (forceUpdate) { LOGGER.info("Updating binding.."); update(); } else if (globalStorageStatus == null) { LOGGER.info("No binding storage found. Updating.."); update(); } else if (globalStorageStatus.isStale()) { LOGGER.info("Binding storage is stale. Updating.."); update(); } else { checkModuleStatus(); } }
private static boolean checkForGlobalUpdates(List<String> changelog, ConnectedSonarLintEngine engine, ServerConfiguration serverConfiguration) { StorageUpdateCheckResult checkForUpdateResult = engine.checkIfGlobalStorageNeedUpdate(serverConfiguration, null); if (checkForUpdateResult.needUpdate()) { changelog.addAll(checkForUpdateResult.changelog()); return true; } return false; }
private void checkForProjectUpdates(List<String> changelog, ConnectedSonarLintEngine engine, ServerConfiguration serverConfiguration) { StorageUpdateCheckResult projectUpdateCheckResult = engine.checkIfProjectStorageNeedUpdate(serverConfiguration, projectSettings.getProjectKey(), null); if (projectUpdateCheckResult.needUpdate()) { changelog.addAll(projectUpdateCheckResult.changelog()); } }
public void stop() { client.stop(false); }