use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method scanBigProject.
@Test
public void scanBigProject() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
int nbFiles = 100;
int ruleCount = 100000;
for (int nb = 1; nb <= nbFiles; nb++) {
File xooFile = new File(srcDir, "sample" + nb + ".xoo");
FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", ruleCount / 1000));
}
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
assertThat(result.inputFiles()).hasSize(100);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method ignore_files_outside_project_basedir.
@Test
public void ignore_files_outside_project_basedir() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample1.xoo", "Sample xoo\ncontent");
File outsideBaseDir = temp.newFolder().getCanonicalFile();
File xooFile2 = writeFile(outsideBaseDir, "another.xoo", "Sample xoo 2\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src," + PathUtils.canonicalPath(xooFile2)).build()).execute();
assertThat(result.inputFiles()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.WARN)).contains("File '" + xooFile2.getAbsolutePath() + "' is ignored. It is not located in project basedir '" + baseDir + "'.");
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method exclusion_based_on_scm_info.
@Test
public void exclusion_based_on_scm_info() {
File projectDir = new File("test-resources/mediumtest/xoo/sample-with-ignored-file");
AnalysisResult result = tester.newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.exclusions", "**/*.xoo.ignore").property("sonar.test.exclusions", "**/*.xoo.ignore").execute();
assertThat(result.inputFile("xources/hello/ClassTwo.xoo")).isNull();
assertThat(result.inputFile("testx/ClassTwoTest.xoo")).isNull();
assertThat(result.inputFile("xources/hello/ClassOne.xoo")).isNotNull();
assertThat(result.inputFile("testx/ClassOneTest.xoo")).isNotNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult 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.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method support_global_server_side_global_exclusions_for_multi_module_project.
@Test
public void support_global_server_side_global_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.GLOBAL_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