use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueExclusionByEnforceMultiCriteria.
@Test
public void testIssueExclusionByEnforceMultiCriteria() throws Exception {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
activateTODORule();
File xooFile1 = new File(srcDir, "sample1.xoo");
FileUtils.write(xooFile1, "1\n2\n3 TODO\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
File xooFile11 = new File(srcDir, "sample11.xoo");
FileUtils.write(xooFile11, "1\n2\n3 TODO\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.sources", "src").build()).property("sonar.issue.enforce.multicriteria", "1,2").property("sonar.issue.enforce.multicriteria.1.ruleKey", "xoo:HasTag").property("sonar.issue.enforce.multicriteria.1.resourceKey", "src/sample11.xoo").property("sonar.issue.enforce.multicriteria.2.ruleKey", "xoo:One*").property("sonar.issue.enforce.multicriteria.2.resourceKey", "src/sample?.xoo").execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample1.xoo"));
assertThat(issues).hasSize(10);
issues = result.issuesFor(result.inputFile("src/sample11.xoo"));
assertThat(issues).hasSize(2);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method warn_user_for_outdated_IssueExclusionByIgnoreMultiCriteria.
@Test
public void warn_user_for_outdated_IssueExclusionByIgnoreMultiCriteria() 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.ignore.multicriteria", "1").addProjectServerSettings("sonar.issue.ignore.multicriteria.1.ruleKey", "*").addProjectServerSettings("sonar.issue.ignore.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.ignore.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).isEmpty();
issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo"));
assertThat(issues).hasSize(10);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method findActiveRuleByInternalKey.
@Test
public void findActiveRuleByInternalKey() throws Exception {
File projectDir = new File("test-resources/mediumtest/xoo/sample");
File tmpDir = temp.newFolder();
FileUtils.copyDirectory(projectDir, tmpDir);
AnalysisResult result = tester.newAnalysis(new File(tmpDir, "sonar-project.properties")).property("sonar.xoo.internalKey", "OneIssuePerLine.internal").execute();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(issues).hasSize(8 + /* lines */
1);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueExclusionByIgnoreMultiCriteria.
@Test
public void testIssueExclusionByIgnoreMultiCriteria() throws Exception {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
activateTODORule();
File xooFile1 = new File(srcDir, "sample1.xoo");
FileUtils.write(xooFile1, "1\n2\n3 TODO\n4\n5\n6 TODO\n7\n8\n9\n10", StandardCharsets.UTF_8);
File xooFile11 = new File(srcDir, "sample11.xoo");
FileUtils.write(xooFile11, "1\n2\n3 TODO\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.sources", "src").build()).property("sonar.issue.ignore.multicriteria", "1,2").property("sonar.issue.ignore.multicriteria.1.ruleKey", "xoo:HasTag").property("sonar.issue.ignore.multicriteria.1.resourceKey", "src/sample11.xoo").property("sonar.issue.ignore.multicriteria.2.ruleKey", "xoo:One*").property("sonar.issue.ignore.multicriteria.2.resourceKey", "src/sample?.xoo").execute();
List<Issue> issues = result.issuesFor(result.inputFile("src/sample1.xoo"));
assertThat(issues).hasSize(2);
issues = result.issuesFor(result.inputFile("src/sample11.xoo"));
assertThat(issues).hasSize(10);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testOneExternalIssuePerLine.
@Test
public void testOneExternalIssuePerLine() throws Exception {
File projectDir = new File("test-resources/mediumtest/xoo/sample");
File tmpDir = temp.newFolder();
FileUtils.copyDirectory(projectDir, tmpDir);
AnalysisResult result = tester.newAnalysis(new File(tmpDir, "sonar-project.properties")).property(OneExternalIssuePerLineSensor.ACTIVATE, "true").execute();
List<ExternalIssue> externalIssues = result.externalIssuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(externalIssues).hasSize(8);
}
Aggregations