Skip to content

Commit

Permalink
Verify the correct image names.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Oct 15, 2024
1 parent 641de01 commit 3c6dd8a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected AnalysisModelParserDescriptor(final String id, final String descriptio
*/
@Override
public StaticAnalysisLabelProvider getLabelProvider() {
return new StaticAnalysisLabelProvider(getId(), getDisplayName(), descriptionProvider);
return new StaticAnalysisLabelProvider(getId(), getDisplayName(), descriptionProvider,
analysisModelDescriptor.getType());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public IssueParser createParser() {
public StaticAnalysisLabelProvider getLabelProvider() {
ParserDescriptor descriptor = getParserDescriptor();

return new StaticAnalysisLabelProvider(descriptor.getId(), getName(), descriptor::getDescription);
return new StaticAnalysisLabelProvider(descriptor.getId(), getName(), descriptor::getDescription,
descriptor.getType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ void shouldFindAllYamlLintIssues() {
/** Runs the YamlLint parser on an output file that contains 4 issues. */
@Test
void shouldFindAllYoctoIssues() {
shouldFindIssuesOfTool(25, new YoctoScanner(), "yocto_scanner_result.json");
var action = shouldFindIssuesOfTool(25, new YoctoScanner(), "yocto_scanner_result.json");

assertThat(action.getIconFileName()).contains("shield");
}

/** Runs the Iar parser on an output file that contains 6 issues. */
Expand Down Expand Up @@ -298,7 +300,9 @@ void shouldFindAllDocFXIssues() {
/** Runs the ErrorProne parser on output files that contain 9 + 2 issues. */
@Test
void shouldFindAllErrorProneIssues() {
shouldFindIssuesOfTool(9 + 2, new ErrorProne(), "errorprone-maven.log", "gradle-error-prone.log");
var action = shouldFindIssuesOfTool(9 + 2, new ErrorProne(), "errorprone-maven.log", "gradle-error-prone.log");

assertThat(action.getIconFileName()).contains("bug");
}

/** Runs the Flake8 parser on an output file that contains 12 issues. */
Expand Down Expand Up @@ -362,8 +366,8 @@ void shouldFindAllZptLintStyleIssues() {
/** Runs the CPD parser on an output file that contains 2 issues. */
@Test
void shouldFindAllCpdIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(2, new Cpd(), "cpd.xml");
Report reportAnsi = findIssuesWithAnsiColorPlugin(2, new Cpd(), "cpd.xml");
Report report = findReportWithoutAnsiColorPlugin(2, new Cpd(), "cpd.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(2, new Cpd(), "cpd.xml");

assertThatDescriptionOfIssueIsSet(new Cpd(), report.get(0), CODE_FRAGMENT);
assertThatDescriptionOfIssueIsSet(new Cpd(), reportAnsi.get(0), CODE_FRAGMENT);
Expand All @@ -372,14 +376,16 @@ void shouldFindAllCpdIssues() {
/** Runs the Simian parser on an output file that contains 4 issues. */
@Test
void shouldFindAllSimianIssues() {
shouldFindIssuesOfTool(4, new Simian(), "simian.xml");
var action = shouldFindIssuesOfTool(4, new Simian(), "simian.xml");

assertThat(action.getIconFileName()).contains("clone");
}

/** Runs the DupFinder parser on an output file that contains 2 issues. */
@Test
void shouldFindAllDupFinderIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(2, new DupFinder(), "dupfinder.xml");
Report reportAnsi = findIssuesWithAnsiColorPlugin(2, new DupFinder(), "dupfinder.xml");
Report report = findReportWithoutAnsiColorPlugin(2, new DupFinder(), "dupfinder.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(2, new DupFinder(), "dupfinder.xml");

assertThatDescriptionOfIssueIsSet(new DupFinder(), report.get(0),
"<pre><code>if (items &#61;&#61; null) throw new ArgumentNullException(&#34;items&#34;);</code></pre>");
Expand All @@ -390,7 +396,9 @@ void shouldFindAllDupFinderIssues() {
/** Runs the Armcc parser on output files that contain 3 + 3 issues. */
@Test
void shouldFindAllArmccIssues() {
shouldFindIssuesOfTool(3 + 3, new ArmCc(), "armcc5.txt", "armcc.txt");
var action = shouldFindIssuesOfTool(3 + 3, new ArmCc(), "armcc5.txt", "armcc.txt");

assertThat(action.getIconFileName()).contains("triangle-exclamation");
}

/** Runs the Buckminster parser on an output file that contains 3 issues. */
Expand All @@ -414,8 +422,8 @@ void shouldFindAllMentorGraphicsIssues() {
/** Runs the PMD parser on an output file that contains 262 issues (PMD 6.1.0). */
@Test
void shouldFindAllPmdIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(262, new Pmd(), "pmd-6.xml");
Report reportAnsi = findIssuesWithAnsiColorPlugin(262, new Pmd(), "pmd-6.xml");
Report report = findReportWithoutAnsiColorPlugin(262, new Pmd(), "pmd-6.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(262, new Pmd(), "pmd-6.xml");

assertThatDescriptionOfIssueIsSet(new Pmd(), report.get(0),
"A high number of imports can indicate a high degree of coupling within an object.");
Expand All @@ -426,8 +434,8 @@ void shouldFindAllPmdIssues() {
/** Runs the CheckStyle parser on an output file that contains 6 issues. */
@Test
void shouldFindAllCheckStyleIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(6, new CheckStyle(), "checkstyle.xml");
Report reportAnsi = findIssuesWithAnsiColorPlugin(6, new CheckStyle(), "checkstyle.xml");
Report report = findReportWithoutAnsiColorPlugin(6, new CheckStyle(), "checkstyle.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(6, new CheckStyle(), "checkstyle.xml");

assertThatDescriptionOfIssueIsSet(new CheckStyle(), report.get(2),
"<p>Since Checkstyle 3.1</p><p>");
Expand All @@ -451,8 +459,8 @@ private void assertThatDescriptionOfIssueIsSet(final Tool tool, final Issue issu
/** Runs the FindBugs parser on an output file that contains 2 issues. */
@Test
void shouldFindAllFindBugsIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(2, new FindBugs(), "findbugs-native.xml");
Report reportAnsi = findIssuesWithAnsiColorPlugin(2, new FindBugs(), "findbugs-native.xml");
Report report = findReportWithoutAnsiColorPlugin(2, new FindBugs(), "findbugs-native.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(2, new FindBugs(), "findbugs-native.xml");

assertThatDescriptionOfIssueIsSet(new FindBugs(), report.get(0),
"<p> The fields of this class appear to be accessed inconsistently with respect\n"
Expand Down Expand Up @@ -523,10 +531,10 @@ void shouldFindAllSpotBugsIssues() {
+ "to instruct SpotBugs that ignoring the return value of this method is acceptable.\n"
+ "</p>";

Report report = findIssuesWithoutAnsiColorPlugin(2, new SpotBugs(), "spotbugsXml.xml");
Report report = findReportWithoutAnsiColorPlugin(2, new SpotBugs(), "spotbugsXml.xml");
assertThatDescriptionOfIssueIsSet(new SpotBugs(), report.get(0), expectedDescription);

Report reportAnsi = findIssuesWithAnsiColorPlugin(2, new SpotBugs(), "spotbugsXml.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(2, new SpotBugs(), "spotbugsXml.xml");
assertThatDescriptionOfIssueIsSet(new SpotBugs(), reportAnsi.get(0), expectedDescription);
}

Expand All @@ -539,13 +547,13 @@ void shouldProvideMessagesAndDescriptionForSecurityIssuesWithSpotBugs() {
+ "<p>This rule identifies <b>potential</b> path traversal vulnerabilities. In many cases, the constructed file path cannot be controlled\n"
+ "by the user. If that is the case, the reported instance is a false positive.</p>";

Report report = findIssuesWithoutAnsiColorPlugin(1, new SpotBugs(), "issue55707.xml");
Report report = findReportWithoutAnsiColorPlugin(1, new SpotBugs(), "issue55707.xml");
Issue issue = report.get(0);
assertThatDescriptionOfIssueIsSet(new SpotBugs(), issue, expectedDescription);
assertThat(issue).hasMessage(
"java/nio/file/Paths.get(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path; reads a file whose location might be specified by user input");

Report reportAnsi = findIssuesWithAnsiColorPlugin(1, new SpotBugs(), "issue55707.xml");
Report reportAnsi = findReportWithAnsiColorPlugin(1, new SpotBugs(), "issue55707.xml");
Issue issueAnsi = reportAnsi.get(0);
assertThatDescriptionOfIssueIsSet(new SpotBugs(), issueAnsi, expectedDescription);
assertThat(issueAnsi).hasMessage(
Expand Down Expand Up @@ -813,8 +821,8 @@ void shouldFindAllEclipseIssues() {
/** Runs the PyLint parser on output files that contains 6 + 19 issues. */
@Test
void shouldFindAllPyLintParserIssues() {
Report report = findIssuesWithoutAnsiColorPlugin(6 + 19, new PyLint(), "pyLint.txt", "pylint_parseable.txt");
Report reportAnsi = findIssuesWithAnsiColorPlugin(6 + 19, new PyLint(), "pyLint.txt",
Report report = findReportWithoutAnsiColorPlugin(6 + 19, new PyLint(), "pyLint.txt", "pylint_parseable.txt");
Report reportAnsi = findReportWithAnsiColorPlugin(6 + 19, new PyLint(), "pyLint.txt",
"pylint_parseable.txt");

assertThatDescriptionOfIssueIsSet(new PyLint(), report.get(1),
Expand Down Expand Up @@ -977,7 +985,9 @@ void shouldFindAllOTDockerLintIssues() {
/** Runs the OWASP dependency check parser on an output file that contains 2 issues. */
@Test
void shouldFindOwaspDependencyCheckIssues() {
shouldFindIssuesOfTool(2, new OwaspDependencyCheck(), "dependency-check-report.json");
var action = shouldFindIssuesOfTool(2, new OwaspDependencyCheck(), "dependency-check-report.json");

assertThat(action.getIconFileName()).contains("shield");
}

/** Runs the Brakeman parser on an output file that contains 32 issues. */
Expand Down Expand Up @@ -1062,13 +1072,23 @@ private ResultAction shouldFindIssuesOfTool(final int expectedSizeOfIssues, fina
return action;
}

private Report findReportWithoutAnsiColorPlugin(final int expectedSizeOfIssues, final ReportScanningTool tool,
final String... fileNames) {
return findIssuesWithoutAnsiColorPlugin(expectedSizeOfIssues, tool, fileNames).getResult().getIssues();
}

private ResultAction findIssuesWithoutAnsiColorPlugin(final int expectedSizeOfIssues, final ReportScanningTool tool,
final String... fileNames) {
return findIssuesInPipeline(
"recordIssues tool: %s(pattern:'**/%s', reportEncoding:'UTF-8')", expectedSizeOfIssues, tool,
fileNames);
}

private Report findReportWithAnsiColorPlugin(final int expectedSizeOfIssues,
final ReportScanningTool tool, final String... fileNames) {
return findIssuesWithAnsiColorPlugin(expectedSizeOfIssues, tool, fileNames).getResult().getIssues();
}

private ResultAction findIssuesWithAnsiColorPlugin(final int expectedSizeOfIssues,
final ReportScanningTool tool, final String... fileNames) {
String pipelineDefinition = "wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {\n"
Expand Down

0 comments on commit 3c6dd8a

Please sign in to comment.