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