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));
 }
  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 void reset() {
   RunnerAndConfigurationSettings configuration = getSettings();
   if (configuration != null) {
     setNameText(configuration.getName());
   }
   super.reset();
 }
 @NotNull
 public static Icon getRawIcon(RunnerAndConfigurationSettings settings) {
   RunConfiguration configuration = settings.getConfiguration();
   ConfigurationFactory factory = settings.getFactory();
   Icon icon = factory != null ? factory.getIcon(configuration) : null;
   if (icon == null) icon = AllIcons.RunConfigurations.Unknown;
   return icon;
 }
Example #5
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 #7
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
   }
 }
 @Nullable
 public static ExecutionEnvironmentBuilder createEnvironment(
     @NotNull Executor executor, @NotNull RunnerAndConfigurationSettings settings) {
   try {
     return ExecutionEnvironmentBuilder.create(executor, settings);
   } catch (ExecutionException e) {
     handleExecutionError(
         settings.getConfiguration().getProject(),
         executor.getToolWindowId(),
         settings.getConfiguration().getName(),
         e);
     return null;
   }
 }
 @Nullable
 public static ProgramRunner getRunner(
     @NotNull final String executorId, final RunnerAndConfigurationSettings configuration) {
   return configuration == null
       ? null
       : RunnerRegistry.getInstance().getRunner(executorId, configuration.getConfiguration());
 }
 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);
 }
 public static void runConfiguration(
     @NotNull RunnerAndConfigurationSettings configuration, @NotNull Executor executor) {
   ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration);
   if (builder != null) {
     ExecutionManager.getInstance(configuration.getConfiguration().getProject())
         .restartRunProfile(builder.activeTarget().build());
   }
 }
Example #13
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 #14
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;
  }
  @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 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);
   }
 }
  public static Icon getConfigurationIcon(
      final RunnerAndConfigurationSettings settings, final boolean invalid) {
    Icon icon = getRawIcon(settings);

    final Icon configurationIcon = settings.isTemporary() ? getTemporaryIcon(icon) : icon;
    if (invalid) {
      return LayeredIcon.create(
          configurationIcon, AllIcons.RunConfigurations.InvalidConfigurationLayer);
    }

    return configurationIcon;
  }
 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 #19
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));
  }
 @NotNull
 private List<RunContentDescriptor> getIncompatibleRunningDescriptors(
     @NotNull RunnerAndConfigurationSettings configurationAndSettings) {
   final RunConfiguration configurationToCheckCompatibility =
       configurationAndSettings.getConfiguration();
   return getRunningDescriptors(
       runningConfigurationAndSettings -> {
         RunConfiguration runningConfiguration =
             runningConfigurationAndSettings == null
                 ? null
                 : runningConfigurationAndSettings.getConfiguration();
         if (runningConfiguration == null
             || !(runningConfiguration instanceof CompatibilityAwareRunProfile)) {
           return false;
         }
         return ((CompatibilityAwareRunProfile) runningConfiguration)
             .mustBeStoppedToRun(configurationToCheckCompatibility);
       });
 }
  @Override
  public void restartRunProfile(@NotNull final ExecutionEnvironment environment) {
    RunnerAndConfigurationSettings configuration = environment.getRunnerAndConfigurationSettings();

    List<RunContentDescriptor> runningIncompatible;
    if (configuration == null) {
      runningIncompatible = Collections.emptyList();
    } else {
      runningIncompatible = getIncompatibleRunningDescriptors(configuration);
    }

    RunContentDescriptor contentToReuse = environment.getContentToReuse();
    final List<RunContentDescriptor> runningOfTheSameType = new SmartList<>();
    if (configuration != null && configuration.isSingleton()) {
      runningOfTheSameType.addAll(getRunningDescriptorsOfTheSameConfigType(configuration));
    } else if (isProcessRunning(contentToReuse)) {
      runningOfTheSameType.add(contentToReuse);
    }

    List<RunContentDescriptor> runningToStop =
        ContainerUtil.concat(runningOfTheSameType, runningIncompatible);
    if (!runningToStop.isEmpty()) {
      if (configuration != null) {
        if (!runningOfTheSameType.isEmpty()
            && (runningOfTheSameType.size() > 1
                || contentToReuse == null
                || runningOfTheSameType.get(0) != contentToReuse)
            && !userApprovesStopForSameTypeConfigurations(
                environment.getProject(), configuration.getName(), runningOfTheSameType.size())) {
          return;
        }
        if (!runningIncompatible.isEmpty()
            && !userApprovesStopForIncompatibleConfigurations(
                myProject, configuration.getName(), runningIncompatible)) {
          return;
        }
      }

      for (RunContentDescriptor descriptor : runningToStop) {
        stop(descriptor);
      }
    }

    if (myAwaitingRunProfiles.get(environment.getRunProfile()) == environment) {
      // defense from rerunning exactly the same ExecutionEnvironment
      return;
    }
    myAwaitingRunProfiles.put(environment.getRunProfile(), environment);

    awaitTermination(
        new Runnable() {
          @Override
          public void run() {
            if (myAwaitingRunProfiles.get(environment.getRunProfile()) != environment) {
              // a new rerun has been requested before starting this one, ignore this rerun
              return;
            }
            if ((DumbService.getInstance(myProject).isDumb()
                    && !Registry.is("dumb.aware.run.configurations"))
                || ExecutorRegistry.getInstance().isStarting(environment)) {
              awaitTermination(this, 100);
              return;
            }

            for (RunContentDescriptor descriptor : runningOfTheSameType) {
              ProcessHandler processHandler = descriptor.getProcessHandler();
              if (processHandler != null && !processHandler.isProcessTerminated()) {
                awaitTermination(this, 100);
                return;
              }
            }
            myAwaitingRunProfiles.remove(environment.getRunProfile());
            start(environment);
          }
        },
        50);
  }
  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);
    }
  }
 private static void start(@NotNull ExecutionEnvironment environment) {
   RunnerAndConfigurationSettings settings = environment.getRunnerAndConfigurationSettings();
   ProgramRunnerUtil.executeConfiguration(
       environment, settings != null && settings.isEditBeforeRun(), true);
 }