You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestMessageHandler.java 2.8KB

пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 9 година
пре 13 година
пре 17 година
пре 13 година
пре 9 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 9 година
пре 17 година
пре 13 година
пре 9 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
пре 13 година
пре 17 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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
  10. *******************************************************************/
  11. package org.aspectj.ajde.core;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.aspectj.bridge.AbortException;
  15. import org.aspectj.bridge.IMessage;
  16. import org.aspectj.bridge.IMessage.Kind;
  17. /**
  18. * Test implementation of IBuildMessageHandler. By default it ignores INFO and WEAVEINFO messages. Stores all messages it's not
  19. * ignoring in an ArrayList and ERRORS and ABORTS also in a separate ArrayList enabling users to query whether anything went wrong
  20. * with the build.
  21. */
  22. public class TestMessageHandler implements IBuildMessageHandler {
  23. private List<Kind> ignoring;
  24. private List<TestMessage> messages;
  25. private List<TestMessage> errors;
  26. public TestMessageHandler() {
  27. ignoring = new ArrayList<Kind>();
  28. messages = new ArrayList<TestMessage>();
  29. errors = new ArrayList<TestMessage>();
  30. ignore(IMessage.INFO);
  31. ignore(IMessage.WEAVEINFO);
  32. }
  33. public boolean handleMessage(IMessage message) throws AbortException {
  34. IMessage.Kind kind = message.getKind();
  35. if (isIgnoring(kind)) {
  36. return true;
  37. }
  38. TestMessage t = new TestMessage(message);
  39. messages.add(t);
  40. if (kind.equals(IMessage.ABORT) || message.getThrown() != null) {
  41. System.err.println("> AjCompiler error: " + message.getMessage()); //$NON-NLS-1$
  42. message.getThrown().printStackTrace();
  43. errors.add(t);
  44. } else if (kind.equals(IMessage.ERROR)) {
  45. errors.add(t);
  46. }
  47. System.out.println("> " + message); //$NON-NLS-1$
  48. return true;
  49. }
  50. public void dontIgnore(Kind kind) {
  51. if (null != kind) {
  52. ignoring.remove(kind);
  53. }
  54. }
  55. public boolean isIgnoring(Kind kind) {
  56. return ((null != kind) && (ignoring.contains(kind)));
  57. }
  58. public void ignore(Kind kind) {
  59. if ((null != kind) && (!ignoring.contains(kind))) {
  60. ignoring.add(kind);
  61. }
  62. }
  63. public List<TestMessage> getMessages() {
  64. return messages;
  65. }
  66. public List<TestMessage> getErrors() {
  67. return errors;
  68. }
  69. public static class TestMessage {
  70. IMessage message;
  71. public TestMessage(IMessage m) {
  72. message = m;
  73. }
  74. public IMessage getContainedMessage() {
  75. return message;
  76. }
  77. public String toString() {
  78. String loc = "<no location>";
  79. if (null != message.getSourceLocation()) {
  80. loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine();
  81. }
  82. return "TestMessage [" + message.getMessage() + ", " + loc + ", " + message.getKind() + "]";
  83. }
  84. }
  85. }