View Javadoc

1   package org.apache.maven.wagon.providers.ssh;
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.wagon.CommandExecutionException;
23  import org.apache.maven.wagon.Streams;
24  
25  import java.io.BufferedReader;
26  import java.io.IOException;
27  
28  /**
29   * CommandExecutorStreamProcessor 
30   *
31   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
32   * @version $Id: CommandExecutorStreamProcessor.java 682071 2008-08-02 22:21:46Z hboutemy $
33   */
34  public class CommandExecutorStreamProcessor
35  {
36      private CommandExecutorStreamProcessor()
37      {
38          // shoo!
39      }
40  
41      public static Streams processStreams( BufferedReader stderrReader, BufferedReader stdoutReader )
42          throws IOException, CommandExecutionException
43      {
44          Streams streams = new Streams();
45  
46          while ( true )
47          {
48              String line = stderrReader.readLine();
49  
50              if ( line == null )
51              {
52                  break;
53              }
54  
55              // TODO: I think we need to deal with exit codes instead, but IIRC there are some cases of errors that
56              // don't have exit codes ignore this error. TODO: output a warning
57              if ( !line.startsWith( "Could not chdir to home directory" )
58                   && !line.endsWith( "ttyname: Operation not supported" ) )
59              {
60                  streams.setErr( streams.getErr() + line + "\n" );
61              }
62          }
63  
64          while ( true )
65          {
66              String line = stdoutReader.readLine();
67  
68              if ( line == null )
69              {
70                  break;
71              }
72  
73              streams.setOut( streams.getOut() + line + "\n" );
74          }
75  
76          // drain the output stream.
77          // TODO: we'll save this for the 1.0-alpha-8 line, so we can test it more. the -q arg in the
78          // unzip command should keep us until then...
79  //            int avail = in.available();
80  //            byte[] trashcan = new byte[1024];
81  //
82  //            while( ( avail = in.available() ) > 0 )
83  //            {
84  //                in.read( trashcan, 0, avail );
85  //            }
86  
87          return streams;
88      }
89  }