001package org.apache.maven.scm.provider.cvslib.cvsjava.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.netbeans.lib.cvsclient.event.CVSAdapter;
023import org.netbeans.lib.cvsclient.event.MessageEvent;
024
025/**
026 * A basic implementation of a CVS listener. It merely saves up
027 * into StringBuilders the stdout and stderr printstreams.
028 *
029 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
030 *
031 */
032public class CvsLogListener
033    extends CVSAdapter
034{
035    private final StringBuffer taggedLine = new StringBuffer();
036
037    private StringBuffer stdout = new StringBuffer();
038
039    private StringBuffer stderr = new StringBuffer();
040
041    /**
042     * Called when the server wants to send a message to be displayed to the
043     * user. The message is only for information purposes and clients can
044     * choose to ignore these messages if they wish.
045     *
046     * {@inheritDoc}
047     */
048    public void messageSent( MessageEvent e )
049    {
050        String line = e.getMessage();
051        StringBuffer stream = e.isError() ? stderr : stdout;
052
053        if ( e.isTagged() )
054        {
055            String message = MessageEvent.parseTaggedMessage( taggedLine, e.getMessage() );
056            if ( message != null )
057            {
058                //stream.println(message);
059                stream.append( message ).append( "\n" );
060
061            }
062        }
063        else
064        {
065            //stream.println(line);
066            stream.append( line ).append( "\n" );
067
068        }
069    }
070
071    /**
072     * @return Returns the standard output from cvs as a StringBuilder..
073     */
074    public StringBuffer getStdout()
075    {
076        return stdout;
077    }
078
079    /**
080     * @return Returns the standard error from cvs as a StringBuilder..
081     */
082    public StringBuffer getStderr()
083    {
084        return stderr;
085    }
086}