Search in sources :

Example 21 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method simpleXoo.

@Test
public void simpleXoo() throws Exception {
    ClientInputFile inputFile = prepareInputFile("foo.xoo", "function xoo() {\n" + "  var xoo1, xoo2;\n" + "  var xoo; //NOSONAR\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", "startLineOffset", "inputFile.path").containsOnly(tuple("xoo:HasTag", 1, 9, inputFile.getPath()), tuple("xoo:HasTag", 2, 6, inputFile.getPath()), tuple("xoo:HasTag", 2, 12, inputFile.getPath()));
}
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)

Example 22 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method simpleCpp.

@Test
public void simpleCpp() throws Exception {
    ClientInputFile inputFile = prepareInputFile("foo.cpp", "void fun() {\n " + "  int a = 0; \n" + "  if (a) {fun();}\n" + "  if (a) {fun();} // NOSONAR\n" + "}\n", false, StandardCharsets.UTF_8, "cpp");
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of("sonar.cfamily.build-wrapper-output.bypass", "true")), issue -> issues.add(issue), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "startLineOffset", "inputFile.path").containsOnly(tuple("cpp:S2583", 3, 6, inputFile.getPath()));
}
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)

Example 23 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method testJavaSurefireDontCrashAnalysis.

@Test
public void testJavaSurefireDontCrashAnalysis() throws Exception {
    File surefireReport = new File(baseDir, "reports/TEST-FooTest.xml");
    FileUtils.write(surefireReport, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<testsuite name=\"FooTest\" time=\"0.121\" tests=\"1\" errors=\"0\" skipped=\"0\" failures=\"0\">\n" + "<testcase name=\"errorAnalysis\" classname=\"FooTest\" time=\"0.031\"/>\n" + "</testsuite>");
    ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + "  public void foo() {\n" + "    int x;\n" + "    System.out.println(\"Foo\");\n" + "    System.out.println(\"Foo\"); //NOSONAR\n" + "  }\n" + "}", false);
    ClientInputFile inputFileTest = prepareInputFile("FooTest.java", "public class FooTest {\n" + "  public void testFoo() {\n" + "  }\n" + "}", true);
    final List<Issue> issues = new ArrayList<>();
    AnalysisResults results = sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile, inputFileTest), ImmutableMap.of("sonar.junit.reportsPath", "reports/")), issue -> issues.add(issue), null, null);
    assertThat(results.fileCount()).isEqualTo(2);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("squid:S106", 4, inputFile.getPath()), tuple("squid:S1220", null, inputFile.getPath()), tuple("squid:S1481", 3, inputFile.getPath()), tuple("squid:S2187", 1, inputFileTest.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) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) File(java.io.File) Test(org.junit.Test)

Example 24 with StandaloneAnalysisConfiguration

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

the class SonarLintTest method simplePom.

@Test
public void simplePom() throws Exception {
    ClientInputFile inputFile = prepareInputFile("pom.xml", "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "  <modelVersion>4.0.0</modelVersion>\n" + "  <groupId>org.sonarsource.java</groupId>\n" + "  <artifactId>simple-project</artifactId>\n" + "  <version>1.0-SNAPSHOT</version>\n" + "  <packaging>jar</packaging>\n" + "  <properties>" + // S3421 line 7
    "    <deprecated>${pom.artifactId}</deprecated>\n" + "  </properties>\n" + "</project>", 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:S3421", 7, 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 25 with StandaloneAnalysisConfiguration

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

the class SonarLintTest 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" + "    System.out.println(\"Foo\"); //NOSONAR\n" + "  }\n" + "}", false);
    final List<Issue> issues = new ArrayList<>();
    StandaloneAnalysisConfiguration standaloneAnalysisConfiguration = new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Collections.singletonList(inputFile), ImmutableMap.<String, String>of());
    sonarlintEngine.analyze(standaloneAnalysisConfiguration, issues::add, 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) 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