@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); }
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()); } }
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); } } }
@Test public void testDownloadAllServerIssues() throws InvalidBindingException { List<VirtualFile> files = new LinkedList<>(); for (int i = 0; i < 10; i++) { VirtualFile file = mock(VirtualFile.class); when(appUtils.getPathRelativeToProjectBaseDir(project, file)).thenReturn("MyFile" + i + ".txt"); files.add(file); } ServerIssue serverIssue = mock(ServerIssue.class); // mock issues fetched when(engine.getServerIssues(eq(PROJECT_BINDING), anyString())).thenReturn(Collections.singletonList(serverIssue)); // run settings.setBindingEnabled(true); updater.initComponent(); updater.fetchAndMatchServerIssues(Collections.singletonMap(module, 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)); } }
private List<ServerIssue> fetchServerIssuesForFile(ProjectBinding projectBinding, String relativePath) { try { ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server, CONNECTION_TIMEOUT, READ_TIMEOUT); LOGGER.debug("fetchServerIssues projectKey=" + projectBinding.projectKey() + ", filepath=" + relativePath); return engine.downloadServerIssues(serverConfiguration, projectBinding, relativePath); } catch (DownloadException e) { console.info(e.getMessage()); return engine.getServerIssues(projectBinding, relativePath); } } }
@Test public void testServerIssueTracking() throws InvalidBindingException { VirtualFile file = mock(VirtualFile.class); ServerIssue serverIssue = mock(ServerIssue.class); String filename = "MyFile.txt"; when(appUtils.getPathRelativeToProjectBaseDir(project, file)).thenReturn(filename); // mock issues downloaded when(engine.downloadServerIssues(any(ServerConfiguration.class), eq(PROJECT_BINDING), eq(filename))) .thenReturn(Collections.singletonList(serverIssue)); // run settings.setBindingEnabled(true); updater.initComponent(); updater.fetchAndMatchServerIssues(Collections.singletonMap(module, 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)); }
@Override protected void trackIssues(Map<ISonarLintFile, IDocument> docPerFile, Map<ISonarLintIssuable, List<Issue>> rawIssuesPerResource, TriggerType triggerType, IProgressMonitor monitor) { if (triggerType.shouldUpdateProjectIssuesSync(rawIssuesPerResource.size())) { ServerConfiguration serverConfiguration = server.getConfig(); ConnectedSonarLintEngine engine = server.getEngine(); SonarLintLogger.get().debug("Download server issues for project " + getProject().getName()); engine.downloadServerIssues(serverConfiguration, binding.projectKey()); } super.trackIssues(docPerFile, rawIssuesPerResource, triggerType, monitor); if (triggerType.shouldUpdateFileIssuesAsync()) { List<ISonarLintIssuable> filesWithAtLeastOneIssue = filesWithAtLeastOneIssue(rawIssuesPerResource); if (!filesWithAtLeastOneIssue.isEmpty()) { trackServerIssuesAsync(server, filesWithAtLeastOneIssue, docPerFile, triggerType); } } }
public static List<ServerIssue> fetchServerIssues(ServerConfiguration serverConfiguration, ConnectedSonarLintEngine engine, ProjectBinding projectBinding, ISonarLintFile file) { String filePath = file.getProjectRelativePath(); try { SonarLintLogger.get().debug("Download server issues for " + file.getName()); return engine.downloadServerIssues(serverConfiguration, projectBinding, filePath); } catch (DownloadException e) { SonarLintLogger.get().info(e.getMessage()); return engine.getServerIssues(projectBinding, filePath); } }