use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTest method testCreate.
@Test
public void testCreate() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn("java");
Path path = temp.getRoot().toPath().resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new TestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1);
InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
SonarLintInputFile inputFile = builder.create(file);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.file()).isEqualTo(path.toFile());
assertThat(inputFile.absolutePath()).isEqualTo(toSonarQubePath(path.toString()));
assertThat(inputFile.language()).isEqualTo("java");
assertThat(inputFile.key()).isEqualTo(toSonarQubePath(path.toAbsolutePath().toString()));
assertThat(inputFile.lines()).isEqualTo(1);
assertThat(builder.langDetection()).isEqualTo(langDetection);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTest method testCreateWithLanguageSet.
@Test
public void testCreateWithLanguageSet() throws IOException {
Path path = temp.getRoot().toPath().resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new TestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1, "cpp");
InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
SonarLintInputFile inputFile = builder.create(file);
assertThat(inputFile.language()).isEqualTo("cpp");
verifyZeroInteractions(langDetection);
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedAnalysisConfiguration method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[\n");
if (moduleKey != null) {
sb.append(" moduleKey: ").append(moduleKey).append("\n");
}
sb.append(" baseDir: ").append(baseDir()).append("\n");
sb.append(" workDir: ").append(workDir()).append("\n");
sb.append(" extraProperties: ").append(extraProperties()).append("\n");
sb.append(" inputFiles: [\n");
for (ClientInputFile inputFile : inputFiles()) {
sb.append(" ").append(inputFile.getPath());
sb.append(" (").append(getCharsetLabel(inputFile)).append(")");
if (inputFile.isTest()) {
sb.append(" [test]");
}
sb.append("\n");
}
sb.append(" ]\n");
sb.append("]\n");
return sb.toString();
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneAnalysisConfiguration method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[\n");
sb.append(" baseDir: ").append(baseDir).append("\n");
sb.append(" workDir: ").append(workDir).append("\n");
sb.append(" extraProperties: ").append(extraProperties).append("\n");
sb.append(" inputFiles: [\n");
for (ClientInputFile inputFile : inputFiles) {
sb.append(" ").append(inputFile.getPath());
sb.append(" (").append(getCharsetLabel(inputFile)).append(")");
if (inputFile.isTest()) {
sb.append(" [test]");
}
if (inputFile.language() != null) {
sb.append(" [" + inputFile.language() + "]");
}
sb.append("\n");
}
sb.append(" ]\n");
sb.append("]\n");
return sb.toString();
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedAnalysisConfigurationTest 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();
ClientInputFile inputFile = new TestClientInputFile(temp.getRoot().toPath(), srcFile1, false, StandardCharsets.UTF_8, null);
ClientInputFile testInputFile = new TestClientInputFile(temp.getRoot().toPath(), srcFile2, true, StandardCharsets.UTF_8, null);
Path baseDir = temp.newFolder().toPath();
Path workDir = temp.newFolder().toPath();
ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration("foo", baseDir, workDir, Arrays.asList(inputFile, testInputFile), props);
assertThat(config.toString()).isEqualTo("[\n" + " moduleKey: foo\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) [test]\n" + " ]\n" + "]\n");
assertThat(config.baseDir()).isEqualTo(baseDir);
assertThat(config.workDir()).isEqualTo(workDir);
assertThat(config.inputFiles()).containsExactly(inputFile, testInputFile);
assertThat(config.moduleKey()).isEqualTo("foo");
assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"));
config = new ConnectedAnalysisConfiguration(null, baseDir, workDir, Arrays.asList(inputFile, 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) [test]\n" + " ]\n" + "]\n");
}
Aggregations