1 | |
package org.apache.maven.plugin.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 | |
import org.apache.maven.surefire.report.ReportEntry; |
28 | |
import org.apache.maven.surefire.report.ReporterException; |
29 | |
import org.apache.maven.surefire.util.NestedRuntimeException; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class ConsoleOutputFileReporter |
40 | |
implements TestcycleConsoleOutputReceiver |
41 | |
{ |
42 | |
private final File reportsDirectory; |
43 | |
|
44 | |
private final String reportNameSuffix; |
45 | |
|
46 | 2 | private PrintWriter printWriter = null; |
47 | |
|
48 | |
private String reportEntryName; |
49 | |
|
50 | |
public ConsoleOutputFileReporter( File reportsDirectory, String reportNameSuffix ) |
51 | 2 | { |
52 | 2 | this.reportsDirectory = reportsDirectory; |
53 | 2 | this.reportNameSuffix = reportNameSuffix; |
54 | 2 | } |
55 | |
|
56 | |
public void testSetStarting( ReportEntry reportEntry ) |
57 | |
{ |
58 | 2 | close(); |
59 | 2 | this.reportEntryName = reportEntry.getName(); |
60 | 2 | } |
61 | |
|
62 | |
public void testSetCompleted( ReportEntry report ) |
63 | |
throws ReporterException |
64 | |
{ |
65 | 2 | } |
66 | |
|
67 | |
public void close() |
68 | |
{ |
69 | 2 | if ( printWriter != null ) |
70 | |
{ |
71 | 0 | printWriter.close(); |
72 | 0 | printWriter = null; |
73 | |
} |
74 | 2 | } |
75 | |
|
76 | |
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) |
77 | |
{ |
78 | |
try |
79 | |
{ |
80 | 2 | if ( printWriter == null ) |
81 | |
{ |
82 | 2 | if ( !reportsDirectory.exists() ) |
83 | |
{ |
84 | |
|
85 | 0 | reportsDirectory.mkdirs(); |
86 | |
} |
87 | 2 | File file = |
88 | |
FileReporter.getReportFile( reportsDirectory, reportEntryName, reportNameSuffix, "-output.txt" ); |
89 | 2 | printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) ); |
90 | |
} |
91 | 2 | printWriter.write( new String( buf, off, len ) ); |
92 | |
} |
93 | 0 | catch ( IOException e ) |
94 | |
{ |
95 | 0 | throw new NestedRuntimeException( e ); |
96 | 2 | } |
97 | 2 | } |
98 | |
} |