use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method scanProjectWithTestDir.
@Test
public void scanProjectWithTestDir() throws IOException {
File test = new File(baseDir, "test");
test.mkdir();
writeFile(test, "sampleTest.xoo", "Sample test xoo\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "").put("sonar.tests", "test").build()).execute();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputFile("test/sampleTest.xoo").type()).isEqualTo(InputFile.Type.TEST);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method indexAnyFile.
@Test
public void indexAnyFile() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
writeFile(srcDir, "sample.other", "Sample other\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
assertThat(result.inputFiles()).hasSize(2);
assertThat(result.inputFile("src/sample.other").type()).isEqualTo(InputFile.Type.MAIN);
assertThat(result.inputFile("src/sample.other").relativePath()).isEqualTo("src/sample.other");
assertThat(result.inputFile("src/sample.other").language()).isNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method log_all_exclusions_properties_per_modules.
@Test
public void log_all_exclusions_properties_per_modules() throws IOException {
File baseDir = temp.getRoot();
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
srcDirA.mkdirs();
File srcDirB = new File(baseDirModuleB, "src");
srcDirB.mkdirs();
writeFile(srcDirA, "sample.xoo", "Sample xoo\ncontent");
writeFile(srcDirB, "sample.xoo", "Sample xoo\ncontent");
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").put("sonar.inclusions", "**/global.inclusions").put("sonar.test.inclusions", "**/global.test.inclusions").put("sonar.exclusions", "**/global.exclusions").put("sonar.test.exclusions", "**/global.test.exclusions").put("sonar.coverage.exclusions", "**/coverage.exclusions").put("sonar.cpd.exclusions", "**/cpd.exclusions").build()).execute();
assertThat(logTester.logs(LoggerLevel.INFO)).containsSequence("Project configuration:", " Included sources: **/global.inclusions", " Excluded sources: **/global.exclusions, **/global.test.inclusions", " Included tests: **/global.test.inclusions", " Excluded tests: **/global.test.exclusions", " Excluded sources for coverage: **/coverage.exclusions", " Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'moduleA'", " Base dir: " + baseDirModuleA.getAbsolutePath(), " Source paths: src", " Included sources: **/global.inclusions", " Excluded sources: **/global.exclusions, **/global.test.inclusions", " Included tests: **/global.test.inclusions", " Excluded tests: **/global.test.exclusions", " Excluded sources for coverage: **/coverage.exclusions", " Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'moduleB'", " Base dir: " + baseDirModuleB.getAbsolutePath(), " Source paths: src", " Included sources: **/global.inclusions", " Excluded sources: **/global.exclusions, **/global.test.inclusions", " Included tests: **/global.test.inclusions", " Excluded tests: **/global.test.exclusions", " Excluded sources for coverage: **/coverage.exclusions", " Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'com.foo.project'", " Base dir: " + baseDir.getAbsolutePath(), " Included sources: **/global.inclusions", " Excluded sources: **/global.exclusions, **/global.test.inclusions", " Included tests: **/global.test.inclusions", " Excluded tests: **/global.test.exclusions", " Excluded sources for coverage: **/coverage.exclusions", " Excluded sources for duplication: **/cpd.exclusions");
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method dont_publish_files_without_detected_language.
@Test
public void dont_publish_files_without_detected_language() throws IOException {
Path mainDir = baseDir.toPath().resolve("src").resolve("main");
Files.createDirectories(mainDir);
Path testDir = baseDir.toPath().resolve("src").resolve("test");
Files.createDirectories(testDir);
writeFile(testDir.toFile(), "sample.java", "Sample xoo\ncontent");
writeFile(mainDir.toFile(), "sample.xoo", "Sample xoo\ncontent");
writeFile(mainDir.toFile(), "sample.java", "Sample xoo\ncontent");
logTester.setLevel(LoggerLevel.DEBUG);
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src/main").put("sonar.tests", "src/test").build()).execute();
assertThat(logTester.logs()).containsAnyOf("'src/main/sample.java' indexed with no language", "'src\\main\\sample.java' indexed with no language");
assertThat(logTester.logs()).contains("3 files indexed");
assertThat(logTester.logs()).contains("'src/main/sample.xoo' generated metadata with charset 'UTF-8'");
assertThat(logTester.logs()).doesNotContain("'src/main/sample.java' generated metadata", "'src\\main\\sample.java' generated metadata");
assertThat(logTester.logs()).doesNotContain("'src/test/sample.java' generated metadata", "'src\\test\\sample.java' generated metadata");
DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
assertThatThrownBy(() -> result.getReportComponent(javaInputFile)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find report for component");
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method support_global_server_side_exclusions_for_multi_module_project.
@Test
public void support_global_server_side_exclusions_for_multi_module_project() throws IOException {
File baseDir = temp.getRoot();
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
srcDirA.mkdirs();
File srcDirB = new File(baseDirModuleB, "src");
srcDirB.mkdirs();
writeFile(srcDirA, "sample.xoo", "Sample xoo\ncontent");
writeFile(srcDirB, "sample.xoo", "Sample xoo\ncontent");
tester.addGlobalServerSettings(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*.xoo");
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").build()).execute();
InputFile fileA = result.inputFile("moduleA/src/sample.xoo");
assertThat(fileA).isNull();
InputFile fileB = result.inputFile("moduleB/src/sample.xoo");
assertThat(fileB).isNull();
}
Aggregations