Search in sources :

Example 1 with BeforeRunTaskProvider

use of com.intellij.execution.BeforeRunTaskProvider in project intellij-community by JetBrains.

the class BeforeRunStepsPanel method updateText.

private void updateText() {
    StringBuilder sb = new StringBuilder();
    if (myShowSettingsBeforeRunCheckBox.isSelected()) {
        sb.append(ExecutionBundle.message("configuration.edit.before.run"));
    }
    List<BeforeRunTask> tasks = myModel.getItems();
    if (!tasks.isEmpty()) {
        LinkedHashMap<BeforeRunTaskProvider, Integer> counter = new LinkedHashMap<>();
        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();
            name = StringUtil.trimStart(name, "Run ");
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(name);
            if (entry.getValue() > 1) {
                sb.append(" (").append(entry.getValue().intValue()).append(")");
            }
        }
    }
    if (myActivateToolWindowBeforeRunCheckBox.isSelected()) {
        sb.append(sb.length() > 0 ? ", " : "").append(ExecutionBundle.message("configuration.activate.toolwindow.before.run"));
    }
    if (sb.length() > 0) {
        sb.insert(0, ": ");
    }
    sb.insert(0, ExecutionBundle.message("before.launch.panel.title"));
    myListener.titleChanged(sb.toString());
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider)

Example 2 with BeforeRunTaskProvider

use of com.intellij.execution.BeforeRunTaskProvider in project intellij-community by JetBrains.

the class BeforeRunStepsPanel method doAddAction.

void doAddAction(AnActionButton button) {
    if (isUnknown()) {
        return;
    }
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    final BeforeRunTaskProvider<BeforeRunTask>[] providers = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myRunConfiguration.getProject());
    Set<Key> activeProviderKeys = getActiveProviderKeys();
    DefaultActionGroup actionGroup = new DefaultActionGroup(null, false);
    for (final BeforeRunTaskProvider<BeforeRunTask> provider : providers) {
        if (provider.createTask(myRunConfiguration) == null)
            continue;
        if (activeProviderKeys.contains(provider.getId()) && provider.isSingleton())
            continue;
        AnAction providerAction = new AnAction(provider.getName(), null, provider.getIcon()) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                BeforeRunTask task = provider.createTask(myRunConfiguration);
                if (task != null) {
                    provider.configureTask(myRunConfiguration, task);
                    if (!provider.canExecuteTask(myRunConfiguration, task))
                        return;
                } else {
                    return;
                }
                task.setEnabled(true);
                Set<RunConfiguration> configurationSet = new HashSet<>();
                getAllRunBeforeRuns(task, configurationSet);
                if (configurationSet.contains(myRunConfiguration)) {
                    JOptionPane.showMessageDialog(BeforeRunStepsPanel.this, ExecutionBundle.message("before.launch.panel.cyclic_dependency_warning", myRunConfiguration.getName(), provider.getDescription(task)), ExecutionBundle.message("warning.common.title"), JOptionPane.WARNING_MESSAGE);
                    return;
                }
                addTask(task);
                myListener.fireStepsBeforeRunChanged();
            }
        };
        actionGroup.add(providerAction);
    }
    final ListPopup popup = popupFactory.createActionGroupPopup(ExecutionBundle.message("add.new.run.configuration.acrtion.name"), actionGroup, SimpleDataContext.getProjectContext(myRunConfiguration.getProject()), false, false, false, null, -1, Conditions.<AnAction>alwaysTrue());
    popup.show(button.getPreferredPopupPoint());
}
Also used : ListPopup(com.intellij.openapi.ui.popup.ListPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) BeforeRunTask(com.intellij.execution.BeforeRunTask) UnknownRunConfiguration(com.intellij.execution.configurations.UnknownRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) Key(com.intellij.openapi.util.Key) HashSet(com.intellij.util.containers.hash.HashSet)

Example 3 with BeforeRunTaskProvider

use of com.intellij.execution.BeforeRunTaskProvider in project android by JetBrains.

the class PostSyncProjectSetup method setMakeStepInJunitRunConfigurations.

private void setMakeStepInJunitRunConfigurations(@NotNull String makeTaskName) {
    ConfigurationType junitConfigurationType = AndroidJUnitConfigurationType.getInstance();
    BeforeRunTaskProvider<BeforeRunTask>[] taskProviders = Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, myProject);
    BeforeRunTaskProvider targetProvider = null;
    for (BeforeRunTaskProvider<? extends BeforeRunTask> provider : taskProviders) {
        if (makeTaskName.equals(provider.getName())) {
            targetProvider = provider;
            break;
        }
    }
    if (targetProvider != null) {
        RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
        // Set the correct "Make step" in the "JUnit Run Configuration" template.
        for (ConfigurationFactory configurationFactory : junitConfigurationType.getConfigurationFactories()) {
            RunnerAndConfigurationSettings template = runManager.getConfigurationTemplate(configurationFactory);
            RunConfiguration runConfiguration = template.getConfiguration();
            setMakeStepInJUnitConfiguration(targetProvider, runConfiguration);
        }
        // Set the correct "Make step" in existing JUnit Configurations.
        for (RunConfiguration runConfiguration : runManager.getConfigurationsList(junitConfigurationType)) {
            setMakeStepInJUnitConfiguration(targetProvider, runConfiguration);
        }
    }
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) AndroidJUnitConfigurationType(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationType) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) MakeBeforeRunTaskProvider(com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Aggregations

BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)3 BeforeRunTask (com.intellij.execution.BeforeRunTask)2 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)2 MakeBeforeRunTaskProvider (com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider)1 AndroidJUnitConfigurationType (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationType)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)1 UnknownRunConfiguration (com.intellij.execution.configurations.UnknownRunConfiguration)1 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 Key (com.intellij.openapi.util.Key)1 HashSet (com.intellij.util.containers.hash.HashSet)1