2
2
3
3
import java .io .InputStream ;
4
4
import java .nio .charset .StandardCharsets ;
5
+ import java .util .Set ;
5
6
7
+ import org .apache .commons .lang3 .reflect .FieldUtils ;
6
8
import org .sonar .api .server .rule .RulesDefinition ;
7
9
import org .sonar .api .server .rule .RulesDefinitionXmlLoader ;
10
+ import org .sonar .api .server .rule .RulesDefinition .NewRule ;
11
+ import org .sonar .api .server .rule .RulesDefinition .OwaspTop10 ;
8
12
9
13
public class CloudformationRulesDefinition implements RulesDefinition {
10
14
@@ -27,10 +31,31 @@ private void defineRulesForLanguage(Context context, String repositoryKey, Strin
27
31
if (rulesXml != null ) {
28
32
RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader ();
29
33
rulesLoader .load (repository , rulesXml , StandardCharsets .UTF_8 .name ());
30
- }
31
-
34
+
35
+
36
+ for (NewRule newRule : repository .rules ()) {
37
+
38
+ try {
39
+ final Set <String > tags = (Set <String >) FieldUtils .readField (newRule , "tags" , true );
40
+ for (String tag : tags ) {
41
+
42
+ if (tag .contains ("cweid-" )) {
43
+ newRule .addCwe (Integer .parseInt (tag .replace ("cweid-" , "" )));
44
+ }
45
+
46
+ if (tag .contains ("owasp-" )) {
47
+ newRule .addOwaspTop10 (OwaspTop10 .valueOf (tag .replace ("owasp-" , "" ).toUpperCase ()));
48
+ }
49
+ }
50
+ } catch (IllegalAccessException e ) {
51
+ //LOGGER.warn("Problem parsing security tags",e);
52
+ }
53
+ }
54
+ }
32
55
repository .done ();
56
+
33
57
}
58
+
34
59
35
60
@ Override
36
61
public void define (Context context ) {
0 commit comments