/** * Returns either cached state (if we were previously watching this state in this or the last IDE * session) Or it returns a partially valid state, which will later be filled in by the {@link * CloudDebuggerRunner} * * @param executor the execution mode selected by the user (run, debug, profile etc.) * @param environment the environment object containing additional settings for executing the * configuration. */ @Nullable @Override public RunProfileState getState( @NotNull Executor executor, @NotNull ExecutionEnvironment environment) { if (processState == null) { return new CloudDebugProcessState( googleUsername, null /* debug id */, cloudProjectId, null /* project number */, getProject()); } return processState; }
/** * The value returned from the method is immutable and is safe to access on multiple threads. * * <p>However, multiple successive calls to this method may return a different list. Therefore, * callers must store the return value locally to operate on it and should not call this method * repeatedly expecting the same list. */ // todo: can we declare this as ImmutableList? public List<Breakpoint> getCurrentBreakpointList() { return getProcessState().getCurrentServerBreakpointList(); }
private boolean targetMatchesCurrentState() { CloudDebugProcessState state = wireup.getInputState(); return state != null && targetSelector != null && targetSelector.getSelectedItem() != null && StringUtil.equals( state.getDebuggeeId(), ((DebugTarget) targetSelector.getSelectedItem()).getId()); }
/** * Called from {@link CloudDebugRunConfiguration}, it finds any serialized state for that named * run config and if the project name matches, it initializes and returns it. * * @param runConfig the runconfig for which state is queried for * @param projectName the GCP project name associated with this runconfig * @return deserialized state that may have been cached in workspace.xml */ public CloudDebugProcessState getState(@NotNull String runConfig, @NotNull String projectName) { CloudDebugProcessState state = stateMap.get(runConfig); if (state != null && state.getProjectName() != null && state.getProjectName().equals(projectName)) { state.setProject(project); return state; } return null; }
/** * CloudDebugProcessState can be initialized with partial state to indicate preferences on the * {@link CloudDebugRunConfiguration}. When the process state is partial, the attach dialog is * used to make it complete. isValidDebuggee must be true for the attach to continue. * * @param userEmail the user's email which corresponds to a login {@link CredentialedUser} * @param debuggeeId a String Id that represents a target application to debug (debuggee) * @param projectName a alpha-numeric String name identifying a GCP project that owns the target * debuggee * @param projectNumber a numeric String identifying the same GCP project that owns the target * debuggee * @param project the intelliJ IDE project */ public CloudDebugProcessState( @Nullable String userEmail, @Nullable String debuggeeId, @Nullable String projectName, @Nullable String projectNumber, @Nullable Project project) { setUserEmail(userEmail); setDebuggeeId(debuggeeId); setProjectName(projectName); setProjectNumber(projectNumber); setProject(project); setListenInBackground(false); }
public void setInputState(@Nullable CloudDebugProcessState inputState) { this.inputState = inputState; if (this.inputState != null && !Strings.isNullOrEmpty(this.inputState.getProjectName()) && !Strings.isNullOrEmpty(this.inputState.getUserEmail())) { Long projectNumber = null; if (!Strings.isNullOrEmpty(this.inputState.getProjectNumber())) { projectNumber = Long.parseLong(this.inputState.getProjectNumber()); } projectSelector.setSelectedProject( CloudProject.create( this.inputState.getProjectName(), // TODO(ivanporty) add separate project name/ID this.inputState.getProjectName(), projectNumber, this.inputState.getUserEmail())); // update the state here as well refreshDebugTargetList(projectSelector.getSelectedProject()); } }
@Test public void testPollForChanges_firesNotificationOnIOException() throws IOException { cloudDebugProcessState.setListenInBackground(true); cloudDebugProcessState.setUserEmail(FAKE_USER_EMAIL); cloudDebugProcessState.setDebuggeeId(FAKE_DEBUGGEE_ID); cloudDebugProcessState.setProject(getProject()); setupCloudDebuggerBackendMockWithException(FAKE_USER_EMAIL, new IOException()); cloudDebugGlobalPoller.pollForChanges(cloudDebugProcessState); assertFalse(cloudDebugProcessState.isListenInBackground()); verifyNotificationFired(); }
public void testSerialization() throws IOException { CloudDebugProcessState state = new CloudDebugProcessState("emailUser", "debuggeeId", "projectName", "projectNumber", null); Element element = XmlSerializer.serialize(state); state = XmlSerializer.deserialize(element, CloudDebugProcessState.class); assertNotNull(state); assertTrue("debuggeeId".equals(state.getDebuggeeId())); assertTrue("emailUser".equals(state.getUserEmail())); assertTrue("projectName".equals(state.getProjectName())); assertTrue("projectNumber".equals(state.getProjectNumber())); }
new CloudDebugProcessState(USER, DEBUGEE_ID, PROJECT_NAME, PROJECT_NUMBER, null); assertEquals(USER, state.getUserEmail()); CloudDebuggerClient.setClient(state.getUserEmail() + 120000, client); .setIncludeInactive(Boolean.TRUE); List<Breakpoint> currentList = state.getCurrentServerBreakpointList(); assertNotEmpty(currentList);
private XDebugSession createDebugSettingsAndAddToRunnerSettings( List<RunnerAndConfigurationSettings> runnerSettings, boolean isStopped, boolean hasDebugSession, Boolean listenInBackground) { CloudDebugRunConfiguration runConfiguration = mock(CloudDebugRunConfiguration.class); if (listenInBackground != null) { CloudDebugProcessState processState = new CloudDebugProcessState(); processState.setListenInBackground(listenInBackground); when(runConfiguration.getProcessState()).thenReturn(processState); } RunnerAndConfigurationSettings configurationSettings = mock(RunnerAndConfigurationSettings.class); when(configurationSettings.getConfiguration()).thenReturn(runConfiguration); runnerSettings.add(configurationSettings); if (hasDebugSession) { return createMockSession(isStopped, runConfiguration); } else { return null; } }
@Test public void testPollForChanges_firesNotificationIfNoDebugClientObtained() { cloudDebugProcessState.setListenInBackground(true); cloudDebugProcessState.setProject(getProject()); cloudDebugGlobalPoller.pollForChanges(cloudDebugProcessState); assertFalse(cloudDebugProcessState.isListenInBackground()); verifyNotificationFired(); }
new CloudDebugProcessState(); // Mockito.mock(CloudDebugProcessState.class); state.setUserEmail("mockUser@foo.com"); users.put(state.getUserEmail(), credentialedUser);
private void queryServerForBreakpoints(CloudDebugProcessState state, Debugger client) throws IOException { if (state.getDebuggeeId() == null) { throw new IllegalStateException("CloudDebugProcessState.getDebuggeeId() was null"); Breakpoints.List listRequest = breakpoints .list(state.getDebuggeeId()) .setIncludeInactive(Boolean.TRUE) .setActionValue("CAPTURE") .setStripResults(Boolean.TRUE) .setWaitToken(state.getWaitToken()); List<Breakpoint> currentList = response.getBreakpoints(); String responseWaitToken = response.getNextWaitToken(); state.setWaitToken(responseWaitToken); state.setCurrentServerBreakpointList( currentList != null ? ContainerUtil.immutableList(currentList)
return; List<Breakpoint> currentList = state.getCurrentServerBreakpointList(); for (Breakpoint serverBreakpointCandidate : currentList) { if (serverBreakpointCandidate.getId().equals(id) .debuggees() .breakpoints() .get(state.getDebuggeeId(), id) .setClientVersion( ServiceManager.getService(PluginInfoService.class)
@Transient public SyncResult checkSyncStashState() { if (processState.getProject() == null) { return new SyncResult( /*isInvalid*/ true, GitRepositoryManager manager = GitUtil.getRepositoryManager(processState.getProject()); List<GitRepository> repositories = manager.getRepositories(); CloudRepoSourceContext cloudRepo = null; && !com.google.common.base.Strings.isNullOrEmpty(processState.getProjectNumber())) { try { ListDebuggeesResponse debuggeesResponse = .debuggees() .list() .setProject(processState.getProjectNumber()) .setClientVersion( ServiceManager.getService(PluginInfoService.class) if (debuggeesResponse.getDebuggees() != null) { for (Debuggee debuggee : debuggeesResponse.getDebuggees()) { if (processState.getDebuggeeId() != null && processState.getDebuggeeId().equals(debuggee.getId())) { try { GitChangeUtils.resolveReference( processState.getProject(), repository.getRoot(), revisionId); targetLocalRepo = repository;
final Debugger client = CloudDebuggerClient.getShortTimeoutClient(state); if (client == null) { if (state.isListenInBackground()) { StackdriverDebuggerBundle.message( "clouddebug.background.listener.access.error.message", state.getProject().getName())); return; } else { String oldToken = state.getWaitToken(); String responseWaitToken = state.getWaitToken(); if (!Strings.isNullOrEmpty(responseWaitToken)) { changed = oldToken == null || !responseWaitToken.equals(oldToken);
.debuggees() .breakpoints() .list(state.getDebuggeeId()) .setIncludeInactive(Boolean.TRUE) .setActionValue("CAPTURE") state.setWaitToken(responseWaitToken); state.setCurrentServerBreakpointList( currentList != null ? ContainerUtil.immutableList(currentList)
/** * Returns a cloud debugger connection given {@link CloudDebugProcessState} to indicate the * credentials to use. The function may return null if the user is not logged in. TODO: Create a * better experience attaching when not logged in TODO: Handle cases where the user logs out in * the middle of a debug session. */ @Nullable public static Debugger getLongTimeoutClient(final @NotNull CloudDebugProcessState state) { return getClient(state.getUserEmail(), LONG_CONNECTION_TIMEOUT_MS); }
private void handleBreakpointQueryError(@NotNull CloudDebugProcessState state, String message) { state.setListenInBackground(false); String title = StackdriverDebuggerBundle.message("clouddebug.background.listener.error.title"); Notification notification = new Notification( CLOUD_DEBUGGER_ERROR_NOTIFICATIONS_DISPLAY_GROUP, title, message, NotificationType.ERROR); Notifications.Bus.notify(notification, state.getProject()); } }
@VisibleForTesting boolean listensInBackground(CloudDebugProcessState state) { return state != null && state.isListenInBackground(); } }