Search in sources :

Example 1 with AnalysisResults

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);
}
Also used : Path(java.nio.file.Path) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) Test(org.junit.Test)

Example 2 with AnalysisResults

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);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) URI(java.net.URI) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 3 with AnalysisResults

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()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 4 with AnalysisResults

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");
}
Also used : AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Example 5 with AnalysisResults

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);
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Test(org.junit.Test)

Aggregations

AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)15 Test (org.junit.Test)9 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)7 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)6 Path (java.nio.file.Path)4 ProgressMonitor (org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor)4 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)4 ArrayList (java.util.ArrayList)3 Module (com.intellij.openapi.module.Module)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)2 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)2 LogOutput (org.sonarsource.sonarlint.core.client.api.common.LogOutput)2 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)2 LoggedErrorHandler (org.sonarsource.sonarlint.core.util.LoggedErrorHandler)2 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1