@Override public RunConfiguration createTemplateConfiguration(final Project project) { return new CloudDebugRunConfiguration(project, this); } }
@Override protected void resetEditorFrom(@NotNull CloudDebugRunConfiguration runConfiguration) { String projectId = runConfiguration.getCloudProjectId(); // google username may be empty from previous revisions of configurations, should not be null. String googleUsername = Optional.ofNullable(runConfiguration.getGoogleUsername()).orElse(""); if (!Strings.isNullOrEmpty(projectId)) { settingsPanel.setSelectedCloudProject( CloudProject.create( // TODO(ivanporty) no project name in CloudDebugRunConfiguration. projectId /* as name */, projectId, null /* project number */, googleUsername)); } else { settingsPanel.loadActiveCloudProject(); } } }
@NotNull @Override public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() { return new CloudDebugSettingsEditor(getProject()); }
@Override protected void applyEditorTo(@NotNull CloudDebugRunConfiguration runConfiguration) { runConfiguration.setCloudProjectId( Optional.ofNullable(settingsPanel.getSelectedCloudProject()) .map(CloudProject::projectId) .orElse(null)); runConfiguration.setGoogleUsername( Optional.ofNullable(settingsPanel.getSelectedCloudProject()) .map(CloudProject::googleUsername) .orElse(null)); }
@Override public final RunConfiguration clone() { // clone is called for both creation of run configuration and duplication. New run // configurations are cloned from the configuration factory's instance if (this == RunManager.getInstance(getProject()) .getConfigurationTemplate(this.getFactory()) .getConfiguration()) { UsageTrackerService.getInstance() .trackEvent(GctTracking.CLOUD_DEBUGGER_NEW_RUN_CONFIG) .ping(); } final CloudDebugRunConfiguration configuration = (CloudDebugRunConfiguration) super.clone(); configuration.setCloudProjectId(getCloudProjectId()); return configuration; }
private List<CloudDebugProcessState> getBackgroundDebugStates(Project project) { List<CloudDebugProcessState> states = Lists.newArrayList(); RunManager manager = RunManager.getInstance(project); for (final RunnerAndConfigurationSettings config : manager.getAllSettings()) { if (config.getConfiguration() instanceof CloudDebugRunConfiguration) { final CloudDebugRunConfiguration cloudConfig = (CloudDebugRunConfiguration) config.getConfiguration(); CloudDebugProcessState processState = cloudConfig.getProcessState(); if (processState != null && processState.isListenInBackground()) { states.add(processState); } } } return states; }
private void setupDebugRunConfiguration(@NotNull Project project) { RunManager runManager = RunManager.getInstance(project); boolean hasExistingDebugConfiguration = runManager .getAllConfigurationsList() .stream() .anyMatch(config -> config instanceof CloudDebugRunConfiguration); if (!hasExistingDebugConfiguration) { CloudDebugConfigType debugConfigType = CloudDebugConfigType.getInstance(); ConfigurationFactory factory = debugConfigType.getConfigurationFactories()[0]; RunnerAndConfigurationSettings settings = runManager.createConfiguration( new CloudDebugRunConfiguration(project, factory).clone(), factory); runManager.addConfiguration(settings, false /*isShared*/); } } }
/** * Enumerates all runconfigurations in this project and returns a serialized form of their process * states. * * @return a serialized form of the debuggee state as known to the client */ @Nullable @Override public CloudDebugProcessStateSerializer.ProjectState getState() { ProjectState projectState = new ProjectState(); if (CloudDebugConfigType.isFeatureEnabled()) { RunManager manager = RunManager.getInstance(project); for (RunnerAndConfigurationSettings config : manager.getAllSettings()) { if (config.getConfiguration() == null) { continue; } if (config.getConfiguration() instanceof CloudDebugRunConfiguration) { final CloudDebugRunConfiguration cloudConfig = (CloudDebugRunConfiguration) config.getConfiguration(); final CloudDebugProcessState state = cloudConfig.getProcessState(); if (state != null) { projectState.configStates.add(new RunConfigState(cloudConfig.getName(), state)); } } } } return projectState; }
@Override public void readExternal(Element element) throws InvalidDataException { super.readExternal(element); Optional.ofNullable(element.getAttribute(PROJECT_NAME_TAG)) .map(Attribute::getValue) .ifPresent(this::setCloudProjectId); Optional.ofNullable(element.getAttribute(GOOGLE_USERNAME_TAG)) .map(Attribute::getValue) .ifPresent(this::setGoogleUsername); // Call out to the state serializer to get process state out of workspace.xml. if (!Strings.isNullOrEmpty(cloudProjectId) && !Strings.isNullOrEmpty(getName())) { processState = CloudDebugProcessStateSerializer.getInstance(getProject()) .getState(getName(), cloudProjectId); } CloudDebugProcessWatcher.getInstance().ensureWatcher(); }
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; } }
/** Get all the background snapshot states. */ public List<CloudDebugProcessState> getBackgroundListeningStates() { List<CloudDebugProcessState> states = new ArrayList<CloudDebugProcessState>(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { Set<RunProfile> runningProfiles = getProfilesWithActiveDebugSession(project); RunManager manager = RunManager.getInstance(project); // find all CloudDebugRunConfiguration that do not have active debug sessions but are // listening in the background for (final RunnerAndConfigurationSettings config : manager.getAllSettings()) { if (notRunningConfiguration(runningProfiles, config.getConfiguration())) { if (config.getConfiguration() instanceof CloudDebugRunConfiguration) { final CloudDebugRunConfiguration cloudConfig = (CloudDebugRunConfiguration) config.getConfiguration(); CloudDebugProcessState state = cloudConfig.getProcessState(); if (listensInBackground(state)) { states.add(state); } } } } } return states; }
/** * 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; }