1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.booter;
20
21 import java.io.File;
22
23 import org.apache.maven.surefire.api.util.internal.DumpFileUtils;
24
25 import static org.apache.maven.surefire.api.util.internal.DumpFileUtils.newDumpFile;
26
27
28
29
30
31
32
33
34 public final class DumpErrorSingleton {
35 public static final String DUMP_FILE_EXT = ".dump";
36 public static final String DUMPSTREAM_FILE_EXT = ".dumpstream";
37 private static final DumpErrorSingleton SINGLETON = new DumpErrorSingleton();
38
39 private File dumpFile;
40 private File dumpStreamFile;
41 private File binaryDumpStreamFile;
42
43 private DumpErrorSingleton() {}
44
45 public static DumpErrorSingleton getSingleton() {
46 return SINGLETON;
47 }
48
49 public synchronized void init(File reportsDir, String dumpFileName) {
50 dumpFile = createDumpFile(reportsDir, dumpFileName);
51 dumpStreamFile = createDumpStreamFile(reportsDir, dumpFileName);
52 String fileNameWithoutExtension =
53 dumpFileName.contains(".") ? dumpFileName.substring(0, dumpFileName.lastIndexOf('.')) : dumpFileName;
54 binaryDumpStreamFile = newDumpFile(reportsDir, fileNameWithoutExtension + "-commands.bin");
55 }
56
57 public synchronized File dumpException(Throwable t, String msg) {
58 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, dumpFile);
59 return dumpFile;
60 }
61
62 public synchronized File dumpException(Throwable t) {
63 DumpFileUtils.dumpException(t, dumpFile);
64 return dumpFile;
65 }
66
67 public synchronized File dumpText(String msg) {
68 DumpFileUtils.dumpText(msg == null ? "null" : msg, dumpFile);
69 return dumpFile;
70 }
71
72 public synchronized File dumpStreamException(Throwable t, String msg) {
73 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, dumpStreamFile);
74 return dumpStreamFile;
75 }
76
77 public synchronized File dumpStreamException(Throwable t) {
78 DumpFileUtils.dumpException(t, dumpStreamFile);
79 return dumpStreamFile;
80 }
81
82 public synchronized File dumpStreamText(String msg) {
83 DumpFileUtils.dumpText(msg == null ? "null" : msg, dumpStreamFile);
84 return dumpStreamFile;
85 }
86
87 public File getCommandStreamBinaryFile() {
88 return binaryDumpStreamFile;
89 }
90
91 private File createDumpFile(File reportsDir, String dumpFileName) {
92 return newDumpFile(reportsDir, dumpFileName + DUMP_FILE_EXT);
93 }
94
95 private File createDumpStreamFile(File reportsDir, String dumpFileName) {
96 return newDumpFile(reportsDir, dumpFileName + DUMPSTREAM_FILE_EXT);
97 }
98 }