use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints 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.Clouddebugger.Debugger.Debuggees.Breakpoints 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();
}
});
}
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPoller method queryServerForBreakpoints.
private void queryServerForBreakpoints(CloudDebugProcessState state, Debugger client) throws IOException {
if (state.getDebuggeeId() == null) {
throw new IllegalStateException("CloudDebugProcessState.getDebuggeeId() was null");
}
Debuggees debuggees = client.debuggees();
Breakpoints breakpoints = debuggees.breakpoints();
Breakpoints.List listRequest = breakpoints.list(state.getDebuggeeId()).setIncludeInactive(Boolean.TRUE).setActionValue("CAPTURE").setStripResults(Boolean.TRUE).setWaitToken(state.getWaitToken());
ListBreakpointsResponse response = listRequest.setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
List<Breakpoint> currentList = response.getBreakpoints();
String responseWaitToken = response.getNextWaitToken();
state.setWaitToken(responseWaitToken);
if (currentList != null) {
Collections.sort(currentList, BreakpointComparer.getDefaultInstance());
}
state.setCurrentServerBreakpointList(currentList != null ? ContainerUtil.immutableList(currentList) : ContainerUtil.immutableList(new ArrayList<Breakpoint>()));
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method setBreakpointAsync.
/**
* Called from the {@link CloudDebugProcessHandler} to set a breakpoint.
*/
@SuppressWarnings("FutureReturnValueIgnored")
void setBreakpointAsync(@NotNull final Breakpoint serverBreakpoint, @NotNull final SetBreakpointHandler handler) {
if (state == null) {
handler.onError(GctBundle.getString("clouddebug.invalid.state"));
return;
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.warn("no client available attempting to setBreakpoint");
handler.onError(GctBundle.getString("clouddebug.bad.login.message"));
return;
}
final String debuggeeId = state.getDebuggeeId();
assert debuggeeId != null;
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
// Delete old breakpoints at this location.
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
SourceLocation location = serverBreakpoint.getLocation();
for (Breakpoint serverBp : currentList) {
if (!Boolean.TRUE.equals(serverBp.getIsFinalState()) && serverBp.getLocation().getLine() != null && serverBp.getLocation().getLine().equals(location.getLine()) && !Strings.isNullOrEmpty(serverBp.getLocation().getPath()) && serverBp.getLocation().getPath().equals(location.getPath())) {
// should not be async here.
deleteBreakpoint(serverBp.getId());
}
}
SetBreakpointResponse addResponse = client.debuggees().breakpoints().set(debuggeeId, serverBreakpoint).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
if (addResponse != null && addResponse.getBreakpoint() != null) {
Breakpoint result = addResponse.getBreakpoint();
if (result.getStatus() != null && Boolean.TRUE.equals(result.getStatus().getIsError()) && result.getStatus().getDescription() != null) {
handler.onError(BreakpointUtil.getUserErrorMessage(result.getStatus()));
}
handler.onSuccess(addResponse.getBreakpoint().getId());
} else {
handler.onError(GctBundle.getString("clouddebug.no.response"));
}
} catch (IOException ex) {
LOG.error("exception setting a breakpoint", ex);
handler.onError(ex.toString());
}
});
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method deleteBreakpoint.
/**
* Called from the {@link CloudBreakpointHandler} to remove breakpoints from the server.
*
* @param breakpointId the {@link Breakpoint} Id to delete
*/
@SuppressWarnings("FutureReturnValueIgnored")
private void deleteBreakpoint(@NotNull final String breakpointId, boolean performAsync) {
if (state == null) {
throw new IllegalStateException();
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.warn("no client available attempting to setBreakpoint");
Messages.showErrorDialog(state.getProject(), GctBundle.getString("clouddebug.bad.login.message"), GctBundle.getString("clouddebug.message.title"));
return;
}
final String debuggeeId = state.getDebuggeeId();
assert debuggeeId != null;
Runnable performDelete = () -> {
try {
client.debuggees().breakpoints().delete(debuggeeId, breakpointId).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
} catch (IOException ex) {
LOG.warn("exception deleting breakpoint " + breakpointId, ex);
}
};
if (performAsync) {
ApplicationManager.getApplication().executeOnPooledThread(performDelete);
} else {
performDelete.run();
}
}
Aggregations