1 package org.apache.maven.plugin.surefire.booterclient.output; 2 3 /* 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 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 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 19 * under the License. 20 */ 21 22 import org.apache.maven.surefire.report.ReportEntry; 23 24 import java.io.PrintWriter; 25 import java.io.Writer; 26 27 /** 28 * Surefire output consumer that writes everything to a {@link Writer} 29 * 30 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> 31 * @version $Id: PrintWriterOutputConsumer.java 1039320 2010-11-26 11:48:24Z krosenvold $ 32 * @since 2.1 33 */ 34 public class PrintWriterOutputConsumer 35 implements OutputConsumer 36 { 37 38 private final PrintWriter printWriter; 39 40 /** 41 * Create a consumer that will write to the specified {@link Writer} 42 * 43 * @param writer where to write to 44 */ 45 public PrintWriterOutputConsumer( Writer writer ) 46 { 47 this( new PrintWriter( writer ) ); 48 } 49 50 /** 51 * Create a consumer that will write to the specified {@link Writer} 52 * 53 * @param writer where to write to 54 */ 55 public PrintWriterOutputConsumer( PrintWriter writer ) 56 { 57 this.printWriter = writer; 58 } 59 60 /** 61 * Get the {@link PrintWriter} used by this object 62 * 63 * @return the printWriter 64 */ 65 public PrintWriter getPrintWriter() 66 { 67 return printWriter; 68 } 69 70 public void consumeHeaderLine( String line ) 71 { 72 write( line ); 73 } 74 75 public void consumeMessageLine( String line ) 76 { 77 write( line ); 78 } 79 80 public void consumeFooterLine( String line ) 81 { 82 write( line ); 83 } 84 85 public void consumeOutputLine( String line ) 86 { 87 write( line ); 88 } 89 90 /** 91 * Do nothing 92 */ 93 public void testSetStarting( ReportEntry reportEntry ) 94 { 95 // do nothing 96 } 97 98 /** 99 * Do nothing 100 */ 101 public void testSetCompleted() 102 { 103 // do nothing 104 } 105 106 /** 107 * Write a line and flush 108 * 109 * @param line the content to write 110 */ 111 private void write( String line ) 112 { 113 getPrintWriter().println( line ); 114 getPrintWriter().flush(); 115 } 116 117 }