Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MultiProjTestMessageHandler.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.systemtest.incremental.tools;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.aspectj.ajde.core.IBuildMessageHandler;
  15. import org.aspectj.bridge.AbortException;
  16. import org.aspectj.bridge.IMessage;
  17. import org.aspectj.bridge.IMessage.Kind;
  18. /**
  19. * IMessageHandler which by default ignores INFO and WEAVEINFO messages. Records the warning, weaving, compiler errors and error
  20. * messages and provides methods to get them.
  21. */
  22. public class MultiProjTestMessageHandler implements IBuildMessageHandler {
  23. private final boolean VERBOSE = false;
  24. private boolean receivedNonIncrementalBuildMessage = false;
  25. private boolean receivedBatchBuildMessage = false;
  26. private List<IMessage> errorMessages;
  27. private List<IMessage> warningMessages;
  28. private List<IMessage> weavingMessages;
  29. private List<String> compilerErrors;
  30. private List<Kind> ignoring;
  31. public MultiProjTestMessageHandler() {
  32. ignoring = new ArrayList<>();
  33. errorMessages = new ArrayList<IMessage>();
  34. warningMessages = new ArrayList<IMessage>();
  35. weavingMessages = new ArrayList<IMessage>();
  36. compilerErrors = new ArrayList<>();
  37. ignore(IMessage.INFO);
  38. ignore(IMessage.WEAVEINFO);
  39. }
  40. public boolean handleMessage(IMessage message) throws AbortException {
  41. IMessage.Kind kind = message.getKind();
  42. if (isIgnoring(kind)) {
  43. return true;
  44. }
  45. if (kind.equals(IMessage.ABORT) || message.getThrown() != null) {
  46. log("> AjCompiler error: " + message.getMessage() + ", " + message.getThrown() + ")"); //$NON-NLS-1$
  47. message.getThrown().printStackTrace();
  48. compilerErrors.add(message + ", (" + message.getThrown() + ")");
  49. if (VERBOSE && (message.getThrown() != null)) {
  50. message.getThrown().printStackTrace();
  51. }
  52. return true;
  53. }
  54. if (message.getKind() == IMessage.ERROR) {
  55. errorMessages.add(message);
  56. }
  57. if (message.getKind() == IMessage.WARNING) {
  58. warningMessages.add(message);
  59. }
  60. if (message.getKind() == IMessage.WEAVEINFO) {
  61. weavingMessages.add(message);
  62. }
  63. log("IMessageHandler.handleMessage(" + message + ")");
  64. return true;
  65. }
  66. public void dontIgnore(Kind kind) {
  67. if (null != kind) {
  68. ignoring.remove(kind);
  69. }
  70. }
  71. public boolean isIgnoring(Kind kind) {
  72. return ((null != kind) && (ignoring.contains(kind)));
  73. }
  74. public void ignore(Kind kind) {
  75. if ((null != kind) && (!ignoring.contains(kind))) {
  76. ignoring.add(kind);
  77. }
  78. }
  79. public boolean hasWarning() {
  80. return !warningMessages.isEmpty();
  81. }
  82. public boolean hasErrorMessages() {
  83. return !errorMessages.isEmpty();
  84. }
  85. public boolean hasCompilerErrorMessages() {
  86. return !compilerErrors.isEmpty();
  87. }
  88. public List<IMessage> getErrorMessages() {
  89. return errorMessages;
  90. }
  91. public List<IMessage> getWarningMessages() {
  92. return warningMessages;
  93. }
  94. public List<IMessage> getWeavingMessages() {
  95. return weavingMessages;
  96. }
  97. public List<String> getCompilerErrors() {
  98. return compilerErrors;
  99. }
  100. public void log(String s) {
  101. if (VERBOSE) {
  102. System.out.println(s);
  103. }
  104. }
  105. public void reset() {
  106. receivedNonIncrementalBuildMessage = false;
  107. receivedBatchBuildMessage = false;
  108. errorMessages.clear();
  109. warningMessages.clear();
  110. weavingMessages.clear();
  111. compilerErrors.clear();
  112. }
  113. }