~ubuntu-branches/ubuntu/precise/surefire/precise

« back to all changes in this revision

Viewing changes to maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2011-10-10 20:42:16 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20111010204216-cemva69wkagf4fay
Tags: 2.10-1
* Team upload.
* New upstream release.
* Refresh and remove unneccesary patches.
* Add Build-Depends on libsurefire-java and
  libmaven-common-artifact-filters-java.
* Drop outdated Maven artifact surefire-junit.
* Provide new Maven artifacts: surefire-junit3, maven-surefire-common,
  common-junit3, common-junit4, surefire-junit47 and surefire-testng-utils.
* Fix clean target to allow "two in a row" builds.
* Update Vcs-Browser field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import java.util.Collection;
28
28
import java.util.HashMap;
29
29
import java.util.List;
 
30
import java.util.Locale;
30
31
import java.util.Map;
31
32
import java.util.StringTokenizer;
32
33
 
38
39
import org.xml.sax.SAXException;
39
40
import org.xml.sax.helpers.DefaultHandler;
40
41
 
 
42
/**
 
43
 * @version $Id: TestSuiteXmlParser.java 1125058 2011-05-19 19:06:07Z krosenvold $
 
44
 */
41
45
public class TestSuiteXmlParser
42
46
    extends DefaultHandler
43
47
{
44
48
    private ReportTestSuite defaultSuite;
45
49
    private ReportTestSuite currentSuite;
46
50
    private Map classesToSuites;
47
 
    private NumberFormat numberFormat = NumberFormat.getInstance();
 
51
    private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH);
48
52
 
49
53
    /**
50
54
     * @noinspection StringBufferField
59
63
        SAXParserFactory factory = SAXParserFactory.newInstance();
60
64
 
61
65
        SAXParser saxParser = factory.newSAXParser();
62
 
        
 
66
 
63
67
        classesToSuites = new HashMap();
64
68
 
65
69
        saxParser.parse( new File( xmlPath ), this );
66
 
        
 
70
 
67
71
        if ( currentSuite != defaultSuite )
68
72
        { // omit the defaultSuite if it's empty and there are alternatives
69
 
            if ( defaultSuite.getNumberOfTests() == 0 ) 
 
73
            if ( defaultSuite.getNumberOfTests() == 0 )
70
74
            {
71
75
                classesToSuites.remove( defaultSuite.getFullClassName() );
72
76
            }
73
77
        }
74
 
        
 
78
 
75
79
        return classesToSuites.values();
76
80
    }
77
81
 
 
82
    /** {@inheritDoc} */
78
83
    public void startElement( String uri, String localName, String qName, Attributes attributes )
79
84
        throws SAXException
80
85
    {
92
97
                }
93
98
                catch ( NullPointerException npe )
94
99
                {
95
 
                    System.err.println("WARNING: no time attribute found on testsuite element");
 
100
                    System.err.println( "WARNING: no time attribute found on testsuite element" );
96
101
                }
97
102
 
98
103
                //check if group attribute is existing
116
121
                currentElement = new StringBuffer();
117
122
 
118
123
                testCase = new ReportTestCase();
119
 
                
 
124
 
120
125
                testCase.setName( attributes.getValue( "name" ) );
121
 
                
 
126
 
122
127
                String fullClassName = attributes.getValue( "classname" );
123
 
                
 
128
 
124
129
                // if the testcase declares its own classname, it may need to belong to its own suite
125
130
                if ( fullClassName != null )
126
131
                {
132
137
                        classesToSuites.put( fullClassName, currentSuite );
133
138
                    }
134
139
                }
135
 
                
 
140
 
136
141
                testCase.setFullClassName( currentSuite.getFullClassName() );
137
142
                testCase.setClassName( currentSuite.getName() );
138
143
                testCase.setFullName( currentSuite.getFullClassName() + "." + testCase.getName() );
148
153
 
149
154
                testCase.setTime( time.floatValue() );
150
155
 
151
 
                if ( currentSuite != defaultSuite ) {
 
156
                if ( currentSuite != defaultSuite )
 
157
                {
152
158
                    currentSuite.setTimeElapsed( time.floatValue() + currentSuite.getTimeElapsed() );
153
159
                }
154
160
            }
174
180
        }
175
181
    }
176
182
 
177
 
 
 
183
    /** {@inheritDoc} */
178
184
    public void endElement( String uri, String localName, String qName )
179
185
        throws SAXException
180
186
    {
196
202
        }
197
203
        else if ( "time".equals( qName ) )
198
204
        {
199
 
            try {
 
205
            try
 
206
            {
200
207
                Number time = numberFormat.parse( currentElement.toString() );
201
208
                defaultSuite.setTimeElapsed( time.floatValue() );
202
209
            }
208
215
        // TODO extract real skipped reasons
209
216
    }
210
217
 
 
218
    /** {@inheritDoc} */
211
219
    public void characters( char[] ch, int start, int length )
212
220
        throws SAXException
213
221
    {