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;
  }
示例#2
0
 private SelectionDialog(
     RunnerAndConfigurationSettings selectedSettings,
     @NotNull List<RunnerAndConfigurationSettings> settings) {
   super(myProject);
   setTitle(ExecutionBundle.message("before.launch.run.another.configuration.choose"));
   mySelectedSettings = selectedSettings;
   mySettings = settings;
   init();
   myJBList.setSelectedValue(mySelectedSettings, true);
   myJBList.addMouseListener(
       new MouseAdapter() {
         @Override
         public void mouseClicked(MouseEvent e) {
           if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
             doOKAction();
           }
         }
       });
   FontMetrics fontMetrics = myJBList.getFontMetrics(myJBList.getFont());
   int maxWidth = fontMetrics.stringWidth("m") * 30;
   for (RunnerAndConfigurationSettings setting : settings) {
     maxWidth =
         Math.max(fontMetrics.stringWidth(setting.getConfiguration().getName()), maxWidth);
   }
   maxWidth += 24; // icon and gap
   myJBList.setMinimumSize(new Dimension(maxWidth, myJBList.getPreferredSize().height));
 }
示例#3
0
 @Override
 public boolean canExecuteTask(RunConfiguration configuration, RunConfigurableBeforeRunTask task) {
   RunnerAndConfigurationSettings settings = task.getSettings();
   if (settings == null) {
     return false;
   }
   String executorId = DefaultRunExecutor.getRunExecutorInstance().getId();
   final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings);
   return runner != null && runner.canRun(executorId, settings.getConfiguration());
 }
示例#4
0
  @NotNull
  private static List<RunnerAndConfigurationSettings> getAvailableConfigurations(
      RunConfiguration runConfiguration) {
    Project project = runConfiguration.getProject();
    if (project == null || !project.isInitialized()) return Collections.emptyList();
    final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);

    final ArrayList<RunnerAndConfigurationSettings> configurations =
        new ArrayList<RunnerAndConfigurationSettings>(runManager.getSortedConfigurations());
    String executorId = DefaultRunExecutor.getRunExecutorInstance().getId();
    for (Iterator<RunnerAndConfigurationSettings> iterator = configurations.iterator();
        iterator.hasNext(); ) {
      RunnerAndConfigurationSettings settings = iterator.next();
      final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings);
      if (runner == null || settings.getConfiguration() == runConfiguration) iterator.remove();
    }
    return configurations;
  }
示例#5
0
  @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));
  }