use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.
the class ConnectedModeTest method parsingErrorJavascript.
@Test
public void parsingErrorJavascript() throws IOException {
String fileContent = "asd asd";
Path testFile = temp.newFile("MyTest.js").toPath();
Files.write(testFile, fileContent.getBytes(StandardCharsets.UTF_8));
updateGlobal();
updateModule(PROJECT_KEY_JAVASCRIPT);
SaveIssueListener issueListener = new SaveIssueListener();
AnalysisResults results = engine.analyze(createAnalysisConfiguration(PROJECT_KEY_JAVASCRIPT, testFile.toString()), issueListener, null, null);
assertThat(results.failedAnalysisFiles()).hasSize(1);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method analyze.
private void analyze(URI uri, String content) {
Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
files.put(uri, newPublishDiagnostics(uri));
Path baseDir = workspaceRoot != null ? Paths.get(workspaceRoot) : Paths.get(uri).getParent();
Objects.requireNonNull(baseDir);
Objects.requireNonNull(engine);
StandaloneAnalysisConfiguration configuration = new StandaloneAnalysisConfiguration(baseDir, baseDir.resolve(".sonarlint"), Arrays.asList(new DefaultClientInputFile(baseDir, uri, content, userSettings.testFilePattern, languageIdPerFileURI.get(uri))), userSettings.analyzerProperties);
debug("Analysis triggered on " + uri + " with configuration: \n" + configuration.toString());
long start = System.currentTimeMillis();
AnalysisResults analysisResults = engine.analyze(configuration, issue -> {
ClientInputFile inputFile = issue.getInputFile();
if (inputFile != null) {
URI uri1 = inputFile.getClientObject();
PublishDiagnosticsParams publish = files.computeIfAbsent(uri1, SonarLintLanguageServer::newPublishDiagnostics);
convert(issue).ifPresent(publish.getDiagnostics()::add);
}
}, logOutput, null);
telemetry.analysisDoneOnSingleFile(StringUtils.substringAfterLast(uri.toString(), "."), (int) (System.currentTimeMillis() - start));
// Ignore files with parsing error
analysisResults.failedAnalysisFiles().stream().map(ClientInputFile::getClientObject).forEach(files::remove);
files.values().forEach(client::publishDiagnostics);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method analysisErrors.
@Test
public void analysisErrors() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.xoo", "function foo() {\n" + " var xoo;\n" + " var y; //NOSONAR\n" + "}", false);
prepareInputFile("foo.xoo.error", "1,2,error analysing\n2,3,error analysing", false);
final List<Issue> issues = new ArrayList<>();
AnalysisResults results = sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(results.failedAnalysisFiles()).containsExactly(inputFile);
assertThat(issues).extracting("ruleKey", "startLine", "startLineOffset", "inputFile.path").containsOnly(tuple("xoo:HasTag", 2, 6, inputFile.getPath()));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.
the class StandaloneNoPluginMediumTest method dont_fail_if_no_plugin.
@Test
public void dont_fail_if_no_plugin() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.js", "function foo() {var x;}", false);
AnalysisResults results = sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), i -> {
}, null, null);
assertThat(results.fileCount()).isEqualTo(1);
assertThat(logs.get(Level.WARN)).contains("No analyzers installed");
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonar-java by SonarSource.
the class SonarLintTest method parse_error_should_report_analysis_error.
@Test
public void parse_error_should_report_analysis_error() throws Exception {
ClientInputFile inputFile = prepareInputFile("ParseError.java", "class ParseError {", false);
final List<Issue> issues = new ArrayList<>();
AnalysisResults analysisResults = sonarlintEngine.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of()), issues::add, null, null);
assertThat(issues).isEmpty();
assertThat(analysisResults.failedAnalysisFiles()).hasSize(1);
}
Aggregations