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.

TestBuildProgressMonitor.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /**
  15. * Test implementation of IBuildProgressMonitor which prints out
  16. * progress to the console and enables users to cancel the build process
  17. * after a specified string has been printed.
  18. */
  19. public class TestBuildProgressMonitor implements IBuildProgressMonitor {
  20. private static boolean debugTests = false;
  21. public int numWovenClassMessages = 0;
  22. public int numWovenAspectMessages = 0;
  23. public int numCompiledMessages = 0;
  24. private String programmableString;
  25. private int count;
  26. private List<String> messagesReceived = new ArrayList<String>();
  27. private int currentVal;
  28. private boolean isCancelRequested = false;
  29. public void finish(boolean wasFullBuild) {
  30. System.out.println("build finished. Was full build: " + wasFullBuild);
  31. }
  32. public boolean isCancelRequested() {
  33. return isCancelRequested;
  34. }
  35. public void setProgress(double percentDone) {
  36. System.out.println("progress. Completed " + percentDone + " percent");
  37. }
  38. public void setProgressText(String text) {
  39. System.out.println("progress text: " + text);
  40. String newText = text+" [Percentage="+currentVal+"%]";
  41. messagesReceived.add(newText);
  42. if (text.startsWith("woven aspect ")) numWovenAspectMessages++;
  43. if (text.startsWith("woven class ")) numWovenClassMessages++;
  44. if (text.startsWith("compiled:")) numCompiledMessages++;
  45. if (programmableString != null
  46. && text.contains(programmableString)) {
  47. count--;
  48. if (count==0) {
  49. if (debugTests) System.out.println("Just got message '"+newText+"' - asking build to cancel");
  50. isCancelRequested = true;
  51. programmableString = null;
  52. }
  53. }
  54. }
  55. public void begin() {
  56. System.out.println("build started");
  57. currentVal = 0;
  58. }
  59. // ------------- methods to help with testing -------------
  60. public void cancelOn(String string,int count) {
  61. programmableString = string;
  62. this.count = count;
  63. }
  64. public boolean containsMessage(String prefix,String distinguishingMarks) {
  65. for (String element: messagesReceived) {
  66. if (element.startsWith(prefix) &&
  67. element.contains(distinguishingMarks)) return true;
  68. }
  69. return false;
  70. }
  71. public void dumpMessages() {
  72. System.out.println("ProgressMonitorMessages");
  73. for (String element: messagesReceived) {
  74. System.out.println(element);
  75. }
  76. }
  77. }