Search in sources :

Example 11 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method simpleTypeScript.

@Test
public void simpleTypeScript() throws Exception {
    RuleDetails ruleDetails = sonarlint.getRuleDetails("typescript:S1764");
    assertThat(ruleDetails.getName()).isEqualTo("Identical expressions should not be used on both sides of a binary operator");
    assertThat(ruleDetails.getLanguage()).isEqualTo("ts");
    assertThat(ruleDetails.getSeverity()).isEqualTo("MAJOR");
    assertThat(ruleDetails.getTags()).containsOnly("cert");
    assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "Using the same value on either side of a binary operator is almost always a mistake");
    final File tsConfig = new File(baseDir, "tsconfig.json");
    FileUtils.write(tsConfig, "{}", StandardCharsets.UTF_8);
    ClientInputFile inputFile = prepareInputFile("foo.ts", "function foo() {\n" + "  if(bar() && bar()) { return 42; }\n" + "}", false);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), i -> issues.add(i), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("typescript:S1764", 2, 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) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) File(java.io.File) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Example 12 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method simpleJavaPomXml.

@Test
public void simpleJavaPomXml() throws Exception {
    ClientInputFile inputFile = prepareInputFile("pom.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project>\n" + "  <modelVersion>4.0.0</modelVersion>\n" + "  <groupId>com.foo</groupId>\n" + "  <artifactId>bar</artifactId>\n" + "  <version>${pom.version}</version>\n" + "</project>", 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:S3421", 6, 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)

Example 13 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method simplePhp.

@Test
public void simplePhp() throws Exception {
    ClientInputFile inputFile = prepareInputFile("foo.php", "<?php\n" + "function writeMsg($fname) {\n" + "    $i = 0; // NOSONAR\n" + "    echo \"Hello world!\";\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").containsOnly(tuple("php:S1172", 2, 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 14 with StandaloneAnalysisConfiguration

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

the class StandaloneIssueMediumTest method concurrentAnalysis.

@Test
public void concurrentAnalysis() throws Throwable {
    final 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 Path workDir = temp.newFolder().toPath();
    int parallelExecutions = 4;
    ExecutorService executor = Executors.newFixedThreadPool(parallelExecutions);
    List<Future<?>> results = new ArrayList<>();
    for (int i = 0; i < parallelExecutions; i++) {
        Runnable worker = new Runnable() {

            @Override
            public void run() {
                sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), workDir, Arrays.asList(inputFile), ImmutableMap.of()), issue -> {
                }, null, null);
            }
        };
        results.add(executor.submit(worker));
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }
    for (Future<?> future : results) {
        try {
            future.get();
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    }
}
Also used : Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) 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) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 15 with StandaloneAnalysisConfiguration

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

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