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.9KB

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