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 static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
44
45 private final File reportsDirectory;
46
47 private PrintWriter printWriter = null;
48
49 private String reportEntryName;
50
51 private ReportEntry report;
52
53 private final String reportNameSuffix;
54
55 public ConsoleOutputFileReporter( File reportsDirectory )
56 {
57 this( reportsDirectory, null );
58 }
59
60 public ConsoleOutputFileReporter( File reportsDirectory, String reportNameSuffix )
61 {
62 this.reportsDirectory = reportsDirectory;
63 this.reportNameSuffix = reportNameSuffix;
64 }
65
66 public void testSetStarting( ReportEntry reportEntry )
67 {
68 this.reportEntryName = reportEntry.getName();
69 }
70
71 public void testSetCompleted( ReportEntry report )
72 throws ReporterException
73 {
74 if ( printWriter != null )
75 {
76 printWriter.close();
77 printWriter = null;
78 }
79 }
80
81 public void writeMessage( byte[] b, int off, int len )
82 {
83 try
84 {
85 if ( printWriter == null )
86 {
87 if ( !reportsDirectory.exists() )
88 {
89
90 reportsDirectory.mkdirs();
91 }
92 File file = AbstractFileReporter.getReportFile( reportsDirectory, reportEntryName, reportNameSuffix, "-output.txt" );
93 printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) );
94 }
95 printWriter.write( new String( b, off, len ) );
96 printWriter.write( LINE_SEPARATOR );
97
98 }
99 catch ( IOException e )
100 {
101 throw new NestedRuntimeException( e );
102 }
103 }
104
105
106 public void testStarting( ReportEntry report )
107 {
108 }
109
110 public void testSucceeded( ReportEntry report )
111 {
112 }
113
114 public void testSkipped( ReportEntry report )
115 {
116 }
117
118 public void testError( ReportEntry report, String stdOut, String stdErr )
119 {
120 }
121
122 public void testFailed( ReportEntry report, String stdOut, String stdErr )
123 {
124 }
125
126 public void writeMessage( String message )
127 {
128 }
129
130
131 public void reset()
132 {
133 }
134 }