View Javadoc

1   package org.apache.maven.cvslib;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.netbeans.lib.cvsclient.event.CVSAdapter;
22  import org.netbeans.lib.cvsclient.event.MessageEvent;
23  
24  
25  /**
26   * A basic implementation of a CVS listener. It merely saves up
27   * into StringBuffers the stdout and stderr printstreams.
28   *
29   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
30   */
31  public class CvsLogListener extends CVSAdapter
32  {
33      private final StringBuffer taggedLine = new StringBuffer();
34      private StringBuffer stdout = new StringBuffer();
35      private StringBuffer stderr = new StringBuffer();
36  
37      /**
38       * Called when the server wants to send a message to be displayed to the
39       * user. The message is only for information purposes and clients can
40       * choose to ignore these messages if they wish.
41       *
42       * @param e the event
43       */
44      public void messageSent( MessageEvent e )
45      {
46          String line = e.getMessage();
47          StringBuffer stream = e.isError() ? stderr : stdout;
48  
49          if ( e.isTagged() )
50          {
51              String message =
52                  MessageEvent.parseTaggedMessage( taggedLine, e.getMessage() );
53  
54              if ( message != null )
55              {
56                  //stream.println(message);
57                  stream.append( message + "\n" );
58              }
59          }
60          else
61          {
62              //stream.println(line);
63              stream.append( line + "\n" );
64          }
65      }
66  
67      /**
68       * @return Returns the standard output from cvs as a StringBuffer..
69       */
70      public StringBuffer getStdout()
71      {
72          return stdout;
73      }
74  }