~ubuntu-branches/ubuntu/utopic/aspectj/utopic

« back to all changes in this revision

Viewing changes to org.aspectj/modules/ajde/testsrc/org/aspectj/ajde/ui/utils/TestMessageHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch, Michael Koch, Thomas Girard, Mark Howard
  • Date: 2008-01-05 23:31:47 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080105233147-r425rd8nymruj6fk
Tags: 1.5.4-1
[ Michael Koch ]
* New upstream version. Closes: #459363
* Updated Standards-Version to 3.7.3.
* Added myself to Uploaders.

[ Thomas Girard ]
* Add Homepage: control field, and convert XS-Vcs-* to Vcs-*.

[ Mark Howard ]
* debian/watch: added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 
 
7
 *  
 
8
 * Contributors: IBM Corporation - initial API and implementation 
 
9
 *                               Helen Hawkins   - initial version (bug 148190)
 
10
 *******************************************************************/
 
11
package org.aspectj.ajde.ui.utils;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.List;
 
15
 
 
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;
 
20
 
 
21
/**
 
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.
 
27
 */
 
28
public class TestMessageHandler implements IUIBuildMessageHandler {
 
29
 
 
30
        private List ignoring;
 
31
        private List messages;
 
32
        private List errors;
 
33
        
 
34
        public TestMessageHandler() {
 
35
                ignoring = new ArrayList();
 
36
                messages = new ArrayList();
 
37
                errors = new ArrayList();
 
38
        ignore(IMessage.INFO);
 
39
        ignore(IMessage.WEAVEINFO);
 
40
        }
 
41
 
 
42
        public boolean handleMessage(IMessage message) throws AbortException {
 
43
        IMessage.Kind kind = message.getKind(); 
 
44
        if (isIgnoring(kind)) {
 
45
            return true;
 
46
        }
 
47
        TestMessage t = new TestMessage(message);
 
48
        messages.add(t);
 
49
        if (kind.equals(IMessage.ABORT) || message.getThrown() != null) {
 
50
                System.err.println("> AjCompiler error: "+message.getMessage()); //$NON-NLS-1$
 
51
                message.getThrown().printStackTrace();
 
52
                errors.add(t);
 
53
        } else if (kind.equals(IMessage.ERROR)) {
 
54
                errors.add(t);
 
55
        }
 
56
        System.out.println("> "+message); //$NON-NLS-1$
 
57
                return true;
 
58
        }
 
59
 
 
60
        public void dontIgnore(Kind kind) {
 
61
            if (null != kind) {
 
62
                ignoring.remove(kind);
 
63
            }
 
64
        }
 
65
 
 
66
        public boolean isIgnoring(Kind kind) {
 
67
                return ((null != kind) && (ignoring.contains(kind)));
 
68
        }
 
69
        
 
70
        public void ignore(Kind kind) {
 
71
            if ((null != kind) && (!ignoring.contains(kind))) {
 
72
                ignoring.add(kind);
 
73
            }   
 
74
        }
 
75
 
 
76
        public List getMessages() {
 
77
                return messages;
 
78
        }
 
79
        
 
80
        public List getErrors() {
 
81
                return errors;
 
82
        }
 
83
        
 
84
        public static class TestMessage {
 
85
                IMessage message;
 
86
                
 
87
                public TestMessage(IMessage m) {
 
88
                        message = m;
 
89
                }
 
90
                
 
91
                public IMessage getContainedMessage() {
 
92
                        return message;
 
93
                }
 
94
                
 
95
        public String toString() {
 
96
            String loc = "<no location>";
 
97
            if (null != message.getSourceLocation()) {
 
98
                loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine();
 
99
            }
 
100
            return "TestMessage [" + message.getMessage()
 
101
                + ", " + loc
 
102
                + ", " + message.getKind()
 
103
                + "]";
 
104
        }
 
105
        }
 
106
 
 
107
        public void reset() {
 
108
                messages.clear();
 
109
                errors.clear();
 
110
        }
 
111
 
 
112
}