Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit 5e2e3db

Browse files
committed
Lock was not right
1 parent 2cd5a07 commit 5e2e3db

File tree

2 files changed

+21
-53
lines changed

2 files changed

+21
-53
lines changed

src/main/java/net/ossindex/gradle/output/JunitXmlReportWriter.java

+21-18
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public void writeXmlReport(String pathToReport) throws Exception {
103103

104104
try (DocResource docResource = new DocResource(pathToReport)) {
105105
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);
110110
}
111111
}
112112

@@ -147,21 +147,24 @@ private void modifyElementAttribute(Document doc, String tagName, Integer index,
147147
*
148148
* Every document edit is performed by:
149149
*
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
155155
*
156156
* This is done to ensure that parallel builds can all work on the same report file.
157157
*/
158-
class DocResource implements AutoCloseable
158+
class DocResource
159+
implements AutoCloseable
159160
{
160161

161162
private String path;
162163

163164
private Document doc;
164165

166+
private FileLock fileLock;
167+
165168
public DocResource(final String path) {
166169
File f = new File(path);
167170
this.path = f.getAbsolutePath();
@@ -170,14 +173,13 @@ public DocResource(final String path) {
170173
RandomAccessFile randomAccessFile = new RandomAccessFile(path, "rw");
171174
FileChannel fc = randomAccessFile.getChannel();
172175

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();
181183
}
182184
}
183185
catch (IOException e) {
@@ -193,6 +195,7 @@ public Document getDocument() {
193195
@Override
194196
public void close() throws IOException {
195197
writeDocument(doc);
198+
fileLock.close();
196199
}
197200

198201
/**

src/test/java/net/ossindex/common/OssiPackagePurlTest.java

-35
This file was deleted.

0 commit comments

Comments
 (0)