use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcess method navigateToSnapshot.
/**
* Finds the snapshot associated with the given id and sets it as the active snapshot in the
* current debug session.
*/
public void navigateToSnapshot(@NotNull final String id) {
if (Strings.isNullOrEmpty(id)) {
LOG.error("unexpected navigation to empty breakpoint id");
return;
}
navigatedSnapshotId = id;
getStateController().resolveBreakpointAsync(id, new ResolveBreakpointHandler() {
@Override
public void onSuccess(@NotNull final Breakpoint result) {
ApplicationManager.getApplication().invokeLater(() -> {
// selections getting queued up.
if (id.equals(navigatedSnapshotId)) {
if (!Boolean.TRUE.equals(result.getIsFinalState()) || result.getStackFrames() == null) {
getBreakpointHandler().navigateTo(result);
if (result.getStackFrames() == null) {
navigateToBreakpoint(result);
}
return;
}
navigateToBreakpoint(result);
}
}, ModalityState.NON_MODAL);
}
@Override
public void onError(String errorMessage) {
LOG.warn("Could not navigate to breakpoint:" + errorMessage);
}
});
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method waitForChanges.
/**
* Package protected for test purposes only.
*/
void waitForChanges() {
if (state == null) {
LOG.error("no state available attempting to checkForChanges");
return;
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.info("no client available attempting to checkForChanges");
return;
}
String tokenToSend = state.getWaitToken();
List<Breakpoint> currentList;
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (SocketTimeoutException ex) {
// Timeout is expected on a hanging get.
return;
} catch (GoogleJsonResponseException ex) {
// we need to requery.
if (ex.getDetails().getCode() == 409) {
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (IOException ioException) {
LOG.warn("exception listing breakpoints", ioException);
return;
}
} else {
LOG.warn("exception listing breakpoints", ex);
return;
}
} catch (IOException ex) {
LOG.warn("exception listing breakpoints", ex);
return;
}
if (!isBackgroundListening()) {
return;
}
// to do pruning.
if (!Strings.isNullOrEmpty(tokenToSend)) {
pruneBreakpointCache(currentList);
fireBreakpointsChanged();
}
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandler method cloneToNewBreakpoints.
/**
* Called when the user "reactivates" an existing snapshot to create a new breakpoint, this clones
* state into a new breakpoint. It is different from "createIdeRepresentationsIfNecessary" in the
* following respects:
*
* <p>
*
* <ul>
* <li>It only operates on final state breakpoints.
* <li>It always clones them into a new IDE breakpoint.
* <li>It does not set "created by server = true", so when control flow comes back into
* register, it will register with the server.
* </ul>
*/
public void cloneToNewBreakpoints(@NotNull final List<Breakpoint> serverBreakpoints) {
for (Breakpoint serverBreakpoint : serverBreakpoints) {
if (!Boolean.TRUE.equals(serverBreakpoint.getIsFinalState())) {
continue;
}
Project currentProject = process.getXDebugSession().getProject();
final XBreakpointManager manager = XDebuggerManager.getInstance(process.getXDebugSession().getProject()).getBreakpointManager();
if (serverBreakpoint.getLocation() == null) {
LOG.warn("attempted to clone a breakpoint without a source location: " + StringUtil.notNullize(serverBreakpoint.getId()));
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) {
LOG.warn("attempted to clone a breakpoint whose file doesn't exist locally: " + StringUtil.notNullize(serverBreakpoint.getLocation().getPath()));
continue;
}
final XLineBreakpoint existing = manager.findBreakpointAtLine(CloudLineBreakpointType.getInstance(), file, line);
if (existing != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
manager.removeBreakpoint(existing);
}
});
}
final CloudLineBreakpointProperties properties = new CloudLineBreakpointProperties();
final Breakpoint finalserverBreakpoint = serverBreakpoint;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
if (finalserverBreakpoint.getExpressions() != null && finalserverBreakpoint.getExpressions().size() > 0) {
properties.setWatchExpressions(finalserverBreakpoint.getExpressions().toArray(new String[finalserverBreakpoint.getExpressions().size()]));
}
XLineBreakpoint<CloudLineBreakpointProperties> newxIdeBreakpoint = manager.addLineBreakpoint(CloudLineBreakpointType.getInstance(), file.getUrl(), line, properties);
// Condition, watches.
if (!Strings.isNullOrEmpty(finalserverBreakpoint.getCondition())) {
newxIdeBreakpoint.setCondition(finalserverBreakpoint.getCondition());
}
}
});
}
UsageTrackerProvider.getInstance().trackEvent(GctTracking.CLOUD_DEBUGGER_CLONE_BREAKPOINTS).ping();
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method testReOrderNoChange.
public void testReOrderNoChange() throws IOException {
List<Breakpoint> returnedBreakpoints = new ArrayList<Breakpoint>();
returnedBreakpoints.add(createBreakpoint("p1", Boolean.TRUE, 1000, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("p2", Boolean.TRUE, 2000, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("p3", Boolean.TRUE, 2200, "com/google/ex1.java", 15, Boolean.TRUE, "foo!"));
returnedBreakpoints.add(createBreakpoint("p4", Boolean.FALSE, 0, "com/google/ex2.java", 12, null, null));
returnedBreakpoints.add(createBreakpoint("p5", Boolean.FALSE, 0, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("p6", null, 0, "com/google/ex1.java", 16, null, null));
returnedBreakpoints.add(createBreakpoint("p7", Boolean.FALSE, 0, "com/google/ex1.java", 17, null, null));
returnedBreakpoints.add(createBreakpoint("p8", Boolean.FALSE, 0, "com/google/ex3.java", 18, null, null));
Debugger client = createMockClient(returnedBreakpoints);
CloudDebugProcessState state = new CloudDebugProcessState(USER, DEBUGEE_ID, PROJECT_NAME, PROJECT_NUMBER, null);
assertEquals(USER, state.getUserEmail());
// danger: static global state shared between tests
CloudDebuggerClient.setClient(state.getUserEmail() + 120000, client);
CloudDebugProcessStateController controller = new CloudDebugProcessStateController();
controller.initialize(state);
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
assertNotEmpty(currentList);
assertTrue(verifyList(currentList, "p5", "p6", "p7", "p4", "p8", "p3", "p2", "p1"));
returnedBreakpoints.clear();
returnedBreakpoints.add(createBreakpoint("b8", Boolean.FALSE, 0, "com/google/ex3.java", 18, null, null));
returnedBreakpoints.add(createBreakpoint("b7", Boolean.FALSE, 0, "com/google/ex1.java", 17, null, null));
returnedBreakpoints.add(createBreakpoint("b6", null, 0, "com/google/ex1.java", 16, null, null));
returnedBreakpoints.add(createBreakpoint("b5", Boolean.FALSE, 0, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("b4", Boolean.FALSE, 0, "com/google/ex2.java", 12, null, null));
returnedBreakpoints.add(createBreakpoint("b3", Boolean.TRUE, 2200, "com/google/ex1.java", 15, Boolean.TRUE, "foo!"));
returnedBreakpoints.add(createBreakpoint("b2", Boolean.TRUE, 2000, "com/google/ex1.java", 15, null, null));
returnedBreakpoints.add(createBreakpoint("b1", Boolean.TRUE, 1000, "com/google/ex1.java", 15, null, null));
controller.waitForChanges();
List<Breakpoint> changedList = state.getCurrentServerBreakpointList();
assertNotEmpty(changedList);
assertTrue(verifyList(changedList, "b5", "b6", "b7", "b4", "b8", "b3", "b2", "b1"));
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method createBreakpoint.
private static Breakpoint createBreakpoint(String id, Boolean isFinal, int finalTimeSeconds, String locationPath, Integer locationLine, Boolean isError, String statusMessage) {
Breakpoint result = new Breakpoint();
result.setId(id);
result.setIsFinalState(isFinal);
if (Boolean.TRUE.equals(isFinal)) {
Calendar calendar = // gets a calendar using the default time zone and locale.
Calendar.getInstance();
calendar.add(Calendar.SECOND, finalTimeSeconds);
DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
result.setFinalTime(formatter.print(calendar.getTimeInMillis()));
}
SourceLocation location = new SourceLocation();
location.setPath(locationPath);
location.setLine(locationLine);
result.setLocation(location);
StatusMessage status = new StatusMessage();
status.setIsError(isError);
FormatMessage message = new FormatMessage();
message.setFormat(statusMessage);
status.setDescription(message);
result.setStatus(status);
return result;
}
Aggregations