/
TestBuildProgressMonitor.java
91 lines (77 loc) · 2.82 KB
/
TestBuildProgressMonitor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/********************************************************************
* Copyright (c) 2007 Contributors. All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Contributors: IBM Corporation - initial API and implementation
* Helen Hawkins - initial version
*******************************************************************/
package org.aspectj.ajde.core;
import java.util.ArrayList;
import java.util.List;
/**
* Test implementation of IBuildProgressMonitor which prints out
* progress to the console and enables users to cancel the build process
* after a specified string has been printed.
*/
public class TestBuildProgressMonitor implements IBuildProgressMonitor {
private static boolean debugTests = false;
public int numWovenClassMessages = 0;
public int numWovenAspectMessages = 0;
public int numCompiledMessages = 0;
private String programmableString;
private int count;
private List<String> messagesReceived = new ArrayList<String>();
private int currentVal;
private boolean isCancelRequested = false;
public void finish(boolean wasFullBuild) {
System.out.println("build finished. Was full build: " + wasFullBuild);
}
public boolean isCancelRequested() {
return isCancelRequested;
}
public void setProgress(double percentDone) {
System.out.println("progress. Completed " + percentDone + " percent");
}
public void setProgressText(String text) {
System.out.println("progress text: " + text);
String newText = text+" [Percentage="+currentVal+"%]";
messagesReceived.add(newText);
if (text.startsWith("woven aspect ")) numWovenAspectMessages++;
if (text.startsWith("woven class ")) numWovenClassMessages++;
if (text.startsWith("compiled:")) numCompiledMessages++;
if (programmableString != null
&& text.indexOf(programmableString) != -1) {
count--;
if (count==0) {
if (debugTests) System.out.println("Just got message '"+newText+"' - asking build to cancel");
isCancelRequested = true;
programmableString = null;
}
}
}
public void begin() {
System.out.println("build started");
currentVal = 0;
}
// ------------- methods to help with testing -------------
public void cancelOn(String string,int count) {
programmableString = string;
this.count = count;
}
public boolean containsMessage(String prefix,String distinguishingMarks) {
for (String element: messagesReceived) {
if (element.startsWith(prefix) &&
element.indexOf(distinguishingMarks)!=-1) return true;
}
return false;
}
public void dumpMessages() {
System.out.println("ProgressMonitorMessages");
for (String element: messagesReceived) {
System.out.println(element);
}
}
}