Search in sources :

Example 6 with Breakpoints

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());
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with Breakpoints

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();
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Project(com.intellij.openapi.project.Project) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 8 with Breakpoints

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>()));
}
Also used : Breakpoints(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) Debuggees(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService)

Example 9 with Breakpoints

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());
        }
    });
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) SetBreakpointResponse(com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException)

Example 10 with Breakpoints

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();
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) IOException(java.io.IOException)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)13 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)9 IOException (java.io.IOException)5 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)4 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)4 ArrayList (java.util.ArrayList)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)3 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 GetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.GetBreakpointResponse)1 SetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse)1