use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandlerTest method testConflictingRegister.
public void testConflictingRegister() {
Breakpoint existingServerBp = new Breakpoint();
SourceLocation location = new SourceLocation();
location.setPath("com/google/foo.java");
location.setLine(124);
existingServerBp.setLocation(location);
existingServerBp.setId("todelete");
existingBreakpoints.add(existingServerBp);
registerMockBreakpoint(new String[] { "foowatch1" }, "condition == true", 123, "foo.java", "com.google", false, "b_id");
existingBreakpoints.clear();
assertNotNull(addedBp.get());
assertContainsElements(addedBp.get().getExpressions(), "foowatch1");
assertTrue(addedBp.get().getLocation().getLine() == 124);
assertTrue(addedBp.get().getLocation().getPath().equals("com/google/foo.java"));
assertTrue(addedBp.get().getCondition().equals("condition == true"));
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessary.
public void testCreateIdeRepresentationsIfNecessary() {
List<Breakpoint> breakpoints = ImmutableList.of(new Breakpoint().setId("expected_path").setLocation(new SourceLocation().setLine(1).setPath("app/mod/src/main/java/b/f/pkg/Class.java")), new Breakpoint().setId("unexpected_path").setLocation(new SourceLocation().setLine(2).setPath("app/mod/src/m/j/a/b/c/Class.java")), new Breakpoint().setId("unexpected_path_2").setLocation(new SourceLocation().setLine(3).setPath("b/f/pkg/Class.java")));
when(breakpointManager.findBreakpointAtLine(isA(XLineBreakpointType.class), isA(VirtualFile.class), anyInt())).thenReturn(null);
XLineBreakpoint mockLineBreakpoint = mock(XLineBreakpoint.class);
when(breakpointManager.addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(CloudLineBreakpointProperties.class))).thenReturn(mockLineBreakpoint);
when(mockLineBreakpoint.getProperties()).thenReturn(new CloudLineBreakpointProperties());
VirtualFile projectDir = mock(VirtualFile.class);
when(projectDir.getPath()).thenReturn("/project/dir");
project.setBaseDir(projectDir);
VirtualFile classFile = mock(VirtualFile.class);
when(classFile.getUrl()).thenReturn("file:///URL");
when(fileResolver.getFileFromPath(isA(Project.class), eq("app/mod/src/main/java/b/f/pkg/Class.java"))).thenReturn(classFile);
handler.createIdeRepresentationsIfNecessary(breakpoints);
verify(breakpointManager, times(1)).addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(XBreakpointProperties.class));
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugHistoricalSnapshotsTest method testOnBreakpointListChanged.
@Test
public void testOnBreakpointListChanged() throws InterruptedException {
CloudDebugHistoricalSnapshots snapshots = new CloudDebugHistoricalSnapshots(handler);
Breakpoint bp1 = new Breakpoint();
bp1.setId("an ID");
bp1.setFinalTime("2015-08-22T05:23:34.123Z");
bp1.setIsFinalState(true);
SourceLocation location = new SourceLocation();
location.setPath("foo/bar/baz");
location.setLine(12);
bp1.setLocation(location);
List<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
breakpoints.add(bp1);
Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints);
Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp1);
CloudBreakpointHandler breakpointHandler = Mockito.mock(CloudBreakpointHandler.class);
Mockito.when(mockProcess.getBreakpointHandler()).thenReturn(breakpointHandler);
runModelSetter(snapshots);
Assert.assertEquals(0, snapshots.table.getSelectedRow());
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class BreakpointComparer method compare.
@SuppressWarnings("ConstantConditions")
@Override
public int compare(Breakpoint o1, Breakpoint o2) {
if (o2.getFinalTime() == null && o1.getFinalTime() != null) {
return 1;
}
if (o2.getFinalTime() != null && o1.getFinalTime() == null) {
return -1;
}
if (o2.getFinalTime() == null && o1.getFinalTime() == null) {
// compare file and line
SourceLocation s1 = o1.getLocation();
SourceLocation s2 = o2.getLocation();
boolean s1Valid = isSourceLocationValid(s1);
boolean s2Valid = isSourceLocationValid(s2);
if (!s1Valid && !s2Valid) {
return 0;
}
if (s1Valid && !s2Valid) {
return -1;
}
if (!s1Valid && s2Valid) {
return 1;
}
if (s1.getPath().equals(s2.getPath())) {
long s1Line = toLongValue(s1.getLine().longValue());
long s2Line = toLongValue(s2.getLine().longValue());
if (s1Line > s2Line) {
return 1;
}
if (s1Line < s2Line) {
return -1;
}
return 0;
}
return s1.getPath().compareTo(s2.getPath());
}
Date d1, d2;
try {
d1 = ISODateTimeFormat.dateTime().parseDateTime(o1.getFinalTime()).toDate();
d2 = ISODateTimeFormat.dateTime().parseDateTime(o2.getFinalTime()).toDate();
} catch (IllegalArgumentException iae) {
d1 = MINIMUM_DATE;
d2 = MINIMUM_DATE;
}
return d2.compareTo(d1);
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandler method createIdeRepresentationsIfNecessary.
/**
* Called when new breakpoints are encountered in polling the server, this method possibly creates
* local representations of those breakpoints if there isn't one already at that line.
*/
public void createIdeRepresentationsIfNecessary(@NotNull final List<Breakpoint> serverBreakpoints) {
boolean addedBreakpoint = false;
for (final Breakpoint serverBreakpoint : serverBreakpoints) {
if (Boolean.TRUE.equals(serverBreakpoint.getIsFinalState())) {
continue;
}
if (ideBreakpoints.containsKey(serverBreakpoint.getId())) {
final XBreakpoint xIdeBreakpoint = ideBreakpoints.get(serverBreakpoint.getId());
com.intellij.debugger.ui.breakpoints.Breakpoint cloudIdeBreakpoint = BreakpointManager.getJavaBreakpoint(xIdeBreakpoint);
if (cloudIdeBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint) {
CloudLineBreakpointType.CloudLineBreakpoint cloudIdeLineBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) cloudIdeBreakpoint;
cloudIdeLineBreakpoint.setVerified(true);
cloudIdeLineBreakpoint.setErrorMessage(null);
process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
}
continue;
}
Project currentProject = process.getXDebugSession().getProject();
final XBreakpointManager manager = XDebuggerManager.getInstance(process.getXDebugSession().getProject()).getBreakpointManager();
if (serverBreakpoint.getLocation() == null) {
continue;
}
String path = serverBreakpoint.getLocation().getPath();
if (Strings.isNullOrEmpty(path)) {
continue;
}
final VirtualFile file = fileResolver.getFileFromPath(currentProject, path);
final int line = serverBreakpoint.getLocation().getLine() - 1;
if (file == null) {
continue;
}
final XLineBreakpoint existingXIdeBreakpoint = manager.findBreakpointAtLine(CloudLineBreakpointType.getInstance(), file, line);
if (existingXIdeBreakpoint != null && existingXIdeBreakpoint.isEnabled()) {
continue;
}
if (existingXIdeBreakpoint != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
manager.removeBreakpoint(existingXIdeBreakpoint);
}
});
}
final CloudLineBreakpointProperties properties = new CloudLineBreakpointProperties();
properties.setCreatedByServer(true);
addedBreakpoint = true;
ApplicationManager.getApplication().runWriteAction(new DoUpdateIdeWithBreakpoint(manager, file, line, properties, serverBreakpoint, ideBreakpoints, process));
}
if (addedBreakpoint) {
// If we added a new breakpoint, the snapshot list needs to be refreshed.
// However, since adding is async depending on the ability to invoke a write action,
// we want to queue the refresh after all the write actions we just did.
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
process.fireBreakpointsChanged();
}
});
}
}
Aggregations