Search in sources :

Example 1 with CloudLineBreakpoint

use of com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint 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);
        }
    });
}
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) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) SetBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler) PsiJavaFile(com.intellij.psi.PsiJavaFile) PsiFile(com.intellij.psi.PsiFile)

Example 2 with CloudLineBreakpoint

use of com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcess method stop.

@Override
public void stop() {
    getStateController().stopBackgroundListening();
    RunProfile profile = getXDebugSession().getRunProfile();
    if (profile instanceof CloudDebugRunConfiguration) {
        ((CloudDebugRunConfiguration) profile).setProcessState(processState);
    }
    getRepositoryValidator().restoreToOriginalState(getXDebugSession().getProject());
    XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getXDebugSession().getProject()).getBreakpointManager();
    for (XBreakpoint bp : breakpointManager.getAllBreakpoints()) {
        com.intellij.debugger.ui.breakpoints.Breakpoint cloudBreakpoint = BreakpointManager.getJavaBreakpoint(bp);
        if (!(cloudBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint)) {
            continue;
        }
        CloudLineBreakpointType.CloudLineBreakpoint cloudLineBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) cloudBreakpoint;
        cloudLineBreakpoint.setVerified(false);
        cloudLineBreakpoint.setErrorMessage(null);
        updateBreakpointPresentation(cloudLineBreakpoint);
    }
}
Also used : XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) RunProfile(com.intellij.execution.configurations.RunProfile)

Example 3 with CloudLineBreakpoint

use of com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessaryVerifiesNonFinalIdeBreakpoint.

public void testCreateIdeRepresentationsIfNecessaryVerifiesNonFinalIdeBreakpoint() throws Exception {
    XLineBreakpointImpl breakpoint = registerMockBreakpoint(NO_WATCHES, NO_CONDITION, 13, "fileName", "packageName", false, "12abc");
    CloudLineBreakpoint cloudLineBreakpoint = (CloudLineBreakpoint) breakpoint.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY);
    assertNotNull(cloudLineBreakpoint);
    Assert.assertFalse(cloudLineBreakpoint.isVerified());
    handler.createIdeRepresentationsIfNecessary(Lists.newArrayList(new Breakpoint().setId("12abc")));
    assertThat(cloudLineBreakpoint.getErrorMessage(), nullValue());
    Assert.assertTrue(cloudLineBreakpoint.isVerified());
}
Also used : 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) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)

Example 4 with CloudLineBreakpoint

use of com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method verifyMutedIconSettingInUpdateBreakpointPresentation.

private void verifyMutedIconSettingInUpdateBreakpointPresentation(Boolean muted) {
    XBreakpointManager breakpointManager = mock(XBreakpointManager.class);
    XDebugSession debugSession = mock(XDebugSession.class);
    when(debugSession.areBreakpointsMuted()).thenReturn(muted);
    CloudDebugProcess cloudDebugProcess = mockCloudDebugProcess(breakpointManager, debugSession);
    CloudLineBreakpoint breakpoint = mockCloudLineBreakpoint("mock error message", mock(XLineBreakpointImpl.class));
    cloudDebugProcess.updateBreakpointPresentation(breakpoint);
    verify(breakpoint).getSetIcon(muted);
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)

Example 5 with CloudLineBreakpoint

use of com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation.

public void testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation() throws Exception {
    // override the default XBreakpointManager implementation with mock to use Mockito.verify()
    XBreakpointManager breakpointManager = mock(XBreakpointManager.class);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
    ((ProjectImpl) getProject()).registerComponentInstance(XDebuggerManager.class, debuggerManager);
    ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
    Breakpoint breakpoint = new Breakpoint();
    breakpoint.setId("breakpointId").setIsFinalState(Boolean.TRUE).setStatus(new StatusMessage().setIsError(Boolean.TRUE));
    breakpoints.add(breakpoint);
    CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
    when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(breakpoints));
    XLineBreakpointImpl xLineBreakpointImpl = mock(XLineBreakpointImpl.class);
    CloudLineBreakpoint cloudLineBreakpoint = mockCloudLineBreakpoint("mock error message", xLineBreakpointImpl);
    when(xLineBreakpointImpl.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(cloudLineBreakpoint);
    CloudBreakpointHandler breakpointHandler = mock(CloudBreakpointHandler.class);
    when(breakpointHandler.getEnabledXBreakpoint(breakpoint)).thenReturn(xLineBreakpointImpl);
    process.setBreakpointHandler(breakpointHandler);
    process.initialize(processState);
    process.onBreakpointListChanged(mock(CloudDebugProcessState.class));
    verify(cloudLineBreakpoint).setErrorMessage(eq("General error"));
    verify(cloudLineBreakpoint).getXBreakpoint();
    verify(cloudLineBreakpoint).getSetIcon(Matchers.anyBoolean());
    verify(cloudLineBreakpoint).getErrorMessage();
    verify(breakpointManager).updateBreakpointPresentation(same(xLineBreakpointImpl), any(Icon.class), eq("General error"));
    process.getStateController().stopBackgroundListening();
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) ProjectImpl(com.intellij.openapi.project.impl.ProjectImpl) ArrayList(java.util.ArrayList) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Icon(javax.swing.Icon) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Aggregations

CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)9 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)6 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)4 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)4 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)4 XLineBreakpointImpl (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)4 Icon (javax.swing.Icon)3 XDebugSession (com.intellij.xdebugger.XDebugSession)2 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)1 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)1 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 ProjectImpl (com.intellij.openapi.project.impl.ProjectImpl)1 PsiFile (com.intellij.psi.PsiFile)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 HashMap (com.intellij.util.containers.HashMap)1 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)1 XBreakpointBase (com.intellij.xdebugger.impl.breakpoints.XBreakpointBase)1 ArrayList (java.util.ArrayList)1