@@ -40,7 +40,7 @@ public TestResults parse(File f) throws Exception {
4040 String fixed = "<sonar>" + new String (bytes , "UTF-8" ) + "</sonar>" ;
4141 InputSource is = new InputSource (new ByteArrayInputStream ( fixed .getBytes () ) );
4242 Document doc = docBuilder .parse (is );
43-
43+
4444 TestResults tr = new TestResults ( "SonarQube" ,false ,TestResults .ToolType .SAST );
4545
4646 NodeList rootList = doc .getDocumentElement ().getChildNodes ();
@@ -55,25 +55,25 @@ public TestResults parse(File f) throws Exception {
5555 }
5656 return tr ;
5757 }
58-
58+
5959 private TestCaseResult parseSonarIssue (Node flaw ) {
6060 TestCaseResult tcr = new TestCaseResult ();
6161 String rule = getNamedChild ("rule" , flaw ).getTextContent ();
6262 tcr .setCWE ( cweLookup ( rule .substring ( "squid:" .length () ) ) );
63-
63+
6464 String cat = getNamedChild ("message" , flaw ).getTextContent ();
6565 tcr .setCategory ( cat );
66-
66+
6767 tcr .setConfidence ( 5 );
6868
6969 tcr .setEvidence ( cat );
7070
7171 String testfile = getNamedChild ("component" , flaw ).getTextContent ().trim ();
7272 testfile = testfile .substring ( testfile .lastIndexOf ('/' ) +1 );
73- if ( testfile .startsWith ( "Benchmark " ) ) {
73+ if ( testfile .matches ( "BenchmarkTest \\ d+.java " ) ) {
7474 String testno = testfile .substring ( "BenchmarkTest" .length (), testfile .length () -5 );
7575 tcr .setNumber ( Integer .parseInt ( testno ) );
76- return tcr ;
76+ return tcr ;
7777 }
7878 return null ;
7979 }
@@ -104,12 +104,12 @@ private TestCaseResult parseSonarIssue(Node flaw) {
104104// case "Weak Cryptographic Hash" : return 328;
105105// case "Weak Encryption" : return 327;
106106// case "XPath Injection" : return 643;
107-
108107
109-
110-
111- public static int cweLookup (String squidNumber ) {
112- switch ( squidNumber ) {
108+
109+
110+
111+ public static int cweLookup (String squidNumber ) {
112+ switch ( squidNumber ) {
113113 case "S00105" : return 0000 ; //S00105-Replace all tab characters in this file by sequences of white-spaces.
114114 case "S106" : return 0000 ; //S00106-Replace this usage of System.out or System.err by a logger.
115115 case "S00112" : return 397 ; //S00112-Generic exceptions should never be thrown
@@ -159,7 +159,6 @@ public static int cweLookup(String squidNumber) {
159159 // System.out.println( "Failed to translate " + squidNumber );
160160 return -1 ;
161161 }
162-
162+
163163}
164-
165-
164+
0 commit comments