public void restart() { final Project project = PlatformDataKeys.PROJECT.getData( DataManager.getInstance().getDataContext(myDescriptor.getComponent())); if (ExecutorRegistry.getInstance() .isStarting(project, myExecutor.getId(), myRunner.getRunnerId())) { return; } try { final ExecutionEnvironment old = myEnvironment; myRunner.execute( myExecutor, new ExecutionEnvironment( old.getRunProfile(), old.getExecutionTarget(), project, old.getRunnerSettings(), old.getConfigurationSettings(), myDescriptor, old.getRunnerAndConfigurationSettings())); } catch (RunCanceledByUserException ignore) { } catch (ExecutionException e1) { Messages.showErrorDialog( project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title")); } }
private ValidationResult getValidationResult() { if (!myValidationResultValid) { myLastValidationResult = null; try { RunnerAndConfigurationSettings snapshot = getSnapshot(); if (snapshot != null) { snapshot.setName(getNameText()); snapshot.checkSettings(); for (ProgramRunner runner : RunnerRegistry.getInstance().getRegisteredRunners()) { for (Executor executor : ExecutorRegistry.getInstance().getRegisteredExecutors()) { if (runner.canRun(executor.getId(), snapshot.getConfiguration())) { checkConfiguration(runner, snapshot); break; } } } } } catch (RuntimeConfigurationException exception) { myLastValidationResult = exception != null ? new ValidationResult( exception.getLocalizedMessage(), exception.getTitle(), exception.getQuickFix()) : null; } catch (ConfigurationException e) { myLastValidationResult = new ValidationResult( e.getLocalizedMessage(), ExecutionBundle.message("invalid.data.dialog.title"), null); } myValidationResultValid = true; } return myLastValidationResult; }
public ImportRunProfile(VirtualFile file, Project project) { myFile = file; myProject = project; try { final Document document = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(myFile)); final Element config = document.getRootElement().getChild("config"); if (config != null) { String configTypeId = config.getAttributeValue("configId"); if (configTypeId != null) { final ConfigurationType configurationType = ConfigurationTypeUtil.findConfigurationType(configTypeId); if (configurationType != null) { myConfiguration = configurationType.getConfigurationFactories()[0].createTemplateConfiguration( project); myConfiguration.setName(config.getAttributeValue("name")); myConfiguration.readExternal(config); final Executor executor = ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); if (executor != null) { if (myConfiguration instanceof SMRunnerConsolePropertiesProvider) { myProperties = ((SMRunnerConsolePropertiesProvider) myConfiguration) .createTestConsoleProperties(executor); } } } } } } catch (Exception ignore) { } }
boolean isEnabled() { ProcessHandler processHandler = myDescriptor.getProcessHandler(); boolean isTerminating = processHandler != null && processHandler.isProcessTerminating(); boolean isStarting = ExecutorRegistry.getInstance() .isStarting(myEnvironment.getProject(), myExecutor.getId(), myRunner.getRunnerId()); return !isStarting && !isTerminating; }
private void initConsoleUI(Process process) { // Init console view myConsoleView = createConsoleView(); myConsoleView.setBorder(new SideBorder(UIUtil.getBorderColor(), SideBorder.LEFT)); myProcessHandler = createProcessHandler(process, myProvider.getCommandLineString()); myConsoleExecuteActionHandler = createConsoleExecuteActionHandler(); ProcessTerminatedListener.attach(myProcessHandler); myProcessHandler.addProcessListener( new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { finishConsole(); } }); // Attach to process myConsoleView.attachToProcess(myProcessHandler); // Runner creating final Executor defaultExecutor = ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); final DefaultActionGroup toolbarActions = new DefaultActionGroup(); final ActionToolbar actionToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false); // Runner creating final JPanel panel = new JPanel(new BorderLayout()); panel.add(actionToolbar.getComponent(), BorderLayout.WEST); panel.add(myConsoleView.getComponent(), BorderLayout.CENTER); actionToolbar.setTargetComponent(panel); final RunContentDescriptor contentDescriptor = new RunContentDescriptor( myConsoleView, myProcessHandler, panel, constructConsoleTitle(myConsoleTitle)); // tool bar actions final List<AnAction> actions = fillToolBarActions(toolbarActions, defaultExecutor, contentDescriptor); registerActionShortcuts(actions, getLanguageConsole().getConsoleEditor().getComponent()); registerActionShortcuts(actions, panel); panel.updateUI(); showConsole(defaultExecutor, contentDescriptor); // Run myProcessHandler.startNotify(); }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); LOG.assertTrue(project != null); final VirtualFile file = getFile(project); if (file != null) { try { final ImportRunProfile profile = new ImportRunProfile(file, project); SMTRunnerConsoleProperties properties = profile.getProperties(); if (properties == null) { properties = myProperties; LOG.info( "Failed to detect test framework in " + file.getPath() + "; use " + (properties != null ? properties.getTestFrameworkName() + " from toolbar" : "no properties")); } final Executor executor = properties != null ? properties.getExecutor() : ExecutorRegistry.getInstance().getExecutorById(DefaultRunExecutor.EXECUTOR_ID); ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(project, executor, profile); final RunConfiguration initialConfiguration = profile.getInitialConfiguration(); final ProgramRunner runner = initialConfiguration != null ? RunnerRegistry.getInstance().getRunner(executor.getId(), initialConfiguration) : null; if (runner != null) { builder = builder.runner(runner); } builder.buildAndExecute(); } catch (ExecutionException e1) { Messages.showErrorDialog(project, e1.getMessage(), "Import Failed"); } } }
@Nullable public static Pair<ProgramRunner, ExecutionEnvironment> createRunner( @NotNull ExternalSystemTaskExecutionSettings taskSettings, @NotNull String executorId, @NotNull Project project, @NotNull ProjectSystemId externalSystemId) { Executor executor = ExecutorRegistry.getInstance().getExecutorById(executorId); if (executor == null) return null; String runnerId = getRunnerId(executorId); if (runnerId == null) return null; ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(runnerId); if (runner == null) return null; AbstractExternalSystemTaskConfigurationType configurationType = findConfigurationType(externalSystemId); if (configurationType == null) return null; String name = AbstractExternalSystemTaskConfigurationType.generateName(project, taskSettings); RunnerAndConfigurationSettings settings = RunManager.getInstance(project) .createRunConfiguration(name, configurationType.getFactory()); ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) settings.getConfiguration(); runConfiguration.getSettings().setExternalProjectPath(taskSettings.getExternalProjectPath()); runConfiguration .getSettings() .setTaskNames(ContainerUtil.newArrayList(taskSettings.getTaskNames())); runConfiguration .getSettings() .setTaskDescriptions(ContainerUtil.newArrayList(taskSettings.getTaskDescriptions())); runConfiguration.getSettings().setVmOptions(taskSettings.getVmOptions()); runConfiguration.getSettings().setScriptParameters(taskSettings.getScriptParameters()); runConfiguration.getSettings().setExecutionName(taskSettings.getExecutionName()); return Pair.create(runner, new ExecutionEnvironment(executor, runner, settings, project)); }
public static void restart(@NotNull ExecutionEnvironment environment) { if (!ExecutorRegistry.getInstance().isStarting(environment)) { ExecutionManager.getInstance(environment.getProject()).restartRunProfile(environment); } }
public static void executeConfiguration( @NotNull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) { if (ExecutorRegistry.getInstance().isStarting(environment)) { return; } RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings(); if (runnerAndConfigurationSettings != null) { if (!ExecutionTargetManager.canRun(environment)) { ExecutionUtil.handleExecutionError( environment, new ExecutionException( StringUtil.escapeXml( "Cannot run '" + environment.getRunProfile().getName() + "' on '" + environment.getExecutionTarget().getDisplayName() + "'"))); return; } if (!RunManagerImpl.canRunConfiguration(environment) || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } while (!RunManagerImpl.canRunConfiguration(environment)) { if (Messages.YES == Messages.showYesNoDialog( environment.getProject(), "Configuration is still incorrect. Do you want to edit it again?", "Change Configuration Settings", "Edit", "Continue Anyway", Messages.getErrorIcon())) { if (!RunDialog.editConfiguration(environment, "Edit configuration")) { return; } } else { break; } } } ConfigurationType configurationType = runnerAndConfigurationSettings.getType(); if (configurationType != null) { UsageTrigger.trigger( "execute." + ConvertUsagesUtil.ensureProperKey(configurationType.getId()) + "." + environment.getExecutor().getId()); } } try { if (assignNewId) { environment.assignNewExecutionId(); } environment.getRunner().execute(environment); } catch (ExecutionException e) { String name = runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null; if (name == null) { name = environment.getRunProfile().getName(); } if (name == null && environment.getContentToReuse() != null) { name = environment.getContentToReuse().getDisplayName(); } if (name == null) { name = "<Unknown>"; } ExecutionUtil.handleExecutionError( environment.getProject(), environment.getExecutor().getToolWindowId(), name, e); } }