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