Search in sources :

Example 26 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 27 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 28 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class StandaloneNoPluginMediumTest method prepareInputFile.

private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
    final File file = new File(baseDir, relativePath);
    FileUtils.write(file, content);
    return TestUtils.createInputFile(file.toPath(), relativePath, isTest);
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) File(java.io.File)

Example 29 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 30 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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

ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)72 Test (org.junit.Test)45 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)36 ArrayList (java.util.ArrayList)30 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)25 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)19 File (java.io.File)14 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)9 Path (java.nio.file.Path)8 HashMap (java.util.HashMap)7 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)7 LinkedList (java.util.LinkedList)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Collection (java.util.Collection)4 AccessToken (com.intellij.openapi.application.AccessToken)3 Logger (com.intellij.openapi.diagnostic.Logger)3 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3