use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTest method testCreateError.
@Test
public void testCreateError() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn("java");
ClientInputFile file = new TestClientInputFile(Paths.get("INVALID"), "INVALID", true, StandardCharsets.ISO_8859_1);
InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
exception.expect(IllegalStateException.class);
exception.expectMessage("Failed to open a stream on file");
builder.create(file);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneTest method globalExtension.
@Test
public void globalExtension() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.glob", "foo", 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", "inputFile.path", "message").containsOnly(tuple("global:inc", inputFile.getPath(), "Issue number 0"));
issues.clear();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "inputFile.path", "message").containsOnly(tuple("global:inc", inputFile.getPath(), "Issue number 1"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest, Charset encoding, @Nullable String language) throws IOException {
final File file = new File(baseDir, relativePath);
FileUtils.write(file, content, encoding);
ClientInputFile inputFile = new TestClientInputFile(baseDir.toPath(), file.toPath(), isTest, encoding);
return inputFile;
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method analyze.
private void analyze(URI uri, String content) {
Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
files.put(uri, newPublishDiagnostics(uri));
Path baseDir = workspaceRoot != null ? Paths.get(workspaceRoot) : Paths.get(uri).getParent();
Objects.requireNonNull(baseDir);
Objects.requireNonNull(engine);
StandaloneAnalysisConfiguration configuration = new StandaloneAnalysisConfiguration(baseDir, baseDir.resolve(".sonarlint"), Arrays.asList(new DefaultClientInputFile(baseDir, uri, content, userSettings.testFilePattern, languageIdPerFileURI.get(uri))), userSettings.analyzerProperties);
debug("Analysis triggered on " + uri + " with configuration: \n" + configuration.toString());
long start = System.currentTimeMillis();
AnalysisResults analysisResults = engine.analyze(configuration, issue -> {
ClientInputFile inputFile = issue.getInputFile();
if (inputFile != null) {
URI uri1 = inputFile.getClientObject();
PublishDiagnosticsParams publish = files.computeIfAbsent(uri1, SonarLintLanguageServer::newPublishDiagnostics);
convert(issue).ifPresent(publish.getDiagnostics()::add);
}
}, logOutput, null);
telemetry.analysisDoneOnSingleFile(StringUtils.substringAfterLast(uri.toString(), "."), (int) (System.currentTimeMillis() - start));
// Ignore files with parsing error
analysisResults.failedAnalysisFiles().stream().map(ClientInputFile::getClientObject).forEach(files::remove);
files.values().forEach(client::publishDiagnostics);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneAnalysisConfigurationTest method testToString.
@Test
public void testToString() throws Exception {
Map<String, String> props = new HashMap<>();
props.put("sonar.java.libraries", "foo bar");
final Path srcFile1 = temp.newFile().toPath();
final Path srcFile2 = temp.newFile().toPath();
final Path srcFile3 = temp.newFile().toPath();
ClientInputFile inputFile = new TestClientInputFile(temp.getRoot().toPath(), srcFile1, false, StandardCharsets.UTF_8, null);
ClientInputFile inputFileWithLanguage = new TestClientInputFile(temp.getRoot().toPath(), srcFile2, false, StandardCharsets.UTF_8, "java");
ClientInputFile testInputFile = new TestClientInputFile(temp.getRoot().toPath(), srcFile3, true, StandardCharsets.UTF_8, "php");
Path baseDir = temp.newFolder().toPath();
Path workDir = temp.newFolder().toPath();
StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDir, workDir, Arrays.asList(inputFile, inputFileWithLanguage, testInputFile), props);
assertThat(config.toString()).isEqualTo("[\n" + " baseDir: " + baseDir.toString() + "\n" + " workDir: " + workDir.toString() + "\n" + " extraProperties: {sonar.java.libraries=foo bar}\n" + " inputFiles: [\n" + " " + srcFile1.toString() + " (UTF-8)\n" + " " + srcFile2.toString() + " (UTF-8) [java]\n" + " " + srcFile3.toString() + " (UTF-8) [test] [php]\n" + " ]\n" + "]\n");
assertThat(config.baseDir()).isEqualTo(baseDir);
assertThat(config.workDir()).isEqualTo(workDir);
assertThat(config.inputFiles()).containsExactly(inputFile, inputFileWithLanguage, testInputFile);
assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"));
}
Aggregations