001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.util;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: /**
024: * An abstract base class to ease {@link MessageLogger} implementation.
025: */
026: public abstract class AbstractMessageLogger implements MessageLogger {
027: private List problems = new ArrayList();
028:
029: private List warns = new ArrayList();
030:
031: private List errors = new ArrayList();
032:
033: private boolean showProgress = true;
034:
035: /* (non-Javadoc)
036: * @see org.apache.ivy.util.MessageLogger#debug(java.lang.String)
037: */
038: public void debug(String msg) {
039: log(msg, Message.MSG_DEBUG);
040: }
041:
042: /* (non-Javadoc)
043: * @see org.apache.ivy.util.MessageLogger#verbose(java.lang.String)
044: */
045: public void verbose(String msg) {
046: log(msg, Message.MSG_VERBOSE);
047: }
048:
049: /* (non-Javadoc)
050: * @see org.apache.ivy.util.MessageLogger#deprecated(java.lang.String)
051: */
052: public void deprecated(String msg) {
053: log("DEPRECATED: " + msg, Message.MSG_WARN);
054: }
055:
056: /* (non-Javadoc)
057: * @see org.apache.ivy.util.MessageLogger#info(java.lang.String)
058: */
059: public void info(String msg) {
060: log(msg, Message.MSG_INFO);
061: }
062:
063: /* (non-Javadoc)
064: * @see org.apache.ivy.util.MessageLogger#info(java.lang.String)
065: */
066: public void rawinfo(String msg) {
067: rawlog(msg, Message.MSG_INFO);
068: }
069:
070: /* (non-Javadoc)
071: * @see org.apache.ivy.util.MessageLogger#warn(java.lang.String)
072: */
073: public void warn(String msg) {
074: log("WARN: " + msg, Message.MSG_VERBOSE);
075: problems.add("WARN: " + msg);
076: getWarns().add(msg);
077: }
078:
079: /* (non-Javadoc)
080: * @see org.apache.ivy.util.MessageLogger#error(java.lang.String)
081: */
082: public void error(String msg) {
083: // log in verbose mode because message is appended as a problem, and will be
084: // logged at the end at error level
085: log("ERROR: " + msg, Message.MSG_VERBOSE);
086: problems.add("\tERROR: " + msg);
087: getErrors().add(msg);
088: }
089:
090: /* (non-Javadoc)
091: * @see org.apache.ivy.util.MessageLogger#getProblems()
092: */
093: public List getProblems() {
094: return problems;
095: }
096:
097: /* (non-Javadoc)
098: * @see org.apache.ivy.util.MessageLogger#sumupProblems()
099: */
100: public void sumupProblems() {
101: MessageLoggerHelper.sumupProblems(this );
102: clearProblems();
103: }
104:
105: public void clearProblems() {
106: problems.clear();
107: warns.clear();
108: errors.clear();
109: }
110:
111: public List getErrors() {
112: return errors;
113: }
114:
115: public List getWarns() {
116: return warns;
117: }
118:
119: /* (non-Javadoc)
120: * @see org.apache.ivy.util.MessageLogger#progress()
121: */
122: public void progress() {
123: if (showProgress) {
124: doProgress();
125: }
126: }
127:
128: /* (non-Javadoc)
129: * @see org.apache.ivy.util.MessageLogger#endProgress()
130: */
131: public void endProgress() {
132: endProgress("");
133: }
134:
135: /* (non-Javadoc)
136: * @see org.apache.ivy.util.MessageLogger#endProgress(java.lang.String)
137: */
138: public void endProgress(String msg) {
139: if (showProgress) {
140: doEndProgress(msg);
141: }
142: }
143:
144: /* (non-Javadoc)
145: * @see org.apache.ivy.util.MessageLogger#isShowProgress()
146: */
147: public boolean isShowProgress() {
148: return showProgress;
149: }
150:
151: /* (non-Javadoc)
152: * @see org.apache.ivy.util.MessageLogger#setShowProgress(boolean)
153: */
154: public void setShowProgress(boolean progress) {
155: showProgress = progress;
156: }
157:
158: /**
159: * Indicates a progression for a long running task
160: */
161: protected abstract void doProgress();
162:
163: /**
164: * Indicates the end of a long running task
165: * @param msg the message associated with long running task end.
166: */
167: protected abstract void doEndProgress(String msg);
168:
169: }
|