Search in sources :

Example 11 with ExternalSystemRunConfiguration

use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.

the class GradleRerunFailedTestsAction method getRunProfile.

@Nullable
@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @NotNull
        @Override
        public Module[] getModules() {
            return Module.EMPTY_ARRAY;
        }

        @Nullable
        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
            ExternalSystemRunConfiguration runProfile = ((ExternalSystemRunConfiguration) getPeer()).clone();
            Project project = runProfile.getProject();
            Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
            Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
            boolean useResolvedTasks = true;
            for (AbstractTestProxy test : failedTests) {
                if (test instanceof GradleSMTestProxy) {
                    String testName = test.getName();
                    String className = ((GradleSMTestProxy) test).getClassName();
                    scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(className, testName));
                    if (!useResolvedTasks)
                        continue;
                    if (className == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.projectScope(project));
                    if (psiClass == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiFile psiFile = psiClass.getContainingFile();
                    if (psiFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
                    if (moduleForFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    ContainerUtil.addAllNotNull(tasksToRun, GradleTestRunConfigurationProducer.getTasksToRun(moduleForFile));
                }
            }
            runProfile.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
            if (useResolvedTasks && !tasksToRun.isEmpty()) {
                runProfile.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
            }
            return runProfile.getState(executor, environment);
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with ExternalSystemRunConfiguration

use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.

the class ExternalSystemUtil method createExternalSystemRunnerAndConfigurationSettings.

@Nullable
public static RunnerAndConfigurationSettings createExternalSystemRunnerAndConfigurationSettings(@NotNull ExternalSystemTaskExecutionSettings taskSettings, @NotNull Project project, @NotNull ProjectSystemId externalSystemId) {
    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 settings;
}
Also used : ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractExternalSystemTaskConfigurationType(com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with ExternalSystemRunConfiguration

use of com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration in project intellij-community by JetBrains.

the class RunConfigurationNode method update.

@Override
protected void update(PresentationData presentation) {
    super.update(presentation);
    presentation.setIcon(ProgramRunnerUtil.getConfigurationIcon(mySettings, false));
    final ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) mySettings.getConfiguration();
    final ExternalSystemTaskExecutionSettings taskExecutionSettings = runConfiguration.getSettings();
    final String shortcutHint = StringUtil.nullize(getShortcutsManager().getDescription(taskExecutionSettings.getExternalProjectPath(), mySettings.getName()));
    final String activatorHint = StringUtil.nullize(getTaskActivator().getDescription(taskExecutionSettings.getExternalSystemId(), taskExecutionSettings.getExternalProjectPath(), getRunConfigurationActivationTaskName(mySettings)));
    String hint;
    if (shortcutHint == null) {
        hint = activatorHint;
    } else if (activatorHint == null) {
        hint = shortcutHint;
    } else {
        hint = shortcutHint + ", " + activatorHint;
    }
    setNameAndTooltip(getName(), StringUtil.join(taskExecutionSettings.getTaskNames(), " "), hint);
}
Also used : ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Aggregations

ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)13 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)7 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)6 PsiClass (com.intellij.psi.PsiClass)5 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3 InheritorChooser (com.intellij.execution.junit.InheritorChooser)3 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)3 Module (com.intellij.openapi.module.Module)3 PsiMethod (com.intellij.psi.PsiMethod)3 List (java.util.List)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 Phase (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator.Phase)2 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)2 RunConfigurationNode (com.intellij.openapi.externalSystem.view.RunConfigurationNode)2 Project (com.intellij.openapi.project.Project)2 CantRunException (com.intellij.execution.CantRunException)1 Executor (com.intellij.execution.Executor)1 JavaExecutionUtil (com.intellij.execution.JavaExecutionUtil)1