1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.booterclient.output;
20
21 import java.io.File;
22
23 import org.apache.maven.surefire.api.util.internal.DumpFileUtils;
24
25 import static java.lang.String.format;
26 import static org.apache.maven.plugin.surefire.SurefireHelper.DUMPSTREAM_FILENAME;
27 import static org.apache.maven.plugin.surefire.SurefireHelper.DUMPSTREAM_FILENAME_FORMATTER;
28 import static org.apache.maven.plugin.surefire.SurefireHelper.DUMP_FILENAME;
29 import static org.apache.maven.plugin.surefire.SurefireHelper.DUMP_FILENAME_FORMATTER;
30 import static org.apache.maven.plugin.surefire.SurefireHelper.EVENTS_BINARY_DUMP_FILENAME_FORMATTER;
31
32
33
34
35
36 public final class InPluginProcessDumpSingleton {
37 private static final InPluginProcessDumpSingleton SINGLETON = new InPluginProcessDumpSingleton();
38
39 private InPluginProcessDumpSingleton() {}
40
41 public static InPluginProcessDumpSingleton getSingleton() {
42 return SINGLETON;
43 }
44
45 public synchronized File dumpStreamException(Throwable t, String msg, File reportsDirectory, int jvmRun) {
46 File dump = newDumpStreamFile(reportsDirectory, jvmRun);
47 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, dump);
48 return dump;
49 }
50
51 public synchronized void dumpStreamException(Throwable t, String msg, File reportsDirectory) {
52 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, newDumpStreamFile(reportsDirectory));
53 }
54
55 public synchronized File dumpStreamText(String msg, File reportsDirectory, int jvmRun) {
56 File dump = newDumpStreamFile(reportsDirectory, jvmRun);
57 DumpFileUtils.dumpText(msg == null ? "null" : msg, dump);
58 return dump;
59 }
60
61 public synchronized void dumpStreamText(String msg, File reportsDirectory) {
62 DumpFileUtils.dumpText(msg == null ? "null" : msg, newDumpStreamFile(reportsDirectory));
63 }
64
65 public synchronized void dumpException(Throwable t, String msg, File reportsDirectory, int jvmRun) {
66 File dump = newDumpFile(reportsDirectory, jvmRun);
67 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, dump);
68 }
69
70 public synchronized void dumpException(Throwable t, String msg, File reportsDirectory) {
71 File dump = newDumpFile(reportsDirectory);
72 DumpFileUtils.dumpException(t, msg == null ? "null" : msg, dump);
73 }
74
75 public File getEventStreamBinaryFile(File reportsDirectory, int jvmRun) {
76 reportsDirectory.mkdirs();
77 return new File(reportsDirectory, format(EVENTS_BINARY_DUMP_FILENAME_FORMATTER, jvmRun));
78 }
79
80 private File newDumpStreamFile(File reportsDirectory) {
81 return new File(reportsDirectory, DUMPSTREAM_FILENAME);
82 }
83
84 private static File newDumpStreamFile(File reportsDirectory, int jvmRun) {
85 return new File(reportsDirectory, format(DUMPSTREAM_FILENAME_FORMATTER, jvmRun));
86 }
87
88 private static File newDumpFile(File reportsDirectory, int jvmRun) {
89 return new File(reportsDirectory, format(DUMP_FILENAME_FORMATTER, jvmRun));
90 }
91
92 private static File newDumpFile(File reportsDirectory) {
93 return new File(reportsDirectory, DUMP_FILENAME);
94 }
95 }