Integer lineNum = commandLine.getIntValue(Options.LINE_OPTION);
ArrayList<IBreakpoint> enabled = new ArrayList<IBreakpoint>();
ArrayList<IBreakpoint> disabled = new ArrayList<IBreakpoint>();
IBreakpointManager breakpointMgr = DebugPlugin.getDefault()
.getBreakpointManager();
IBreakpoint[] breakpoints = breakpointMgr.getBreakpoints();
for (IBreakpoint breakpoint : breakpoints) {
IResource resource = breakpoint.getMarker().getResource();
String curProject = resource.getProject().getName();
String curFileName = resource.getRawLocation().toOSString();
if (!curProject.equals(projectName)){
continue;
}
String projectRelPath = breakpoint.getMarker().getResource()
.getProjectRelativePath().toString();
if (fileName != null){
if (fileName.equals(curFileName) || fileName.equals(projectRelPath)) {
if (lineNum == null ||
lineNum == -1 ||
lineNum == ((ILineBreakpoint)breakpoint).getLineNumber())
{
if (breakpoint.isEnabled()){
enabled.add(breakpoint);
}else{
disabled.add(breakpoint);
}
}
}
}else{
if (breakpoint.isEnabled()){
enabled.add(breakpoint);
}else{
disabled.add(breakpoint);
}
}
}
// edge case when acting on a line in a file, create the breakpoint if none
// exists
if (fileName != null && lineNum != null &&
enabled.size() == 0 && disabled.size() == 0)
{
fileName = commandLine.getValue(Options.FILE_OPTION);
create(projectName, fileName, lineNum);
return Services.getMessage("debugging.breakpoint.added");
}
String action = "enabled";
if (enabled.size() == 0){
for (IBreakpoint breakpoint : disabled){
breakpoint.setEnabled(true);
}
}else{
action = "disabled";
// another edge case when acting on a line in a file, delete the
// breakpoint if the 'delete' option was supplied
if (fileName != null && lineNum != null &&
enabled.size() == 1 && commandLine.hasOption("d"))
{
action = "removed";
breakpointMgr.removeBreakpoint(enabled.get(0), true);
}else{
for (IBreakpoint breakpoint : enabled){
breakpoint.setEnabled(false);
}
}