Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TestMessageHandler.java 3.1KB

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