Skip to content

Commit 4a98fa1

Browse files
authored
✨ allow SARIF to be bound from multiple rule IDs (#421)
1 parent 785ead7 commit 4a98fa1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ protected void configure() {
4141
.findFirst();
4242

4343
annotation.ifPresent(
44-
providedAppScanScan ->
45-
bind(RuleSarif.class)
46-
.annotatedWith(providedAppScanScan)
47-
.toInstance(map.getOrDefault(providedAppScanScan.ruleId(), RuleSarif.EMPTY)));
44+
providedAppScanScan -> {
45+
RuleSarif sarif = null;
46+
for (final var ruleId : providedAppScanScan.ruleIds()) {
47+
final var value = map.get(ruleId);
48+
if (value != null) {
49+
sarif = value;
50+
break;
51+
}
52+
}
53+
54+
if (sarif == null) {
55+
sarif = RuleSarif.EMPTY;
56+
}
57+
58+
bind(RuleSarif.class).annotatedWith(providedAppScanScan).toInstance(sarif);
59+
});
4860
}
4961
}
5062
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
@Target(ElementType.PARAMETER)
1414
public @interface ProvidedAppScanScan {
1515

16-
/** The AppScan rule "id" field from the sarif. */
17-
String ruleId();
16+
/**
17+
* The AppScan rule "id" field from the sarif. If multiple are provided, we look for the first ID
18+
* in the SARIF before looking up alternative rule IDs
19+
*/
20+
String[] ruleIds();
1821
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static class AppScanSarifTestCodemod implements CodeChanger {
2828
private final RuleSarif ruleSarif;
2929

3030
@Inject
31-
AppScanSarifTestCodemod(@ProvidedAppScanScan(ruleId = "SA2813462719") RuleSarif ruleSarif) {
31+
AppScanSarifTestCodemod(@ProvidedAppScanScan(ruleIds = {"SA2813462719"}) RuleSarif ruleSarif) {
3232
this.ruleSarif = ruleSarif;
3333
}
3434

0 commit comments

Comments
 (0)