diff --git a/core/src/main/java/hudson/tasks/junit/SuiteResult.java b/core/src/main/java/hudson/tasks/junit/SuiteResult.java index 0b484cec9fafaea92d8784ff295dd5c83ccaa3ed..ed5965789a2a3ae42188c38f113c8fbf7074831a 100644 --- a/core/src/main/java/hudson/tasks/junit/SuiteResult.java +++ b/core/src/main/java/hudson/tasks/junit/SuiteResult.java @@ -26,6 +26,7 @@ package hudson.tasks.junit; import hudson.tasks.test.TestObject; import hudson.util.IOException2; import hudson.util.io.ParserConfigurator; +import org.apache.commons.io.FileUtils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; @@ -209,14 +210,22 @@ public final class SuiteResult implements Serializable { File mavenOutputFile = new File(xmlReport.getParentFile(),m.group(1)+"-output.txt"); if (mavenOutputFile.exists()) { try { - RandomAccessFile raf = new RandomAccessFile(mavenOutputFile, "r"); - try { - ByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, mavenOutputFile.length()); - CharBuffer cb = Charset.defaultCharset().decode(bb); - stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, cb); - } finally { - raf.close(); + CharSequence out; + long sz = mavenOutputFile.length(); + if (sz<64*1024) { + out = FileUtils.readFileToString(mavenOutputFile); + } else { + // memory mapped files have unpredictable release timing, which blocks file deletion on Windows. + // so don't do this unless there's a clear saving + RandomAccessFile raf = new RandomAccessFile(mavenOutputFile, "r"); + try { + ByteBuffer bb = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, sz); + out = Charset.defaultCharset().decode(bb); + } finally { + raf.close(); + } } + stdout = CaseResult.possiblyTrimStdio(cases, keepLongStdio, out); } catch (IOException e) { throw new IOException2("Failed to read "+mavenOutputFile,e); }