use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueExclusionByBlock.
@Test
public void testIssueExclusionByBlock() throws Exception {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "1\nSONAR-OFF 2\n3\n4\n5\nSONAR-ON 6\n7\n8\n9\n10", StandardCharsets.UTF_8);
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").build()).property("sonar.issue.ignore.block", "1").property("sonar.issue.ignore.block.1.beginBlockRegexp", "SON.*-OFF").property("sonar.issue.ignore.block.1.endBlockRegexp", "SON.*-ON").execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues).hasSize(5);
assertThat(issues).extracting("textRange.startLine").containsExactlyInAnyOrder(1, 7, 8, 9, 10);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method warn_user_for_outdated_IssueExclusionByEnforceMultiCriteria.
@Test
public void warn_user_for_outdated_IssueExclusionByEnforceMultiCriteria() throws Exception {
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();
File xooFileA = new File(srcDirA, "sampleA.xoo");
FileUtils.write(xooFileA, "1\n2\n3\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
File xooFileB = new File(srcDirB, "sampleB.xoo");
FileUtils.write(xooFileB, "1\n2\n3\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
tester.addProjectServerSettings("sonar.issue.enforce.multicriteria", "1").addProjectServerSettings("sonar.issue.enforce.multicriteria.1.ruleKey", "*").addProjectServerSettings("sonar.issue.enforce.multicriteria.1.resourceKey", "src/sampleA.xoo");
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.modules", "moduleA,moduleB").put("sonar.sources", "src").build()).execute();
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Specifying module-relative paths at project level in property 'sonar.issue.enforce.multicriteria' is deprecated. To continue matching files like 'moduleA/src/sampleA.xoo', update this property so that patterns refer to project-relative paths.");
List<Issue> issues = result.issuesFor(result.inputFile("moduleA/src/sampleA.xoo"));
assertThat(issues).hasSize(10);
issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo"));
assertThat(issues).isEmpty();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueDetails.
@Test
public void testIssueDetails() throws IOException {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10", StandardCharsets.UTF_8);
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").build()).execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
assertThat(issues).hasSize(10);
assertThat(issues).extracting("msg", "textRange.startLine", "gap").contains(tuple("This issue is generated on each line", 1, 0.0));
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method warn_user_for_unsupported_module_level_IssueExclusion.
@Test
public void warn_user_for_unsupported_module_level_IssueExclusion() throws Exception {
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();
File xooFileA = new File(srcDirA, "sampleA.xoo");
FileUtils.write(xooFileA, "1\n2\n3\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
File xooFileB = new File(srcDirB, "sampleB.xoo");
FileUtils.write(xooFileB, "1\n2\n3\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.modules", "moduleA,moduleB").put("sonar.sources", "src").put("sonar.scm.disabled", "true").put("sonar.issue.ignore.multicriteria", "1").put("sonar.issue.ignore.multicriteria.1.ruleKey", "*").put("sonar.issue.ignore.multicriteria.1.resourceKey", "*").build()).execute();
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.modules", "moduleA,moduleB").put("sonar.sources", "src").put("sonar.scm.disabled", "true").put("moduleA.sonar.issue.ignore.multicriteria", "1").put("moduleA.sonar.issue.ignore.multicriteria.1.ruleKey", "*").put("moduleA.sonar.issue.ignore.multicriteria.1.resourceKey", "*").build()).execute();
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Specifying issue exclusions at module level is not supported anymore. Configure the property 'sonar.issue.ignore.multicriteria' and any other issue exclusions at project level.");
List<Issue> issues = result.issuesFor(result.inputFile("moduleA/src/sampleA.xoo"));
assertThat(issues).hasSize(10);
issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo"));
assertThat(issues).hasSize(10);
// SONAR-11850 The Maven scanner replicates properties defined on the root module to all modules
logTester.clear();
result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.modules", "moduleA,moduleB").put("sonar.sources", "src").put("sonar.scm.disabled", "true").put("sonar.issue.ignore.multicriteria", "1").put("sonar.issue.ignore.multicriteria.1.ruleKey", "*").put("sonar.issue.ignore.multicriteria.1.resourceKey", "*").put("moduleA.sonar.issue.ignore.multicriteria", "1").put("moduleA.sonar.issue.ignore.multicriteria.1.ruleKey", "*").put("moduleA.sonar.issue.ignore.multicriteria.1.resourceKey", "*").build()).execute();
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class ProjectBuilderMediumTest method testProjectBuilder.
@Test
public void testProjectBuilder() throws IOException {
File baseDir = prepareProject();
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", ".").put("sonar.verbose", "true").put("sonar.xoo.enableProjectBuilder", "true").build()).execute();
List<Issue> issues = result.issuesFor(result.inputFile("module1/src/sample.xoo"));
assertThat(issues).hasSize(10);
assertThat(issues).extracting("msg", "textRange.startLine", "gap").contains(tuple("This issue is generated on each line", 1, 0.0));
}
Aggregations