use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method language_without_publishAllFiles_should_not_auto_publish_files.
@Test
public void language_without_publishAllFiles_should_not_auto_publish_files() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo3", "Sample xoo\ncontent");
writeFile(srcDir, "sample2.xoo3", "Sample xoo 2\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
assertThat(result.inputFiles()).extracting(InputFile::filename, InputFile::language, f -> ((DefaultInputFile) f).isPublished()).containsOnly(tuple("sample.xoo3", "xoo3", false), tuple("sample2.xoo3", "xoo3", false));
assertThat(result.getReportReader().readComponent(result.getReportReader().readMetadata().getRootComponentRef()).getChildRefCount()).isZero();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method publishFilesWithIssues.
@Test
public void publishFilesWithIssues() throws IOException {
tester.addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo");
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
assertThat(file.isPublished()).isTrue();
assertThat(result.getReportComponent(file)).isNotNull();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method create_issue_on_any_file.
@Test
public void create_issue_on_any_file() throws IOException {
tester.addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssuePerUnknownFile", null, "OneIssuePerUnknownFile", "MAJOR", null, "xoo");
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.unknown", "Sample xoo\ncontent");
logTester.setLevel(LoggerLevel.DEBUG);
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
assertThat(logTester.logs()).contains("1 file indexed");
assertThat(logTester.logs()).contains("'src" + File.separator + "sample.unknown' indexed with no language");
assertThat(logTester.logs()).contains("'src/sample.unknown' generated metadata with charset 'UTF-8'");
DefaultInputFile inputFile = (DefaultInputFile) result.inputFile("src/sample.unknown");
assertThat(result.getReportComponent(inputFile)).isNotNull();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileMetadataTest method ignore_whitespace_when_computing_line_hashes.
@Test
public void ignore_whitespace_when_computing_line_hashes() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", StandardCharsets.UTF_8, true);
DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName()).setModuleBaseDir(tempFile.getParentFile().toPath()).setCharset(StandardCharsets.UTF_8).build();
FileMetadata.computeLineHashesForIssueTracking(f, new FileMetadata.LineHashConsumer() {
@Override
public void consume(int lineIdx, @Nullable byte[] hash) {
switch(lineIdx) {
case 1:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("foo"));
break;
case 2:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("bar"));
break;
case 3:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("baz"));
break;
default:
fail("Invalid line");
}
}
});
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileMetadataTest method dont_fail_on_empty_file.
@Test
public void dont_fail_on_empty_file() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "", StandardCharsets.UTF_8, true);
DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName()).setModuleBaseDir(tempFile.getParentFile().toPath()).setCharset(StandardCharsets.UTF_8).build();
FileMetadata.computeLineHashesForIssueTracking(f, new FileMetadata.LineHashConsumer() {
@Override
public void consume(int lineIdx, @Nullable byte[] hash) {
switch(lineIdx) {
case 1:
assertThat(hash).isNull();
break;
default:
fail("Invalid line");
}
}
});
}
Aggregations