1 | |
package org.apache.maven.surefire.report; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.BufferedWriter; |
23 | |
import java.io.File; |
24 | |
import java.io.FileWriter; |
25 | |
import java.io.IOException; |
26 | |
import java.io.PrintWriter; |
27 | |
|
28 | |
import org.apache.maven.surefire.util.NestedRuntimeException; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class ConsoleOutputFileReporter |
41 | |
implements Reporter |
42 | |
{ |
43 | |
private final File reportsDirectory; |
44 | |
|
45 | 0 | private PrintWriter printWriter = null; |
46 | |
|
47 | |
private String reportEntryName; |
48 | |
|
49 | |
private final String reportNameSuffix; |
50 | |
|
51 | |
public ConsoleOutputFileReporter( File reportsDirectory ) |
52 | |
{ |
53 | 0 | this( reportsDirectory, null ); |
54 | 0 | } |
55 | |
|
56 | |
public ConsoleOutputFileReporter( File reportsDirectory, String reportNameSuffix ) |
57 | 0 | { |
58 | 0 | this.reportsDirectory = reportsDirectory; |
59 | 0 | this.reportNameSuffix = reportNameSuffix; |
60 | 0 | } |
61 | |
|
62 | |
public void testSetStarting( ReportEntry reportEntry ) |
63 | |
{ |
64 | 0 | this.reportEntryName = reportEntry.getName(); |
65 | 0 | } |
66 | |
|
67 | |
public void testSetCompleted( ReportEntry report ) |
68 | |
throws ReporterException |
69 | |
{ |
70 | 0 | if ( printWriter != null ) |
71 | |
{ |
72 | 0 | printWriter.close(); |
73 | 0 | printWriter = null; |
74 | |
} |
75 | 0 | } |
76 | |
|
77 | |
public void writeMessage( byte[] b, int off, int len ) |
78 | |
{ |
79 | |
try |
80 | |
{ |
81 | 0 | if ( printWriter == null ) |
82 | |
{ |
83 | 0 | if ( !reportsDirectory.exists() ) |
84 | |
{ |
85 | |
|
86 | 0 | reportsDirectory.mkdirs(); |
87 | |
} |
88 | 0 | File file = AbstractFileReporter.getReportFile( reportsDirectory, reportEntryName, reportNameSuffix, "-output.txt" ); |
89 | 0 | printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) ); |
90 | |
} |
91 | 0 | printWriter.write( new String( b, off, len ) ); |
92 | |
} |
93 | 0 | catch ( IOException e ) |
94 | |
{ |
95 | 0 | throw new NestedRuntimeException( e ); |
96 | 0 | } |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
public void testStarting( ReportEntry report ) |
101 | |
{ |
102 | 0 | } |
103 | |
|
104 | |
public void testSucceeded( ReportEntry report ) |
105 | |
{ |
106 | 0 | } |
107 | |
|
108 | |
public void testSkipped( ReportEntry report ) |
109 | |
{ |
110 | 0 | } |
111 | |
|
112 | |
public void testError( ReportEntry report, String stdOut, String stdErr ) |
113 | |
{ |
114 | 0 | } |
115 | |
|
116 | |
public void testFailed( ReportEntry report, String stdOut, String stdErr ) |
117 | |
{ |
118 | 0 | } |
119 | |
|
120 | |
public void writeMessage( String message ) |
121 | |
{ |
122 | 0 | } |
123 | |
|
124 | |
public void reset() |
125 | |
{ |
126 | 0 | } |
127 | |
} |