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

пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 17 година
пре 9 година
пре 17 година
пре 17 година
пре 17 година
пре 9 година
пре 17 година
пре 17 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /**
  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<>();
  27. private int currentVal;
  28. private boolean isCancelRequested = false;
  29. public void finish(boolean wasFullBuild) {
  30. info("build finished. Was full build: " + wasFullBuild);
  31. }
  32. public boolean isCancelRequested() {
  33. return isCancelRequested;
  34. }
  35. private void info(String message) {
  36. if (AjdeCoreModuleTests.verbose) {
  37. System.out.println(message);
  38. }
  39. }
  40. public void setProgress(double percentDone) {
  41. info("progress. Completed " + percentDone + " percent");
  42. }
  43. public void setProgressText(String text) {
  44. info("progress text: " + text);
  45. String newText = text+" [Percentage="+currentVal+"%]";
  46. messagesReceived.add(newText);
  47. if (text.startsWith("woven aspect ")) {
  48. numWovenAspectMessages++;
  49. }
  50. if (text.startsWith("woven class ")) {
  51. numWovenClassMessages++;
  52. }
  53. if (text.startsWith("compiled:")) {
  54. numCompiledMessages++;
  55. }
  56. if (programmableString != null
  57. && text.contains(programmableString)) {
  58. count--;
  59. if (count==0) {
  60. if (debugTests) {
  61. System.out.println("Just got message '"+newText+"' - asking build to cancel");
  62. }
  63. isCancelRequested = true;
  64. programmableString = null;
  65. }
  66. }
  67. }
  68. public void begin() {
  69. info("build started");
  70. currentVal = 0;
  71. }
  72. // ------------- methods to help with testing -------------
  73. public void cancelOn(String string,int count) {
  74. programmableString = string;
  75. this.count = count;
  76. }
  77. public boolean containsMessage(String prefix,String distinguishingMarks) {
  78. for (String element: messagesReceived) {
  79. if (element.startsWith(prefix) &&
  80. element.contains(distinguishingMarks)) {
  81. return true;
  82. }
  83. }
  84. return false;
  85. }
  86. public void dumpMessages() {
  87. System.out.println("ProgressMonitorMessages");
  88. for (String element: messagesReceived) {
  89. System.out.println(element);
  90. }
  91. }
  92. }