提交 047233eb 编写于 作者: K Kohsuke Kawaguchi

Don't do memory mapped file unless it's helpful.

This will hopefully reduce the file locking problems on Windows.
上级 59f0f32f
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册