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.plugin.surefire.report.DefaultReporterFactory;
23 import org.apache.maven.surefire.util.internal.DumpFileUtils;
24
25 import java.io.File;
26
27 import static java.lang.String.format;
28 import static org.apache.maven.plugin.surefire.SurefireHelper.DUMPSTREAM_FILENAME_FORMATTER;
29 import static org.apache.maven.surefire.booter.DumpErrorSingleton.DUMPSTREAM_FILE_EXT;
30
31
32
33
34
35 public final class InPluginProcessDumpSingleton
36 {
37 private static final InPluginProcessDumpSingleton SINGLETON = new InPluginProcessDumpSingleton();
38
39 private final String creationDate = DumpFileUtils.newFormattedDateFileName();
40
41 private InPluginProcessDumpSingleton()
42 {
43 }
44
45 public static InPluginProcessDumpSingleton getSingleton()
46 {
47 return SINGLETON;
48 }
49
50 public synchronized File dumpException( Throwable t, String msg, DefaultReporterFactory defaultReporterFactory,
51 int jvmRun )
52 {
53 File dump = newDumpFile( defaultReporterFactory, jvmRun );
54 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, dump );
55 return dump;
56 }
57
58 public synchronized void dumpException( Throwable t, String msg, DefaultReporterFactory defaultReporterFactory )
59 {
60 DumpFileUtils.dumpException( t, msg == null ? "null" : msg, newDumpFile( defaultReporterFactory ) );
61 }
62
63 public synchronized void dumpException( Throwable t, DefaultReporterFactory defaultReporterFactory )
64 {
65 DumpFileUtils.dumpException( t, newDumpFile( defaultReporterFactory ) );
66 }
67
68 public synchronized File dumpText( String msg, DefaultReporterFactory defaultReporterFactory, int jvmRun )
69 {
70 File dump = newDumpFile( defaultReporterFactory, jvmRun );
71 DumpFileUtils.dumpText( msg == null ? "null" : msg, dump );
72 return dump;
73 }
74
75 public synchronized void dumpText( String msg, DefaultReporterFactory defaultReporterFactory )
76 {
77 DumpFileUtils.dumpText( msg == null ? "null" : msg, newDumpFile( defaultReporterFactory ) );
78 }
79
80 private File newDumpFile( DefaultReporterFactory defaultReporterFactory )
81 {
82 File reportsDirectory = defaultReporterFactory.getReportsDirectory();
83 return new File( reportsDirectory, creationDate + DUMPSTREAM_FILE_EXT );
84 }
85
86 private static File newDumpFile( DefaultReporterFactory defaultReporterFactory, int jvmRun )
87 {
88 File reportsDirectory = defaultReporterFactory.getReportsDirectory();
89 return new File( reportsDirectory, format( DUMPSTREAM_FILENAME_FORMATTER, jvmRun ) );
90 }
91 }