@@ -103,10 +103,10 @@ public void writeXmlReport(String pathToReport) throws Exception {
103
103
104
104
try (DocResource docResource = new DocResource (pathToReport )) {
105
105
Document doc = docResource .getDocument ();
106
- String testCount = getTotalOfElementsByName (doc , "testcase" ).toString ();
107
- modifyElementAttribute (doc , "testsuites" , 0 , "tests" , testCount );
108
- String failureCount = getTotalOfElementsByName (doc , "failure" ).toString ();
109
- modifyElementAttribute (doc , "testsuites" , 0 , "failures" , failureCount );
106
+ String testCount = getTotalOfElementsByName (doc , "testcase" ).toString ();
107
+ modifyElementAttribute (doc , "testsuites" , 0 , "tests" , testCount );
108
+ String failureCount = getTotalOfElementsByName (doc , "failure" ).toString ();
109
+ modifyElementAttribute (doc , "testsuites" , 0 , "failures" , failureCount );
110
110
}
111
111
}
112
112
@@ -147,21 +147,24 @@ private void modifyElementAttribute(Document doc, String tagName, Integer index,
147
147
*
148
148
* Every document edit is performed by:
149
149
*
150
- * 1. Locking the file
151
- * 2. Creating/Loading the document
152
- * 3. Performing the document changes
153
- * 4. Writing the file
154
- * 5. Unlocking the file
150
+ * 1. Locking the file
151
+ * 2. Creating/Loading the document
152
+ * 3. Performing the document changes
153
+ * 4. Writing the file
154
+ * 5. Unlocking the file
155
155
*
156
156
* This is done to ensure that parallel builds can all work on the same report file.
157
157
*/
158
- class DocResource implements AutoCloseable
158
+ class DocResource
159
+ implements AutoCloseable
159
160
{
160
161
161
162
private String path ;
162
163
163
164
private Document doc ;
164
165
166
+ private FileLock fileLock ;
167
+
165
168
public DocResource (final String path ) {
166
169
File f = new File (path );
167
170
this .path = f .getAbsolutePath ();
@@ -170,14 +173,13 @@ public DocResource(final String path) {
170
173
RandomAccessFile randomAccessFile = new RandomAccessFile (path , "rw" );
171
174
FileChannel fc = randomAccessFile .getChannel ();
172
175
173
- try (FileLock fileLock = fc .lock ()) {
174
- if (fc .size () == 0 ) {
175
- // If this is a new file, then initialize it.
176
- doc = createDocument ();
177
- }
178
- else {
179
- doc = loadDocument ();
180
- }
176
+ fileLock = fc .lock ();
177
+ if (fc .size () == 0 ) {
178
+ // If this is a new file, then initialize it.
179
+ doc = createDocument ();
180
+ }
181
+ else {
182
+ doc = loadDocument ();
181
183
}
182
184
}
183
185
catch (IOException e ) {
@@ -193,6 +195,7 @@ public Document getDocument() {
193
195
@ Override
194
196
public void close () throws IOException {
195
197
writeDocument (doc );
198
+ fileLock .close ();
196
199
}
197
200
198
201
/**
0 commit comments