21
21
* questions.
22
22
*/
23
23
24
+ import javax .xml .XMLConstants ;
24
25
import javax .xml .stream .XMLInputFactory ;
25
26
import javax .xml .stream .XMLStreamConstants ;
26
27
import javax .xml .stream .XMLStreamException ;
@@ -39,34 +40,32 @@ public class GTestResultParser {
39
40
public GTestResultParser (Path file ) {
40
41
List <String > failedTests = new ArrayList <>();
41
42
try (Reader r = Files .newBufferedReader (file )) {
42
- try {
43
- XMLStreamReader xmlReader = XMLInputFactory .newInstance ()
44
- .createXMLStreamReader (r );
45
- String testSuite = null ;
46
- String testCase = null ;
47
- while (xmlReader .hasNext ()) {
48
- switch (xmlReader .next ()) {
49
- case XMLStreamConstants .START_ELEMENT :
50
- switch (xmlReader .getLocalName ()) {
51
- case "testsuite" :
52
- testSuite = xmlReader .getAttributeValue ("" , "name" );
53
- break ;
54
- case "testcase" :
55
- testCase = xmlReader .getAttributeValue ("" , "name" );
56
- break ;
57
- case "failure" :
58
- failedTests .add (testSuite + "::" + testCase );
59
- default :
60
- // ignore
61
- }
43
+ XMLInputFactory factory = XMLInputFactory .newInstance ();
44
+ factory .setProperty (XMLConstants .ACCESS_EXTERNAL_DTD , "" );
45
+ factory .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
46
+ XMLStreamReader xmlReader = factory .createXMLStreamReader (r );
47
+ String testSuite = null ;
48
+ String testCase = null ;
49
+ while (xmlReader .hasNext ()) {
50
+ int code = xmlReader .next ();
51
+ if (code == XMLStreamConstants .START_ELEMENT ) {
52
+ switch (xmlReader .getLocalName ()) {
53
+ case "testsuite" :
54
+ testSuite = xmlReader .getAttributeValue ("" , "name" );
55
+ break ;
56
+ case "testcase" :
57
+ testCase = xmlReader .getAttributeValue ("" , "name" );
58
+ break ;
59
+ case "failure" :
60
+ failedTests .add (testSuite + "::" + testCase );
62
61
break ;
63
62
default :
64
63
// ignore
65
64
}
66
65
}
67
- } catch (XMLStreamException e ) {
68
- throw new IllegalArgumentException ("can't open parse xml " + file , e );
69
66
}
67
+ } catch (XMLStreamException e ) {
68
+ throw new IllegalArgumentException ("can't open parse xml " + file , e );
70
69
} catch (IOException e ) {
71
70
throw new IllegalArgumentException ("can't open result file " + file , e );
72
71
}
0 commit comments