content.append(format("public class %s {%n", className1));
content.append(format(" public %s() {%n", className1));
content.append(format(" System.out.println();%n")); // This is line 4
content.append(format(" }%n"));
content.append(format("}"));
ICompilationUnit unit1 = pkg.createCompilationUnit(className1 + ".java",
content.toString(), true, null);
// Create a breakpoint at line 4 in the above file:
JDIDebugModel.createLineBreakpoint(unit1.getResource(),
unit1.getType(className1).getFullyQualifiedName(), 4, -1, -1, 0, true,
null);
String className2 = "TestEnabledWithBreakpointsAndFiles2";
content = new StringBuilder();
content.append(format("package %s;%n", pkg.getElementName()));
content.append(format("public class %s {%n", className2));
content.append(format(" public static void main(String[] args) {%n"));
content.append(format(" new %s();%n", className1)); // This is line 4
content.append(format(" }%n"));
content.append(format("}"));
ICompilationUnit unit2 = pkg.createCompilationUnit(className2 + ".java",
content.toString(), true, null);
// Create a breakpoint at line 4 in the above file:
JDIDebugModel.createLineBreakpoint(unit2.getResource(),
unit2.getType(className2).getFullyQualifiedName(), 4, -1, -1, 0, true,
null);
final ISuspendResume[] suspendResume = new ISuspendResume[1];
MyDebugListener listener = new MyDebugListener() {
@Override
public void handleDebugEvents(DebugEvent[] events) {
super.handleDebugEvents(events);
for (DebugEvent e : events) {
if (e.getKind() == DebugEvent.SUSPEND) {
suspendResume[0] = (ISuspendResume) e.getSource();
}
}
}
};
DebugPlugin.getDefault().addDebugEventListener(listener);
// Launch in debug mode:
tracker.setEnabled(true);
launch("TestEnabledWithBreakpointsAndFiles",
pkg.getJavaProject().getElementName(),
unit2.getType(className2).getFullyQualifiedName(),
ILaunchManager.DEBUG_MODE);
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
lock.lock();
try {
// We had two breakpoints set, so we need to resume twice:
while (suspendResume[0] == null) {
condition.await(100, TimeUnit.MICROSECONDS);
}
suspendResume[0].resume();
suspendResume[0] = null;
condition.await(100, TimeUnit.MILLISECONDS);
while (suspendResume[0] == null) {
condition.await(100, TimeUnit.MILLISECONDS);
}
suspendResume[0].resume();
condition.await(500, TimeUnit.MILLISECONDS);
} finally {
lock.unlock();
}
assertEquals(1, tracker.getData().size());
LaunchEvent event = tracker.getData().iterator().next();
assertEquals(2, event.getFilePaths().size());
assertTrue(event.getFilePaths().contains(unit1.getResource().getFullPath()));
assertTrue(event.getFilePaths().contains(unit2.getResource().getFullPath()));
}