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();
}
}
}
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");
}
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);
}
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"));
}
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);
}
Aggregations