use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class CpdExecutorTest method createComponent.
private DefaultInputFile createComponent(String relativePath, int lines) {
DefaultInputFile file = new TestInputFileBuilder("foo", relativePath).setModuleBaseDir(baseDir.toPath()).setLines(lines).build();
componentStore.put(file);
return file;
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class CpdExecutorTest method timeout.
@Test
public void timeout() {
for (int i = 1; i <= 2; i++) {
DefaultInputFile component = createComponent("src/Foo" + i + ".php", 100);
List<Block> blocks = new ArrayList<>();
for (int j = 1; j <= 10000; j++) {
blocks.add(Block.builder().setResourceId(component.key()).setIndexInFile(j).setLines(j, j + 1).setUnit(j, j + 1).setBlockHash(new ByteArray("abcd1234".getBytes())).build());
}
index.insert((InputFile) component, blocks);
}
executor.execute(1);
readDuplications(0);
assertThat(logTester.logs(LoggerLevel.WARN)).usingElementComparator((l, r) -> l.matches(r) ? 0 : 1).containsOnly("Timeout during detection of duplications for .*Foo1.php", "Timeout during detection of duplications for .*Foo2.php");
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class BranchMediumTest method scanMultiModuleWithBranch.
@Test
public void scanMultiModuleWithBranch() throws IOException {
Path srcDir = baseDir.toPath().resolve("moduleA").resolve("src");
Files.createDirectories(srcDir);
File xooFile = new File(srcDir.toFile(), "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "branch").put("sonar.modules", "moduleA").build()).start();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
// no branch in the report
DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo");
assertThat(result.getReportReader().readComponent(inputfile.batchId()).getPath()).isEqualTo("src/sample.xoo");
// no branch in InputModule's key or in report
assertThat(result.getReportComponent("com.foo.project:moduleA").getKey()).isEqualTo("com.foo.project:moduleA");
assertThat(result.getReportReader().readMetadata().getBranch()).isEqualTo("branch");
result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "").put("sonar.modules", "moduleA").build()).start();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method dontPublishFilesWithoutDetectedLanguage.
@Test
public void dontPublishFilesWithoutDetectedLanguage() throws IOException {
builder = createBuilder();
Path mainDir = baseDir.toPath().resolve("src").resolve("main");
Files.createDirectories(mainDir);
Path testDir = baseDir.toPath().resolve("src").resolve("test");
Files.createDirectories(testDir);
Path testXooFile = testDir.resolve("sample.java");
Files.write(testXooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
Path xooFile = mainDir.resolve("sample.xoo");
Files.write(xooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
Path javaFile = mainDir.resolve("sample.java");
Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src/main").put("sonar.tests", "src/test").build()).start();
assertThat(logs.getAllAsString()).contains("3 files indexed");
assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata");
assertThat(logs.getAllAsString()).doesNotContain("'src/main/sample.java' generated metadata");
assertThat(logs.getAllAsString()).doesNotContain("'src/test/sample.java' generated metadata");
DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
assertThat(result.getReportComponent(javaInputFile.key())).isNull();
}
use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.
the class FileSystemMediumTest method scanProjectWithoutProjectName.
@Test
public void scanProjectWithoutProjectName() throws IOException {
builder = createBuilder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src").build()).start();
int ref = result.getReportReader().readMetadata().getRootComponentRef();
assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputDirs()).hasSize(1);
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
InputDir dir = result.inputDir("src");
assertThat(file.type()).isEqualTo(InputFile.Type.MAIN);
assertThat(file.relativePath()).isEqualTo("src/sample.xoo");
assertThat(file.language()).isEqualTo("xoo");
assertThat(dir.relativePath()).isEqualTo("src");
// file and dirs were published, since language matched xoo
assertThat(file.publish()).isTrue();
assertThat(result.getReportComponent(dir.key())).isNotNull();
assertThat(result.getReportComponent(file.key())).isNotNull();
}
Aggregations