private void updateText() {
    StringBuilder sb = new StringBuilder();

    if (myShowSettingsBeforeRunCheckBox.isSelected()) {
      sb.append(ExecutionBundle.message("configuration.edit.before.run")).append(", ");
    }

    List<BeforeRunTask> tasks = myModel.getItems();
    if (!tasks.isEmpty()) {
      LinkedHashMap<BeforeRunTaskProvider, Integer> counter =
          new LinkedHashMap<BeforeRunTaskProvider, Integer>();
      for (BeforeRunTask task : tasks) {
        BeforeRunTaskProvider<BeforeRunTask> provider =
            BeforeRunTaskProvider.getProvider(
                myRunConfiguration.getProject(), task.getProviderId());
        if (provider != null) {
          Integer count = counter.get(provider);
          if (count == null) {
            count = task.getItemsCount();
          } else {
            count += task.getItemsCount();
          }
          counter.put(provider, count);
        }
      }
      for (Iterator<Map.Entry<BeforeRunTaskProvider, Integer>> iterator =
              counter.entrySet().iterator();
          iterator.hasNext(); ) {
        Map.Entry<BeforeRunTaskProvider, Integer> entry = iterator.next();
        BeforeRunTaskProvider provider = entry.getKey();
        String name = provider.getName();
        if (name.startsWith("Run ")) {
          name = name.substring(4);
        }
        sb.append(name);
        if (entry.getValue() > 1) {
          sb.append(" (").append(entry.getValue().intValue()).append(")");
        }
        if (iterator.hasNext()) sb.append(", ");
      }
    }
    if (sb.length() > 0) {
      sb.insert(0, ": ");
    }
    sb.insert(0, ExecutionBundle.message("before.launch.panel.title"));
    myListener.titleChanged(sb.toString());
  }
 private Set<Key> getActiveProviderKeys() {
   Set<Key> result = new HashSet<Key>();
   for (BeforeRunTask task : myModel.getItems()) {
     result.add(task.getProviderId());
   }
   return result;
 }
  @Override
  public void compileAndRun(
      @NotNull final Runnable startRunnable,
      @NotNull final ExecutionEnvironment environment,
      @Nullable final RunProfileState state,
      @Nullable final Runnable onCancelRunnable) {
    long id = environment.getExecutionId();
    if (id == 0) {
      id = environment.assignNewExecutionId();
    }

    RunProfile profile = environment.getRunProfile();
    if (!(profile instanceof RunConfiguration)) {
      startRunnable.run();
      return;
    }

    final RunConfiguration runConfiguration = (RunConfiguration) profile;
    final List<BeforeRunTask> beforeRunTasks =
        RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
    if (beforeRunTasks.isEmpty()) {
      startRunnable.run();
    } else {
      DataContext context = environment.getDataContext();
      final DataContext projectContext =
          context != null ? context : SimpleDataContext.getProjectContext(myProject);
      final long finalId = id;
      final Long executionSessionId = new Long(id);
      ApplicationManager.getApplication()
          .executeOnPooledThread(
              () -> {
                for (BeforeRunTask task : beforeRunTasks) {
                  if (myProject.isDisposed()) {
                    return;
                  }
                  @SuppressWarnings("unchecked")
                  BeforeRunTaskProvider<BeforeRunTask> provider =
                      BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
                  if (provider == null) {
                    LOG.warn(
                        "Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'");
                    continue;
                  }
                  ExecutionEnvironment taskEnvironment =
                      new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build();
                  taskEnvironment.setExecutionId(finalId);
                  EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId);
                  if (!provider.executeTask(
                      projectContext, runConfiguration, taskEnvironment, task)) {
                    if (onCancelRunnable != null) {
                      SwingUtilities.invokeLater(onCancelRunnable);
                    }
                    return;
                  }
                }

                doRun(environment, startRunnable);
              });
    }
  }
 @Nullable
 private Pair<BeforeRunTask, BeforeRunTaskProvider<BeforeRunTask>> getSelection() {
   final int index = myList.getSelectedIndex();
   if (index == -1) return null;
   BeforeRunTask task = myModel.getElementAt(index);
   Key providerId = task.getProviderId();
   BeforeRunTaskProvider<BeforeRunTask> provider =
       BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), providerId);
   return provider != null ? Pair.create(task, provider) : null;
 }
 @Override
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
   if (value instanceof BeforeRunTask) {
     BeforeRunTask task = (BeforeRunTask) value;
     BeforeRunTaskProvider<BeforeRunTask> provider =
         BeforeRunTaskProvider.getProvider(
             myRunConfiguration.getProject(), task.getProviderId());
     if (provider != null) {
       setIcon(provider.getTaskIcon(task));
       setText(provider.getDescription(task));
     }
   }
   return this;
 }
Example #6
0
 @Override
 public void readExternal(Element element) {
   super.readExternal(element);
   Attribute configurationNameAttr = element.getAttribute("run_configuration_name");
   Attribute configurationTypeAttr = element.getAttribute("run_configuration_type");
   myConfigurationName = configurationNameAttr != null ? configurationNameAttr.getValue() : null;
   myConfigurationType = configurationTypeAttr != null ? configurationTypeAttr.getValue() : null;
 }
  @Override
  public boolean configureTask(
      RunConfiguration runConfiguration,
      KevAnnotationProcessorBeforeRunTask kevAnnotationProcessorBeforeRunTask) {
    System.out.println("KevScriptBeforeTask configureTask");
    if (!this.getName().equals("KevScriptDevRunnerTemplate")) {
      // RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(getProject());
      // RunManager.getInstance(getProject()).
      RunManagerEx runManager = RunManagerImpl.getInstanceEx(myProject);

      List<BeforeRunTask> list = runManager.getBeforeRunTasks(runConfiguration);
      KevBeforeRunTaskProvider prov = new KevBeforeRunTaskProvider(myProject);
      list.add(prov.createTask(runConfiguration));
      for (BeforeRunTask t : list) {
        System.out.println("Before Run Task:" + t.toString());
      }
      runManager.setBeforeRunTasks(runConfiguration, list, true);
    }
    return true;
  }
Example #8
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());
   }
 }