Search in sources :

Example 21 with BeforeRunTask

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

the class PostSyncProjectSetup method setMakeStepInJUnitConfiguration.

private void setMakeStepInJUnitConfiguration(@NotNull BeforeRunTaskProvider targetProvider, @NotNull RunConfiguration runConfiguration) {
    // Only "make" steps of beforeRunTasks should be overridden (see http://b.android.com/194704 and http://b.android.com/227280)
    List<BeforeRunTask> newBeforeRunTasks = new LinkedList<>();
    RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject);
    for (BeforeRunTask beforeRunTask : runManager.getBeforeRunTasks(runConfiguration)) {
        if (beforeRunTask.getProviderId().equals(CompileStepBeforeRun.ID)) {
            BeforeRunTask task = targetProvider.createTask(runConfiguration);
            if (task != null) {
                task.setEnabled(true);
                newBeforeRunTasks.add(task);
            }
        } else {
            newBeforeRunTasks.add(beforeRunTask);
        }
    }
    runManager.setBeforeRunTasks(runConfiguration, newBeforeRunTasks, false);
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) LinkedList(java.util.LinkedList) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Example 22 with BeforeRunTask

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

the class ApplicationRunParameters method addOrRemoveMakeTask.

private void addOrRemoveMakeTask(boolean add) {
    final DataContext dataContext = DataManager.getInstance().getDataContext(myPanel);
    final ConfigurationSettingsEditorWrapper editor = ConfigurationSettingsEditorWrapper.CONFIGURATION_EDITOR_KEY.getData(dataContext);
    if (editor == null) {
        return;
    }
    final List<BeforeRunTask> makeTasks = new ArrayList<BeforeRunTask>();
    for (BeforeRunTask task : editor.getStepsBeforeLaunch()) {
        if (task instanceof CompileStepBeforeRun.MakeBeforeRunTask || task instanceof CompileStepBeforeRunNoErrorCheck.MakeBeforeRunTaskNoErrorCheck) {
            makeTasks.add(task);
        }
    }
    if (add) {
        if (makeTasks.size() == 0) {
            editor.addBeforeLaunchStep(new CompileStepBeforeRun.MakeBeforeRunTask());
        } else {
            for (BeforeRunTask task : makeTasks) {
                task.setEnabled(true);
            }
        }
    } else {
        for (BeforeRunTask task : makeTasks) {
            task.setEnabled(false);
        }
    }
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) DataContext(com.intellij.openapi.actionSystem.DataContext) CompileStepBeforeRun(com.intellij.compiler.options.CompileStepBeforeRun) CompileStepBeforeRunNoErrorCheck(com.intellij.compiler.options.CompileStepBeforeRunNoErrorCheck) ConfigurationSettingsEditorWrapper(com.intellij.execution.impl.ConfigurationSettingsEditorWrapper)

Example 23 with BeforeRunTask

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

the class PostSyncProjectSetupTest method testJUnitRunConfigurationSetup.

public void testJUnitRunConfigurationSetup() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(true);
    PostSyncProjectSetup.Request request = new PostSyncProjectSetup.Request();
    mySetup.setUpProject(request, myProgressIndicator);
    ConfigurationFactory configurationFactory = AndroidJUnitConfigurationType.getInstance().getConfigurationFactories()[0];
    AndroidJUnitConfiguration jUnitConfiguration = new AndroidJUnitConfiguration("", getProject(), configurationFactory);
    myRunManager.addConfiguration(myRunManager.createConfiguration(jUnitConfiguration, configurationFactory), true);
    List<RunConfiguration> junitRunConfigurations = myRunManager.getConfigurationsList(AndroidJUnitConfigurationType.getInstance());
    for (RunConfiguration runConfiguration : junitRunConfigurations) {
        assertSize(1, myRunManager.getBeforeRunTasks(runConfiguration));
        assertEquals(MakeBeforeRunTaskProvider.ID, myRunManager.getBeforeRunTasks(runConfiguration).get(0).getProviderId());
    }
    RunConfiguration runConfiguration = junitRunConfigurations.get(0);
    List<BeforeRunTask> tasks = new LinkedList<>(myRunManager.getBeforeRunTasks(runConfiguration));
    BeforeRunTask newTask = new MakeBeforeRunTaskProvider(getProject()).createTask(runConfiguration);
    newTask.setEnabled(true);
    tasks.add(newTask);
    myRunManager.setBeforeRunTasks(runConfiguration, tasks, false);
    mySetup.setUpProject(request, myProgressIndicator);
    assertSize(2, myRunManager.getBeforeRunTasks(runConfiguration));
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) MakeBeforeRunTaskProvider(com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) LinkedList(java.util.LinkedList)

Example 24 with BeforeRunTask

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

the class BeforeRunStepsPanel method getAllRunBeforeRuns.

private void getAllRunBeforeRuns(BeforeRunTask task, Set<RunConfiguration> configurationSet) {
    if (task instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
        RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask runTask = (RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) task;
        RunConfiguration configuration = runTask.getSettings().getConfiguration();
        List<BeforeRunTask> tasks = RunManagerImpl.getInstanceImpl(configuration.getProject()).getBeforeRunTasks(configuration);
        for (BeforeRunTask beforeRunTask : tasks) {
            if (beforeRunTask instanceof RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) {
                if (configurationSet.add(((RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask) beforeRunTask).getSettings().getConfiguration()))
                    getAllRunBeforeRuns(beforeRunTask, configurationSet);
            }
        }
    }
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) UnknownRunConfiguration(com.intellij.execution.configurations.UnknownRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration)

Example 25 with BeforeRunTask

use of com.intellij.execution.BeforeRunTask 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)

Aggregations

BeforeRunTask (com.intellij.execution.BeforeRunTask)37 RunManagerEx (com.intellij.execution.RunManagerEx)24 ArrayList (java.util.ArrayList)22 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)17 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)13 Project (com.intellij.openapi.project.Project)12 MavenBeforeRunTask (org.jetbrains.idea.maven.tasks.MavenBeforeRunTask)6 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)4 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)2 UnknownRunConfiguration (com.intellij.execution.configurations.UnknownRunConfiguration)2 ConfigurationSettingsEditorWrapper (com.intellij.execution.impl.ConfigurationSettingsEditorWrapper)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 ExternalSystemBeforeRunTask (com.intellij.openapi.externalSystem.service.execution.ExternalSystemBeforeRunTask)2 Module (com.intellij.openapi.module.Module)2 Key (com.intellij.openapi.util.Key)2 BuildArtifactsBeforeRunTask (com.intellij.packaging.impl.run.BuildArtifactsBeforeRunTask)2 FunctionDeploymentConfigurationFactory (com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeploymentConfigurationFactory)2 FunctionRunConfigurationFactory (com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfigurationFactory)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 LinkedList (java.util.LinkedList)2