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);
}
});
}
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);
}
}
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());
}
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);
}
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();
}
Aggregations