Skip to content

Commit 2209d82

Browse files
committed
pr cleanup
1 parent 403caef commit 2209d82

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/AppScanProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.List;
99
import java.util.Set;
1010

11-
/** Provides codemods that act on AppSCan results. */
11+
/** Provides codemods that act on AppScan results. */
1212
public final class AppScanProvider implements CodemodProvider {
1313

1414
@Override

plugins/codemodder-plugin-appscan/src/main/java/io/codemodder/providers/sarif/appscan/AppScanRuleSarif.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ final class AppScanRuleSarif implements RuleSarif {
2121
private final Path repositoryRoot;
2222
private final List<String> locations;
2323

24-
/** A map of a HCL SARIF "location" URIs mapped to their respective file paths. */
24+
/** A map of a AppScan SARIF "location" URIs mapped to their respective file paths. */
2525
private final Map<Path, Set<Integer>> artifactLocationIndices;
2626

2727
/**
28-
* Creates an {@link AppScanRuleSarif} that has already done the work of mapping HCL SARIF
28+
* Creates an {@link AppScanRuleSarif} that has already done the work of mapping AppScan SARIF
2929
* locations, which are strange combinations of class name and file path, into predictable paths.
3030
*/
3131
public AppScanRuleSarif(
@@ -38,9 +38,9 @@ public AppScanRuleSarif(
3838
sarif.getRuns().get(0).getArtifacts().stream()
3939
.map(Artifact::getLocation)
4040
.map(ArtifactLocation::getUri)
41-
.map(u -> u.substring(8))
41+
.map(u -> u.substring(8)) // trim the file:/// of all results
4242
.toList();
43-
Map<Path, Set<Integer>> artifactLocationIndices = new HashMap<>();
43+
Map<Path, Set<Integer>> artifactLocationIndicesMap = new HashMap<>();
4444

4545
for (int i = 0; i < locations.size(); i++) {
4646
final Integer index = i;
@@ -56,9 +56,9 @@ public AppScanRuleSarif(
5656

5757
// add to the map if we found a matching file
5858
existingRealPath.ifPresent(
59-
p -> artifactLocationIndices.computeIfAbsent(p, k -> new HashSet<>()).add(index));
59+
p -> artifactLocationIndicesMap.computeIfAbsent(p, k -> new HashSet<>()).add(index));
6060
}
61-
this.artifactLocationIndices = Map.copyOf(artifactLocationIndices);
61+
this.artifactLocationIndices = Map.copyOf(artifactLocationIndicesMap);
6262
}
6363

6464
private Optional<Path> findFileWithTrailingPath(final String path) throws IOException {
@@ -88,8 +88,8 @@ public List<Region> getRegionsFromResultsByRule(final Path path) {
8888
}
8989

9090
/**
91-
* This call receives an actual source file path, whereas the HCL results store a reference to a
92-
* fully qualified class name plus ".java", e.g.:
91+
* This call receives an actual source file path, whereas the AppScan results store a reference to
92+
* a fully qualified class name plus ".java", e.g.:
9393
*
9494
* <pre>file:///org/owasp/webgoat/lessons/challenges/challenge5/Assignment5.java</pre>
9595
*/
@@ -116,20 +116,29 @@ public List<Result> getResultsByLocationPath(final Path path) {
116116
.toList());
117117
}
118118

119+
@Override
120+
public String getDriver() {
121+
return toolName;
122+
}
123+
124+
/**
125+
* This returns the raw SARIF. This SARIF, for Java, contains binary analysis results. These
126+
* results may need a lot of massaging to act on.
127+
*/
119128
@Override
120129
public SarifSchema210 rawDocument() {
121130
return sarif;
122131
}
123132

133+
/**
134+
* This returns the "ruleId" element, which has a value like "SA2813462719". The "message[text]"
135+
* field has a more human-readable value like "SQL Injection". To stay aligned with other tools
136+
* that use a more strict ID, we use the rule ID.
137+
*/
124138
@Override
125139
public String getRule() {
126140
return ruleId;
127141
}
128142

129-
@Override
130-
public String getDriver() {
131-
return toolName;
132-
}
133-
134143
static final String toolName = "HCL AppScan Static Analyzer";
135144
}

plugins/codemodder-plugin-appscan/src/test/java/io/codemodder/providers/sarif/appscan/AppScanRuleSarifFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void it_parses_sarif_and_maps_java_locations(@TempDir final Path tmpDir) throws
5151
assertThat(ruleSarif.getDriver()).isEqualTo("HCL AppScan Static Analyzer");
5252
assertThat(ruleSarif.rawDocument()).isEqualTo(rawSarif);
5353

54-
// get the results for the file path (not the weird HCL thing) and confirm we have the right
54+
// get the results for the file path (not the weird AppScan thing) and confirm we have the right
5555
// results
5656
List<Result> resultsForPath =
5757
ruleSarif.getResultsByLocationPath(actualAssignmentedJavaFilePath);

0 commit comments

Comments
 (0)