Search in sources :

Example 6 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testConflictingRegister.

public void testConflictingRegister() {
    Breakpoint existingServerBp = new Breakpoint();
    SourceLocation location = new SourceLocation();
    location.setPath("com/google/foo.java");
    location.setLine(124);
    existingServerBp.setLocation(location);
    existingServerBp.setId("todelete");
    existingBreakpoints.add(existingServerBp);
    registerMockBreakpoint(new String[] { "foowatch1" }, "condition == true", 123, "foo.java", "com.google", false, "b_id");
    existingBreakpoints.clear();
    assertNotNull(addedBp.get());
    assertContainsElements(addedBp.get().getExpressions(), "foowatch1");
    assertTrue(addedBp.get().getLocation().getLine() == 124);
    assertTrue(addedBp.get().getLocation().getPath().equals("com/google/foo.java"));
    assertTrue(addedBp.get().getCondition().equals("condition == true"));
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) 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)

Example 7 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessary.

public void testCreateIdeRepresentationsIfNecessary() {
    List<Breakpoint> breakpoints = ImmutableList.of(new Breakpoint().setId("expected_path").setLocation(new SourceLocation().setLine(1).setPath("app/mod/src/main/java/b/f/pkg/Class.java")), new Breakpoint().setId("unexpected_path").setLocation(new SourceLocation().setLine(2).setPath("app/mod/src/m/j/a/b/c/Class.java")), new Breakpoint().setId("unexpected_path_2").setLocation(new SourceLocation().setLine(3).setPath("b/f/pkg/Class.java")));
    when(breakpointManager.findBreakpointAtLine(isA(XLineBreakpointType.class), isA(VirtualFile.class), anyInt())).thenReturn(null);
    XLineBreakpoint mockLineBreakpoint = mock(XLineBreakpoint.class);
    when(breakpointManager.addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(CloudLineBreakpointProperties.class))).thenReturn(mockLineBreakpoint);
    when(mockLineBreakpoint.getProperties()).thenReturn(new CloudLineBreakpointProperties());
    VirtualFile projectDir = mock(VirtualFile.class);
    when(projectDir.getPath()).thenReturn("/project/dir");
    project.setBaseDir(projectDir);
    VirtualFile classFile = mock(VirtualFile.class);
    when(classFile.getUrl()).thenReturn("file:///URL");
    when(fileResolver.getFileFromPath(isA(Project.class), eq("app/mod/src/main/java/b/f/pkg/Class.java"))).thenReturn(classFile);
    handler.createIdeRepresentationsIfNecessary(breakpoints);
    verify(breakpointManager, times(1)).addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(XBreakpointProperties.class));
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) 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) XLineBreakpointType(com.intellij.xdebugger.breakpoints.XLineBreakpointType) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 8 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint 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 9 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class BreakpointComparer method compare.

@SuppressWarnings("ConstantConditions")
@Override
public int compare(Breakpoint o1, Breakpoint o2) {
    if (o2.getFinalTime() == null && o1.getFinalTime() != null) {
        return 1;
    }
    if (o2.getFinalTime() != null && o1.getFinalTime() == null) {
        return -1;
    }
    if (o2.getFinalTime() == null && o1.getFinalTime() == null) {
        // compare file and line
        SourceLocation s1 = o1.getLocation();
        SourceLocation s2 = o2.getLocation();
        boolean s1Valid = isSourceLocationValid(s1);
        boolean s2Valid = isSourceLocationValid(s2);
        if (!s1Valid && !s2Valid) {
            return 0;
        }
        if (s1Valid && !s2Valid) {
            return -1;
        }
        if (!s1Valid && s2Valid) {
            return 1;
        }
        if (s1.getPath().equals(s2.getPath())) {
            long s1Line = toLongValue(s1.getLine().longValue());
            long s2Line = toLongValue(s2.getLine().longValue());
            if (s1Line > s2Line) {
                return 1;
            }
            if (s1Line < s2Line) {
                return -1;
            }
            return 0;
        }
        return s1.getPath().compareTo(s2.getPath());
    }
    Date d1, d2;
    try {
        d1 = ISODateTimeFormat.dateTime().parseDateTime(o1.getFinalTime()).toDate();
        d2 = ISODateTimeFormat.dateTime().parseDateTime(o2.getFinalTime()).toDate();
    } catch (IllegalArgumentException iae) {
        d1 = MINIMUM_DATE;
        d2 = MINIMUM_DATE;
    }
    return d2.compareTo(d1);
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Date(java.util.Date)

Example 10 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint 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)

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