View Javadoc

1   package org.apache.maven.surefire.booter;
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.ForkingConsoleReporter;
23  import org.codehaus.plexus.util.cli.StreamConsumer;
24  
25  import java.io.PrintWriter;
26  import java.io.Writer;
27  
28  /**
29   * @author Jason van Zyl
30   * @version $Revision: 682222 $
31   * @deprecated use {@link org.apache.maven.surefire.booter.output.ForkingStreamConsumer}
32   */
33  public class ForkingWriterStreamConsumer
34      implements StreamConsumer
35  {
36      private PrintWriter printWriter;
37  
38      private int standardPrefixLength;
39  
40      private int headingPrefixLength;
41  
42      private boolean showHeading;
43  
44      private int footerPrefixLength;
45  
46      private boolean showFooter;
47  
48      public ForkingWriterStreamConsumer( Writer writer, boolean showHeading, boolean showFooter )
49      {
50          this.showHeading = showHeading;
51  
52          this.showFooter = showFooter;
53  
54          printWriter = new PrintWriter( writer );
55  
56          standardPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_STANDARD.length();
57  
58          headingPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_HEADING.length();
59  
60          footerPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_FOOTER.length();
61      }
62  
63      public void consumeLine( String line )
64      {
65          if ( line.startsWith( ForkingConsoleReporter.FORKING_PREFIX_HEADING ) )
66          {
67              if ( showHeading )
68              {
69                  printWriter.println( line.substring( headingPrefixLength ) );
70              }
71          }
72          else if ( line.startsWith( ForkingConsoleReporter.FORKING_PREFIX_STANDARD ) )
73          {
74              printWriter.println( line.substring( standardPrefixLength ) );
75          }
76          else if ( line.startsWith( ForkingConsoleReporter.FORKING_PREFIX_FOOTER ) )
77          {
78              if ( showFooter )
79              {
80                  printWriter.println( line.substring( footerPrefixLength ) );
81              }
82          }
83          else
84          {
85              // stdout
86              printWriter.println( line );
87          }
88          printWriter.flush();
89      }
90  }