Search in sources :

Example 56 with ClientInputFile

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);
}
Also used : FileUtils.toSonarQubePath(org.sonarsource.sonarlint.core.client.api.util.FileUtils.toSonarQubePath) Path(java.nio.file.Path) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) InputFile(org.sonar.api.batch.fs.InputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 57 with ClientInputFile

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);
}
Also used : FileUtils.toSonarQubePath(org.sonarsource.sonarlint.core.client.api.util.FileUtils.toSonarQubePath) Path(java.nio.file.Path) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 58 with ClientInputFile

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();
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 59 with ClientInputFile

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();
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 60 with ClientInputFile

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");
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) TestClientInputFile(org.sonarsource.sonarlint.core.client.api.TestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.client.api.TestClientInputFile) 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