use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandler method registerBreakpoint.
/**
* Called by IntelliJ when the user has enabled or created a new breakpoint. Creates the server
* breakpoint.
*
* @param ideBreakpoint breakpoint to register
*/
@Override
public void registerBreakpoint(@NotNull final XLineBreakpoint<CloudLineBreakpointProperties> ideBreakpoint) {
if (ideBreakpoint.getSourcePosition() == null || !ideBreakpoint.isEnabled() || !(ideBreakpoint.getType() instanceof CloudLineBreakpointType)) {
return;
}
com.intellij.debugger.ui.breakpoints.Breakpoint cloudIdeBreakpoint = BreakpointManager.getJavaBreakpoint(ideBreakpoint);
if (!(cloudIdeBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint)) {
LOG.error("breakpoint was not of the correct type to create on the cloud. It was not a " + "CloudLineBreakpoint");
return;
}
final CloudLineBreakpointType.CloudLineBreakpoint cloudIdeLineBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) cloudIdeBreakpoint;
if (ideBreakpoint.getProperties().isCreatedByServer()) {
// gets called during construction.
return;
}
if (ideBreakpoint.getProperties().isAddedOnServer() && !ideBreakpoint.getProperties().isDisabledByServer()) {
// disabled breakpoint
return;
}
PsiFile javaFile = psiManager.findFile(ideBreakpoint.getSourcePosition().getFile());
if (!(javaFile instanceof PsiJavaFile)) {
return;
}
SourceLocation location = new SourceLocation();
// Sending the file as com/package/example/Class.java to Cloud Debugger because it plays nice
// with the CDB plugin. See ServerToIdeFileResolver.
location.setPath(ServerToIdeFileResolver.getCloudPathFromJavaFile((PsiJavaFile) javaFile));
location.setLine(ideBreakpoint.getSourcePosition().getLine() + 1);
Breakpoint serverNewBreakpoint = new Breakpoint();
serverNewBreakpoint.setLocation(location);
if (ideBreakpoint.getConditionExpression() != null) {
serverNewBreakpoint.setCondition(ideBreakpoint.getConditionExpression().getExpression());
}
List<String> watches = cloudIdeLineBreakpoint.getWatchExpressions();
if (watches != null) {
serverNewBreakpoint.setExpressions(watches);
}
// The breakpoint will enter error state asynchronously. For now, we state that its verified.
process.getStateController().setBreakpointAsync(serverNewBreakpoint, new SetBreakpointHandler() {
@Override
public void onSuccess(@NotNull final String id) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!Strings.isNullOrEmpty(id)) {
if (!cloudIdeLineBreakpoint.isEnabled()) {
process.getStateController().deleteBreakpointAsync(// race condition
id);
} else {
// Success.
// Mark as added so we don't add it again.
ideBreakpoint.getProperties().setAddedOnServer(true);
cloudIdeLineBreakpoint.setErrorMessage(null);
process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
}
} else {
// TODO(joaomartins): Why couldn't the breakpoint be set? Improve this
// message.
cloudIdeLineBreakpoint.setErrorMessage(GctBundle.getString("clouddebug.errorset"));
process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
}
if (!Strings.isNullOrEmpty(id)) {
ideBreakpoint.getProperties().setDisabledByServer(false);
String oldId = ideBreakpoint.getUserData(CLOUD_ID);
if (!Strings.isNullOrEmpty(oldId)) {
ideBreakpoints.remove(oldId);
}
ideBreakpoint.putUserData(CLOUD_ID, id);
ideBreakpoints.put(id, ideBreakpoint);
}
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
SwingUtilities.invokeLater(runnable);
}
}
@Override
public void onError(String errorMessage) {
cloudIdeLineBreakpoint.setErrorMessage(errorMessage);
process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
}
});
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint 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.model.Breakpoint 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.model.Breakpoint 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();
}
}
use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method resolveBreakpointAsync.
/**
* Returns a fully realized {@link Breakpoint} with all results possibly asynchronously.
*/
@SuppressWarnings("FutureReturnValueIgnored")
public void resolveBreakpointAsync(@NotNull final String id, @NotNull final ResolveBreakpointHandler handler) {
if (fullFinalBreakpoints.containsKey(id)) {
handler.onSuccess(fullFinalBreakpoints.get(id));
return;
}
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 resolveBreakpointAsync");
handler.onError(GctBundle.getString("clouddebug.bad.login.message"));
return;
}
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
for (Breakpoint serverBreakpointCandidate : currentList) {
if (serverBreakpointCandidate.getId().equals(id) && !Boolean.TRUE.equals(serverBreakpointCandidate.getIsFinalState())) {
handler.onSuccess(serverBreakpointCandidate);
return;
}
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// At this point, the user has selected a final state breakpoint which is not yet
// hydrated.
// So we query the server to get this final on a worker thread and then run the
// runnable
// back on ui
GetBreakpointResponse response;
try {
response = client.debuggees().breakpoints().get(state.getDebuggeeId(), id).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
Breakpoint result = response.getBreakpoint();
if (result != null) {
fullFinalBreakpoints.put(id, result);
handler.onSuccess(result);
} else {
handler.onError(GctBundle.getString("clouddebug.no.response"));
}
} catch (IOException ex) {
LOG.warn("IOException hydrating a snapshot. User may have deleted the snapshot", ex);
handler.onError(ex.toString());
}
});
}
Aggregations