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.api.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 import static org.apache.maven.plugin.surefire.SurefireHelper.EVENTS_BINARY_DUMP_FILENAME_FORMATTER;
32
33
34
35
36
37 public final class InPluginProcessDumpSingleton
38 {
39 private static final InPluginProcessDumpSingleton SINGLETON = new InPluginProcessDumpSingleton();
40
41 private InPluginProcessDumpSingleton()
42 {
43 }
44
45 public static InPluginProcessDumpSingleton getSingleton()
46 {
47 return SINGLETON;
48 }
49
50 public synchronized File dumpStreamException( Throwable t, String msg, File reportsDirectory, int jvmRun )
51 {
52 File dump = newDumpStreamFile( reportsDirectory, jvmRun );
53 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, dump );
54 return dump;
55 }
56
57 public synchronized void dumpStreamException( Throwable t, String msg, File reportsDirectory )
58 {
59 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, newDumpStreamFile( reportsDirectory ) );
60 }
61
62 public synchronized File dumpStreamText( String msg, File reportsDirectory, int jvmRun )
63 {
64 File dump = newDumpStreamFile( reportsDirectory, jvmRun );
65 DumpFileUtils.dumpText( msg == null ? "null" : msg, dump );
66 return dump;
67 }
68
69 public synchronized void dumpStreamText( String msg, File reportsDirectory )
70 {
71 DumpFileUtils.dumpText( msg == null ? "null" : msg, newDumpStreamFile( reportsDirectory ) );
72 }
73
74 public synchronized void dumpException( Throwable t, String msg, File reportsDirectory, int jvmRun )
75 {
76 File dump = newDumpFile( reportsDirectory, jvmRun );
77 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, dump );
78 }
79
80 public synchronized void dumpException( Throwable t, String msg, File reportsDirectory )
81 {
82 File dump = newDumpFile( reportsDirectory );
83 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, dump );
84 }
85
86 public File getEventStreamBinaryFile( File reportsDirectory, int jvmRun )
87 {
88 reportsDirectory.mkdirs();
89 return new File( reportsDirectory, format( EVENTS_BINARY_DUMP_FILENAME_FORMATTER, jvmRun ) );
90 }
91
92 private File newDumpStreamFile( File reportsDirectory )
93 {
94 return new File( reportsDirectory, DUMPSTREAM_FILENAME );
95 }
96
97 private static File newDumpStreamFile( File reportsDirectory, int jvmRun )
98 {
99 return new File( reportsDirectory, format( DUMPSTREAM_FILENAME_FORMATTER, jvmRun ) );
100 }
101
102 private static File newDumpFile( File reportsDirectory, int jvmRun )
103 {
104 return new File( reportsDirectory, format( DUMP_FILENAME_FORMATTER, jvmRun ) );
105 }
106
107 private static File newDumpFile( File reportsDirectory )
108 {
109 return new File( reportsDirectory, DUMP_FILENAME );
110 }
111 }