1
package org.apache.maven.surefire.report;
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
22
import java.io.BufferedWriter;
24
import java.io.FileWriter;
25
import java.io.IOException;
26
import java.io.PrintWriter;
28
import org.apache.maven.surefire.util.NestedRuntimeException;
31
* Surefire output consumer proxy that writes test output to a {@link java.io.File} for each test suite.
33
* This class is not threadsafe, but can be encapsulated with a SynchronizedOutputConsumer. It may still be
34
* accessed from different threads (serially).
36
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
37
* @version $Id: ConsoleOutputFileReporter.java 1143207 2011-07-05 21:37:57Z pgier $
40
public class ConsoleOutputFileReporter
43
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
45
private final File reportsDirectory;
47
private PrintWriter printWriter = null;
49
private String reportEntryName;
51
private ReportEntry report;
53
private final String reportNameSuffix;
55
public ConsoleOutputFileReporter( File reportsDirectory )
57
this( reportsDirectory, null );
60
public ConsoleOutputFileReporter( File reportsDirectory, String reportNameSuffix )
62
this.reportsDirectory = reportsDirectory;
63
this.reportNameSuffix = reportNameSuffix;
66
public void testSetStarting( ReportEntry reportEntry )
68
this.reportEntryName = reportEntry.getName();
71
public void testSetCompleted( ReportEntry report )
72
throws ReporterException
74
if ( printWriter != null )
81
public void writeMessage( byte[] b, int off, int len )
85
if ( printWriter == null )
87
if ( !reportsDirectory.exists() )
89
//noinspection ResultOfMethodCallIgnored
90
reportsDirectory.mkdirs();
92
File file = AbstractFileReporter.getReportFile( reportsDirectory, reportEntryName, reportNameSuffix, "-output.txt" );
93
printWriter = new PrintWriter( new BufferedWriter( new FileWriter( file ) ) );
95
printWriter.write( new String( b, off, len ) );
96
printWriter.write( LINE_SEPARATOR );
99
catch ( IOException e )
101
throw new NestedRuntimeException( e );
106
public void testStarting( ReportEntry report )
110
public void testSucceeded( ReportEntry report )
114
public void testSkipped( ReportEntry report )
118
public void testError( ReportEntry report, String stdOut, String stdErr )
122
public void testFailed( ReportEntry report, String stdOut, String stdErr )
126
public void writeMessage( String message )