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