Example #1
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));
 }
 public void reset() {
   RunnerAndConfigurationSettings configuration = getSettings();
   if (configuration != null) {
     setNameText(configuration.getName());
   }
   super.reset();
 }
  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;
  }
Example #4
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());
 }
 @Nullable
 private static RunnerAndConfigurationSettings chooseTempSettings(@NotNull Project project) {
   RunnerAndConfigurationSettings selectedConfiguration =
       RunManager.getInstance(project).getSelectedConfiguration();
   if (selectedConfiguration != null && selectedConfiguration.isTemporary()) {
     return selectedConfiguration;
   }
   Iterator<RunnerAndConfigurationSettings> iterator =
       RunManager.getInstance(project).getTempConfigurationsList().iterator();
   return iterator.hasNext() ? iterator.next() : null;
 }
Example #6
0
 @Override
 public void writeExternal(Element element) {
   super.writeExternal(element);
   if (myConfigurationName != null && myConfigurationType != null) {
     element.setAttribute("run_configuration_name", myConfigurationName);
     element.setAttribute("run_configuration_type", myConfigurationType);
   } else if (mySettings != null) {
     element.setAttribute("run_configuration_name", mySettings.getName());
     element.setAttribute("run_configuration_type", mySettings.getType().getId());
   }
 }
 private static void checkConfiguration(
     final ProgramRunner runner, final RunnerAndConfigurationSettings snapshot)
     throws RuntimeConfigurationException {
   final RunnerSettings runnerSettings = snapshot.getRunnerSettings(runner);
   final ConfigurationPerRunnerSettings configurationSettings =
       snapshot.getConfigurationSettings(runner);
   try {
     runner.checkConfiguration(runnerSettings, configurationSettings);
   } catch (AbstractMethodError e) {
     // backward compatibility
   }
 }
 public SelectConfigAction(
     final RunnerAndConfigurationSettings configuration, final Project project) {
   myConfiguration = configuration;
   myProject = project;
   String name = configuration.getName();
   if (name == null || name.length() == 0) {
     name = " ";
   }
   final Presentation presentation = getTemplatePresentation();
   presentation.setText(name, false);
   final ConfigurationType type = configuration.getType();
   if (type != null) {
     presentation.setDescription(
         "Select " + type.getConfigurationTypeDescription() + " '" + name + "'");
   }
   updateIcon(presentation);
 }
Example #9
0
 void init() {
   if (myInitialized) {
     return;
   }
   if (myConfigurationName != null && myConfigurationType != null) {
     Collection<RunnerAndConfigurationSettings> configurations =
         RunManagerImpl.getInstanceImpl(myProject).getSortedConfigurations();
     for (RunnerAndConfigurationSettings runConfiguration : configurations) {
       ConfigurationType type = runConfiguration.getType();
       if (myConfigurationName.equals(runConfiguration.getName())
           && type != null
           && myConfigurationType.equals(type.getId())) {
         setSettings(runConfiguration);
         return;
       }
     }
   }
 }
Example #10
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;
  }
 @Override
 public void update(final AnActionEvent e) {
   final Presentation presentation = e.getPresentation();
   final Project project = e.getData(CommonDataKeys.PROJECT);
   if (project == null) {
     disable(presentation);
     return;
   }
   RunnerAndConfigurationSettings settings = chooseTempSettings(project);
   if (settings == null) {
     disable(presentation);
   } else {
     presentation.setText(
         ExecutionBundle.message(
             "save.temporary.run.configuration.action.name", settings.getName()));
     presentation.setDescription(presentation.getText());
     presentation.setVisible(true);
     presentation.setEnabled(true);
   }
 }
 private static void updatePresentation(
     @Nullable ExecutionTarget target,
     @Nullable RunnerAndConfigurationSettings settings,
     @Nullable Project project,
     @NotNull Presentation presentation) {
   if (project != null && target != null && settings != null) {
     String name = settings.getName();
     if (target != DefaultExecutionTarget.INSTANCE) {
       name += " | " + target.getDisplayName();
     } else {
       if (!settings.canRunOn(target)) {
         name += " | Nothing to run on";
       }
     }
     presentation.setText(name, false);
     setConfigurationIcon(presentation, settings, project);
   } else {
     presentation.setText(""); // IDEA-21657
     presentation.setIcon(null);
   }
 }
Example #13
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));
  }