1 /*
2 The MIT License
3
4 Copyright (c) 2004, The Codehaus
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of
7 this software and associated documentation files (the "Software"), to deal in
8 the Software without restriction, including without limitation the rights to
9 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 of the Software, and to permit persons to whom the Software is furnished to do
11 so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 package org.codehaus.mojo.scmchangelog;
25
26 import java.io.StringWriter;
27
28 import org.apache.maven.scm.log.ScmLogger;
29 import org.codehaus.plexus.util.cli.StreamConsumer;
30
31 /**
32 * Abstract consumer for the return stream from the svn commands.
33 * @author ehsavoie
34 * @version $Id: AbstractBufferedConsumer.java 7623 2008-09-09 08:46:14Z ehsavoie $
35 */
36 public abstract class AbstractBufferedConsumer
37 implements StreamConsumer
38 {
39
40 /**
41 * A buffer of the output.
42 */
43 private StringWriter buffer = new StringWriter();
44 /**
45 * The logger.
46 */
47 private ScmLogger logger;
48
49 /**
50 * @return a logger
51 * @see org.apache.maven.scm.command.Command#getLogger()
52 */
53 public final ScmLogger getLogger()
54 {
55 return logger;
56 }
57
58 /**
59 * Setter for the logger.
60 * @param scmLogger the logger.
61 * @see org.apache.maven.scm.command.Command#setLogger(org.apache.maven.scm.log.ScmLogger)
62 */
63 public final void setLogger( ScmLogger scmLogger )
64 {
65 this.logger = scmLogger;
66 }
67
68 // ----------------------------------------------------------------------
69 // StreamConsumer Implementation
70 // ----------------------------------------------------------------------
71 /**
72 * Consume the output of a process and store it in a buffer.
73 * @param line the line to be consumed and stored in the buffer.
74 */
75 public void consumeLine( String line )
76 {
77 this.buffer.write( line );
78 }
79
80 /**
81 * Returns the output.
82 * @return the output.
83 */
84 protected String getOutput()
85 {
86 return this.buffer.toString();
87 }
88
89 /**
90 * Parses the output of the command and returns a list of elements.
91 * @return a list of elements.
92 */
93 public abstract java.util.List analyse();
94 }