@Nullable public static ProgramRunner getRunner( @NotNull final String executorId, final RunnerAndConfigurationSettings configuration) { return configuration == null ? null : RunnerRegistry.getInstance().getRunner(executorId, configuration.getConfiguration()); }
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; }
@Override protected void hyperlinkActivated(HyperlinkEvent e) { final Module moduleByName = ModuleManager.getInstance(myProject).findModuleByName(e.getDescription()); if (moduleByName != null) { myConfiguration.getConfigurationModule().setModule(moduleByName); try { final Executor executor = myConsoleProperties.isDebug() ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance(); final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), myConfiguration); assert runner != null; runner.execute( executor, new ExecutionEnvironment( myConfiguration, myProject, getRunnerSettings(), getConfigurationSettings(), null)); final Balloon balloon = myToolWindowManager.getToolWindowBalloon(myTestRunDebugId); if (balloon != null) { balloon.hide(); } } catch (ExecutionException e1) { LOG.error(e1); } } }
@NotNull private static ExecutionEnvironmentBuilder createEnvironmentBuilder( @NotNull Project project, @NotNull Executor executor, @Nullable RunnerAndConfigurationSettings configuration) { ExecutionEnvironmentBuilder builder = new ExecutionEnvironmentBuilder(project, executor); ProgramRunner runner = RunnerRegistry.getInstance() .getRunner( executor.getId(), configuration != null ? configuration.getConfiguration() : null); if (runner == null && configuration != null) { LOG.error("Cannot find runner for " + configuration.getName()); } else if (runner != null) { assert configuration != null; builder.runnerAndSettings(runner, configuration); } return builder; }
@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)); }
void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) { MyRunProfile profile = getRunProfile(environment); if (profile == null) { return; } final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile); final InputEvent event = e.getInputEvent(); if (!(event instanceof MouseEvent) || !event.isShiftDown()) { performAction(environmentBuilder); return; } final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>(); for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) { final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile); if (runner != null) { availableRunners.put(ex, runner); } } if (availableRunners.isEmpty()) { LOG.error(environment.getExecutor().getActionName() + " is not available now"); } else if (availableRunners.size() == 1) { //noinspection ConstantConditions performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor()))); } else { final JBList list = new JBList(availableRunners.keySet()); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedValue(environment.getExecutor(), true); list.setCellRenderer( new DefaultListCellRenderer() { @NotNull @Override public Component getListCellRendererComponent( @NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Executor) { setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText())); setIcon(((Executor) value).getIcon()); } return component; } }); //noinspection ConstantConditions JBPopupFactory.getInstance() .createListPopupBuilder(list) .setTitle("Restart Failed Tests") .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback( () -> { final Object value = list.getSelectedValue(); if (value instanceof Executor) { //noinspection ConstantConditions performAction( environmentBuilder .runner(availableRunners.get(value)) .executor((Executor) value)); } }) .createPopup() .showUnderneathOf(event.getComponent()); } }
private void runConfigurations( final Executor executor, final List<RunConfiguration> runConfigurations, final int index) { if (index >= runConfigurations.size()) { stopRunningMultirunConfiguration.doneStaringConfigurations(); return; } if (!stopRunningMultirunConfiguration.canContinueStartingConfigurations()) { stopRunningMultirunConfiguration.doneStaringConfigurations(); // don't start more configurations if user stopped the plugin work. return; } final RunConfiguration runConfiguration = runConfigurations.get(index); final Project project = runConfiguration.getProject(); final RunnerAndConfigurationSettings configuration = new RunnerAndConfigurationSettingsImpl( RunManagerImpl.getInstanceImpl(project), runConfiguration, false); boolean started = false; try { ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), runConfiguration); if (runner == null) return; if (!checkRunConfiguration(executor, project, configuration)) return; runTriggers(executor, configuration); RunContentDescriptor runContentDescriptor = getRunContentDescriptor(runConfiguration, project); ExecutionEnvironment executionEnvironment = new ExecutionEnvironment( runner, DefaultExecutionTarget.INSTANCE, configuration, runContentDescriptor, project); runner.execute( executor, executionEnvironment, new ProgramRunner.Callback() { @SuppressWarnings("ConstantConditions") @Override public void processStarted(final RunContentDescriptor descriptor) { if (descriptor == null) { if (startOneByOne) { // start next configuration.. runConfigurations(executor, runConfigurations, index + 1); } return; } final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null) { processHandler.addProcessListener( new ProcessAdapter() { @SuppressWarnings("ConstantConditions") @Override public void startNotified(ProcessEvent processEvent) { Content content = descriptor.getAttachedContent(); if (content != null) { content.setIcon(descriptor.getIcon()); if (!stopRunningMultirunConfiguration .canContinueStartingConfigurations()) { // Multirun was stopped - destroy processes that are still starting up processHandler.destroyProcess(); if (!content.isPinned() && !startOneByOne) { // checks if not pinned, to avoid destroying already existed tab // checks if start one by one - no need to close the console tab, as // it's won't be shown // as other checks disallow starting it // content.getManager() can be null, if content is removed already as // part of destroy above if (content.getManager() != null) { content.getManager().removeContent(content, false); } } } else { // mark all current console tab as pinned content.setPinned(true); // mark running process tab with * content.setDisplayName(descriptor.getDisplayName() + "*"); } } } @Override public void processTerminated(final ProcessEvent processEvent) { onTermination(processEvent, true); } @Override public void processWillTerminate( ProcessEvent processEvent, boolean willBeDestroyed) { onTermination(processEvent, false); } private void onTermination( final ProcessEvent processEvent, final boolean terminated) { if (descriptor.getAttachedContent() == null) { return; } LaterInvocator.invokeLater( new Runnable() { @Override public void run() { final Content content = descriptor.getAttachedContent(); if (content == null) return; // exit code is 0 if the process completed successfully final boolean completedSuccessfully = (terminated && processEvent.getExitCode() == 0); if (hideSuccessProcess && completedSuccessfully) { // close the tab for the success process and exit - nothing else // could be done if (content.getManager() != null) { content.getManager().removeContent(content, false); return; } } if (!separateTabs && completedSuccessfully) { // un-pin the console tab if re-use is allowed and process // completed successfully, // so the tab could be re-used for other processes content.setPinned(false); } // remove the * used to identify running process content.setDisplayName(descriptor.getDisplayName()); // add the alert icon in case if process existed with non-0 status if (markFailedProcess && processEvent.getExitCode() != 0) { LaterInvocator.invokeLater( new Runnable() { @Override public void run() { content.setIcon( LayeredIcon.create( content.getIcon(), AllIcons.Nodes.TabAlert)); } }); } } }); } }); } stopRunningMultirunConfiguration.addProcess(project, processHandler); if (startOneByOne) { // start next configuration.. runConfigurations(executor, runConfigurations, index + 1); } } }); started = true; } catch (ExecutionException e) { ExecutionUtil.handleExecutionError( project, executor.getToolWindowId(), configuration.getConfiguration(), e); } finally { // start the next one if (!startOneByOne) { runConfigurations(executor, runConfigurations, index + 1); } else if (!started) { // failed to start current, means the chain is broken runConfigurations(executor, runConfigurations, index + 1); } } }