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 3.0KB

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