Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TestMessageHandler.java 2.9KB

17 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
9 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
9 лет назад
17 лет назад
12 лет назад
9 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
12 лет назад
17 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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<>();
  28. messages = new ArrayList<>();
  29. errors = new ArrayList<>();
  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. if (AjdeCoreModuleTests.verbose) {
  48. System.out.println("> " + message); //$NON-NLS-1$
  49. }
  50. return true;
  51. }
  52. public void dontIgnore(Kind kind) {
  53. if (null != kind) {
  54. ignoring.remove(kind);
  55. }
  56. }
  57. public boolean isIgnoring(Kind kind) {
  58. return ((null != kind) && (ignoring.contains(kind)));
  59. }
  60. public void ignore(Kind kind) {
  61. if ((null != kind) && (!ignoring.contains(kind))) {
  62. ignoring.add(kind);
  63. }
  64. }
  65. public List<TestMessage> getMessages() {
  66. return messages;
  67. }
  68. public List<TestMessage> getErrors() {
  69. return errors;
  70. }
  71. public static class TestMessage {
  72. IMessage message;
  73. public TestMessage(IMessage m) {
  74. message = m;
  75. }
  76. public IMessage getContainedMessage() {
  77. return message;
  78. }
  79. public String toString() {
  80. String loc = "<no location>";
  81. if (null != message.getSourceLocation()) {
  82. loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine();
  83. }
  84. return "TestMessage [" + message.getMessage() + ", " + loc + ", " + message.getKind() + "]";
  85. }
  86. }
  87. }