Search in sources :

Example 16 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonar-web by SonarSource.

the class SonarLintTest method should_raise_three_issues.

@Test
public void should_raise_three_issues() throws IOException {
    ClientInputFile inputFile = prepareInputFile("foo.html", "<html>\n" + "<body>\n" + "<a href=\"foo.png\">a</a>\n" + "</body>\n" + "</html>\n", false);
    List<Issue> issues = new ArrayList<>();
    sonarlintEngine.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), new HashMap<>()), issues::add);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("Web:DoctypePresenceCheck", 1, inputFile.getPath(), "MAJOR"), tuple("Web:LinkToImageCheck", 3, inputFile.getPath(), "MAJOR"), tuple("Web:PageWithoutTitleCheck", 1, inputFile.getPath(), "MAJOR"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) HashMap(java.util.HashMap) 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)

Example 17 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration 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)

Example 18 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonar-java by SonarSource.

the class SonarLintTest method supportJavaSuppressWarning.

@Test
public void supportJavaSuppressWarning() throws Exception {
    ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + "  @SuppressWarnings(\"squid:S106\")\n" + "  public void foo() {\n" + "    int x;\n" + "    System.out.println(\"Foo\");\n" + "    System.out.println(\"Foo\"); //NOSONAR\n" + "  }\n" + "}", false);
    final List<Issue> issues = new ArrayList<>();
    sonarlintEngine.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of()), issues::add, null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S1220", null, inputFile.getPath(), "MINOR"), tuple("squid:S1481", 4, inputFile.getPath(), "MINOR"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) 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)

Example 19 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-intellij by SonarSource.

the class StandaloneSonarLintFacade method analyze.

@Override
protected AnalysisResults analyze(Path baseDir, Path workDir, Collection<ClientInputFile> inputFiles, Map<String, String> props, IssueListener issueListener, ProgressMonitor progressMonitor) {
    StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDir, workDir, inputFiles, props);
    console.debug("Starting analysis with configuration:\n" + config.toString());
    return sonarlint.analyze(config, issueListener, new ProjectLogOutput(console, projectSettings), progressMonitor);
}
Also used : ProjectLogOutput(org.sonarlint.intellij.util.ProjectLogOutput) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)

Example 20 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method simpleJava.

@Test
public void simpleJava() throws Exception {
    ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + "  public void foo() {\n" + "    int x;\n" + "    System.out.println(\"Foo\");\n" + "  }\n" + "}", false);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S106", 4, inputFile.getPath(), "MAJOR"), tuple("squid:S1220", null, inputFile.getPath(), "MINOR"), tuple("squid:S1481", 3, inputFile.getPath(), "MINOR"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) 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)

Aggregations

StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)27 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)22 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)15 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)5 File (java.io.File)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)2 RuleDetails (org.sonarsource.sonarlint.core.client.api.common.RuleDetails)2 URI (java.net.URI)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1 DefaultClientInputFile (org.sonarlint.daemon.model.DefaultClientInputFile)1 ProxyIssueListener (org.sonarlint.daemon.model.ProxyIssueListener)1 ProjectLogOutput (org.sonarlint.intellij.util.ProjectLogOutput)1