use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class JGitBlameCommandTest method dontFailOnSymlink.
@Test
public void dontFailOnSymlink() throws IOException {
assumeTrue(!System2.INSTANCE.isOsWindows());
File projectDir = temp.newFolder();
javaUnzip("dummy-git.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
String relativePath = DUMMY_JAVA;
String relativePath2 = "src/main/java/org/dummy/Dummy2.java";
DefaultInputFile inputFile = new TestInputFileBuilder("foo", relativePath).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
DefaultInputFile inputFile2 = new TestInputFileBuilder("foo", relativePath2).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile2);
// Create symlink
Files.createSymbolicLink(inputFile2.file().toPath(), inputFile.file().toPath());
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile, inputFile2));
jGitBlameCommand.blame(input, blameResult);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_skip_significant_code_on_pull_request_when_file_status_is_SAME.
@Test
public void should_skip_significant_code_on_pull_request_when_file_status_is_SAME() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setStatus(InputFile.Status.SAME).setContents("foo").build();
when(branchConfiguration.isPullRequest()).thenReturn(true);
underTest.store(new DefaultSignificantCode().onFile(file).addRange(file.selectLine(1)));
assertThat(reportWriter.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, file.scannerId())).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_save_file_measure.
@Test
public void should_save_file_measure() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
underTest.store(new DefaultMeasure().on(file).forMetric(CoreMetrics.NCLOC).withValue(10));
ScannerReport.Measure m = reportReader.readComponentMeasures(file.scannerId()).next();
assertThat(m.getIntValue().getValue()).isEqualTo(10);
assertThat(m.getMetricKey()).isEqualTo(CoreMetrics.NCLOC_KEY);
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_skip_highlighting_on_pr_when_file_status_is_SAME.
@Test
public void should_skip_highlighting_on_pr_when_file_status_is_SAME() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setContents("// comment").setStatus(InputFile.Status.SAME).build();
when(branchConfiguration.isPullRequest()).thenReturn(true);
DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD);
underTest.store(highlighting);
assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isFalse();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class MetadataGeneratorTest method start_with_bom.
@Test
public void start_with_bom() throws Exception {
Path tempFile = temp.newFile().toPath();
FileUtils.write(tempFile.toFile(), "\uFEFFfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
DefaultInputFile inputFile = createInputFileWithMetadata(tempFile);
assertThat(inputFile.lines()).isEqualTo(3);
assertThat(inputFile.nonBlankLines()).isEqualTo(3);
assertThat(inputFile.hash()).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(inputFile.originalLineStartOffsets()).containsOnly(0, 4, 9);
assertThat(inputFile.originalLineEndOffsets()).containsOnly(3, 7, 12);
}
Aggregations