View Javadoc

1   package org.apache.maven.surefire.booter.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 510866 2007-02-23 08:13:49Z brett $
32   * @since 2.1
33   */
34  public class PrintWriterOutputConsumer
35      implements OutputConsumer
36  {
37  
38      private PrintWriter printWriter;
39  
40      /**
41       * Create a consumer uninitialized, {@link #setPrintWriter(PrintWriter)} must be called before using it
42       */
43      public PrintWriterOutputConsumer()
44      {
45      }
46  
47      /**
48       * Create a consumer that will write to the specified {@link Writer}
49       *
50       * @param writer where to write to
51       */
52      public PrintWriterOutputConsumer( Writer writer )
53      {
54          this.setPrintWriter( new PrintWriter( writer ) );
55      }
56  
57      /**
58       * Set the {@link PrintWriter} used by this object
59       *
60       * @param writer
61       */
62      public void setPrintWriter( PrintWriter writer )
63      {
64          this.printWriter = writer;
65      }
66  
67      /**
68       * Get the {@link PrintWriter} used by this object
69       */
70      public PrintWriter getPrintWriter()
71      {
72          return printWriter;
73      }
74  
75      public void consumeHeaderLine( String line )
76      {
77          write( line );
78      }
79  
80      public void consumeMessageLine( String line )
81      {
82          write( line );
83      }
84  
85      public void consumeFooterLine( String line )
86      {
87          write( line );
88      }
89  
90      public void consumeOutputLine( String line )
91      {
92          write( line );
93      }
94  
95      /**
96       * Do nothing
97       */
98      public void testSetStarting( ReportEntry reportEntry )
99      {
100         // do nothing
101     }
102 
103     /**
104      * Do nothing
105      */
106     public void testSetCompleted()
107     {
108         // do nothing
109     }
110 
111     /**
112      * Write a line and flush
113      *
114      * @param line
115      */
116     private void write( String line )
117     {
118         getPrintWriter().println( line );
119         getPrintWriter().flush();
120     }
121 
122 }