1
/********************************************************************
2
* Copyright (c) 2007 Contributors. All rights reserved.
3
* This program and the accompanying materials are made available
4
* under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution and is available at
6
* http://eclipse.org/legal/epl-v10.html
8
* Contributors: IBM Corporation - initial API and implementation
9
* Helen Hawkins - initial version (bug 148190)
10
*******************************************************************/
11
package org.aspectj.ajde.ui.utils;
13
import java.util.ArrayList;
14
import java.util.List;
16
import org.aspectj.ajde.IUIBuildMessageHandler;
17
import org.aspectj.bridge.AbortException;
18
import org.aspectj.bridge.IMessage;
19
import org.aspectj.bridge.IMessage.Kind;
22
* Test implementation of IBuildMessageHandler. By default it
23
* ignores INFO and WEAVEINFO messages. Stores all messages it's
24
* not ignoring in an ArrayList and ERRORS and ABORTS also in
25
* a separate ArrayList enabling users to query whether anything
26
* went wrong with the build.
28
public class TestMessageHandler implements IUIBuildMessageHandler {
30
private List ignoring;
31
private List messages;
34
public TestMessageHandler() {
35
ignoring = new ArrayList();
36
messages = new ArrayList();
37
errors = new ArrayList();
38
ignore(IMessage.INFO);
39
ignore(IMessage.WEAVEINFO);
42
public boolean handleMessage(IMessage message) throws AbortException {
43
IMessage.Kind kind = message.getKind();
44
if (isIgnoring(kind)) {
47
TestMessage t = new TestMessage(message);
49
if (kind.equals(IMessage.ABORT) || message.getThrown() != null) {
50
System.err.println("> AjCompiler error: "+message.getMessage()); //$NON-NLS-1$
51
message.getThrown().printStackTrace();
53
} else if (kind.equals(IMessage.ERROR)) {
56
System.out.println("> "+message); //$NON-NLS-1$
60
public void dontIgnore(Kind kind) {
62
ignoring.remove(kind);
66
public boolean isIgnoring(Kind kind) {
67
return ((null != kind) && (ignoring.contains(kind)));
70
public void ignore(Kind kind) {
71
if ((null != kind) && (!ignoring.contains(kind))) {
76
public List getMessages() {
80
public List getErrors() {
84
public static class TestMessage {
87
public TestMessage(IMessage m) {
91
public IMessage getContainedMessage() {
95
public String toString() {
96
String loc = "<no location>";
97
if (null != message.getSourceLocation()) {
98
loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine();
100
return "TestMessage [" + message.getMessage()
102
+ ", " + message.getKind()
107
public void reset() {