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