~ubuntu-branches/ubuntu/trusty/ivy/trusty

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/util/AbstractMessageLogger.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-06 22:04:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090306220456-5v37luqiuqda8ewp
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 *  contributor license agreements.  See the NOTICE file distributed with
 
4
 *  this work for additional information regarding copyright ownership.
 
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 *  (the "License"); you may not use this file except in compliance with
 
7
 *  the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 *
 
17
 */
 
18
package org.apache.ivy.util;
 
19
 
 
20
import java.util.ArrayList;
 
21
import java.util.List;
 
22
 
 
23
/**
 
24
 * An abstract base class to ease {@link MessageLogger} implementation.
 
25
 */
 
26
public abstract class AbstractMessageLogger implements MessageLogger {
 
27
    private List problems = new ArrayList();
 
28
 
 
29
    private List warns = new ArrayList();
 
30
 
 
31
    private List errors = new ArrayList();
 
32
 
 
33
    private boolean showProgress = true;
 
34
    
 
35
    /* (non-Javadoc)
 
36
     * @see org.apache.ivy.util.MessageLogger#debug(java.lang.String)
 
37
     */
 
38
    public void debug(String msg) {
 
39
        log(msg, Message.MSG_DEBUG);
 
40
    }
 
41
 
 
42
    /* (non-Javadoc)
 
43
     * @see org.apache.ivy.util.MessageLogger#verbose(java.lang.String)
 
44
     */
 
45
    public void verbose(String msg) {
 
46
        log(msg, Message.MSG_VERBOSE);
 
47
    }
 
48
    
 
49
    /* (non-Javadoc)
 
50
     * @see org.apache.ivy.util.MessageLogger#deprecated(java.lang.String)
 
51
     */
 
52
    public void deprecated(String msg) {
 
53
        log("DEPRECATED: " + msg, Message.MSG_WARN);
 
54
    }
 
55
 
 
56
 
 
57
    /* (non-Javadoc)
 
58
     * @see org.apache.ivy.util.MessageLogger#info(java.lang.String)
 
59
     */
 
60
    public void info(String msg) {
 
61
        log(msg, Message.MSG_INFO);
 
62
    }
 
63
    
 
64
    /* (non-Javadoc)
 
65
     * @see org.apache.ivy.util.MessageLogger#info(java.lang.String)
 
66
     */
 
67
    public void rawinfo(String msg) {
 
68
        rawlog(msg, Message.MSG_INFO);
 
69
    }
 
70
 
 
71
    /* (non-Javadoc)
 
72
     * @see org.apache.ivy.util.MessageLogger#warn(java.lang.String)
 
73
     */
 
74
    public void warn(String msg) {
 
75
        log("WARN: " + msg, Message.MSG_VERBOSE);
 
76
        problems.add("WARN:  " + msg);
 
77
        getWarns().add(msg);
 
78
    }
 
79
 
 
80
    /* (non-Javadoc)
 
81
     * @see org.apache.ivy.util.MessageLogger#error(java.lang.String)
 
82
     */
 
83
    public void error(String msg) {
 
84
        // log in verbose mode because message is appended as a problem, and will be
 
85
        // logged at the end at error level
 
86
        log("ERROR: " + msg, Message.MSG_VERBOSE);
 
87
        problems.add("\tERROR: " + msg);
 
88
        getErrors().add(msg);
 
89
    }
 
90
 
 
91
    /* (non-Javadoc)
 
92
     * @see org.apache.ivy.util.MessageLogger#getProblems()
 
93
     */
 
94
    public List getProblems() {
 
95
        return problems;
 
96
    }
 
97
 
 
98
    /* (non-Javadoc)
 
99
     * @see org.apache.ivy.util.MessageLogger#sumupProblems()
 
100
     */
 
101
    public void sumupProblems() {
 
102
        MessageLoggerHelper.sumupProblems(this);
 
103
        clearProblems();
 
104
    }
 
105
 
 
106
    public void clearProblems() {
 
107
        problems.clear();
 
108
        warns.clear();
 
109
        errors.clear();
 
110
    }
 
111
 
 
112
    public List getErrors() {
 
113
        return errors;
 
114
    }
 
115
 
 
116
    public List getWarns() {
 
117
        return warns;
 
118
    }
 
119
 
 
120
    /* (non-Javadoc)
 
121
     * @see org.apache.ivy.util.MessageLogger#progress()
 
122
     */
 
123
    public void progress() {
 
124
        if (showProgress) {
 
125
            doProgress();
 
126
        }
 
127
    }
 
128
 
 
129
 
 
130
    /* (non-Javadoc)
 
131
     * @see org.apache.ivy.util.MessageLogger#endProgress()
 
132
     */
 
133
    public void endProgress() {
 
134
        endProgress("");
 
135
    }
 
136
 
 
137
    /* (non-Javadoc)
 
138
     * @see org.apache.ivy.util.MessageLogger#endProgress(java.lang.String)
 
139
     */
 
140
    public void endProgress(String msg) {
 
141
        if (showProgress) {
 
142
            doEndProgress(msg);
 
143
        }
 
144
    }
 
145
 
 
146
 
 
147
    /* (non-Javadoc)
 
148
     * @see org.apache.ivy.util.MessageLogger#isShowProgress()
 
149
     */
 
150
    public boolean isShowProgress() {
 
151
        return showProgress;
 
152
    }
 
153
 
 
154
    /* (non-Javadoc)
 
155
     * @see org.apache.ivy.util.MessageLogger#setShowProgress(boolean)
 
156
     */
 
157
    public void setShowProgress(boolean progress) {
 
158
        showProgress = progress;
 
159
    }
 
160
 
 
161
    /**
 
162
     * Indicates a progression for a long running task
 
163
     */
 
164
    protected abstract void doProgress();
 
165
    /**
 
166
     * Indicates the end of a long running task
 
167
     * @param msg the message associated with long running task end.
 
168
     */
 
169
    protected abstract void doEndProgress(String msg);
 
170
 
 
171
}