Search in sources :

Example 1 with Breakpoint

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

Example 2 with Breakpoint

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();
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 3 with Breakpoint

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();
}
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) Project(com.intellij.openapi.project.Project) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) 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) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 4 with Breakpoint

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"));
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ArrayList(java.util.ArrayList)

Example 5 with Breakpoint

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;
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) FormatMessage(com.google.api.services.clouddebugger.v2.model.FormatMessage) Calendar(java.util.Calendar) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)27 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)11 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)11 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)10 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)8 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)7 ArrayList (java.util.ArrayList)7 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)4 IOException (java.io.IOException)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XLineBreakpointImpl (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)3 Test (org.junit.Test)3 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)2 CloudBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler)2 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)2