Search in sources :

Example 6 with ExternalSystemRunConfiguration

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

the class AssignRunConfigurationShortcutAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = getProject(e);
    assert project != null;
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    if (selectedNodes == null || selectedNodes.size() != 1 || !(selectedNodes.get(0) instanceof RunConfigurationNode))
        return;
    RunnerAndConfigurationSettings settings = ((RunConfigurationNode) selectedNodes.get(0)).getSettings();
    assert settings != null;
    ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) settings.getConfiguration();
    String actionIdPrefix = getActionPrefix(project, runConfiguration.getSettings().getExternalProjectPath());
    String actionId = actionIdPrefix + settings.getName();
    AnAction action = ActionManager.getInstance().getAction(actionId);
    if (action == null) {
        ExternalSystemKeymapExtension.getOrRegisterAction(project, settings);
    }
    new EditKeymapsDialog(project, actionId).show();
}
Also used : Project(com.intellij.openapi.project.Project) EditKeymapsDialog(com.intellij.openapi.keymap.impl.ui.EditKeymapsDialog) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) RunConfigurationNode(com.intellij.openapi.externalSystem.view.RunConfigurationNode) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 7 with ExternalSystemRunConfiguration

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

the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.

@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
    if (!isApplicable(executeRunConfigurationTask))
        return null;
    ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
    PsiClass mainClass = applicationConfiguration.getMainClass();
    if (mainClass == null)
        return null;
    VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
    Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
    if (module == null)
        return null;
    final JavaParameters params = new JavaParameters();
    JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
    params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
    String javaExePath = null;
    try {
        final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
        if (jdk == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        final SdkTypeId type = jdk.getSdkType();
        if (!(type instanceof JavaSdkType))
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
        if (javaExePath == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
        javaExePath = FileUtil.toSystemIndependentName(javaExePath);
    } catch (CantRunException e) {
        ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
    }
    StringBuilder parametersString = new StringBuilder();
    for (String parameter : params.getProgramParametersList().getParameters()) {
        parametersString.append("args '").append(parameter).append("'\n");
    }
    StringBuilder vmParametersString = new StringBuilder();
    for (String parameter : params.getVMParametersList().getParameters()) {
        vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
    }
    ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
    taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
    taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
    final String runAppTaskName = "run " + mainClass.getName();
    taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
    String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
    ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
    if (environment != null) {
        RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
        assert runnerAndConfigurationSettings != null;
        ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
        final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
        if (gradlePath == null)
            return null;
        final String sourceSetName;
        if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
            sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
        } else {
            sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
        }
        if (sourceSetName == null)
            return null;
        @Language("Groovy") String initScript = "projectsEvaluated {\n" + "  rootProject.allprojects {\n" + "    if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + "      project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? "        executable = '" + javaExePath + "'\n" : "") + "        classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + "        main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + "      }\n" + "    }\n" + "  }\n" + "}\n";
        runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
        return environment;
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) Language(org.intellij.lang.annotations.Language) JavaParameters(com.intellij.execution.configurations.JavaParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ExternalSystemRunConfiguration

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

the class TestClassGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, ArrayUtil.toObjectArray(classes, PsiClass.class)))
                return;
            super.runForClasses(classes, method, context, performRunnable);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestConfiguration(configuration, context, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, null, (PsiClass) fromContext.getSourceElement()))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

Example 9 with ExternalSystemRunConfiguration

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

the class TestClassGradleConfigurationProducer method applyTestConfiguration.

private static boolean applyTestConfiguration(@NotNull ExternalSystemRunConfiguration configuration, @NotNull ConfigurationContext context, @NotNull PsiClass... containingClasses) {
    final Module module = context.getModule();
    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        return false;
    final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (projectPath == null)
        return false;
    List<String> tasksToRun = getTasksToRun(module);
    if (tasksToRun.isEmpty())
        return false;
    configuration.getSettings().setExternalProjectPath(projectPath);
    configuration.getSettings().setTaskNames(tasksToRun);
    StringBuilder buf = new StringBuilder();
    for (PsiClass aClass : containingClasses) {
        buf.append(String.format("--tests %s ", aClass.getQualifiedName()));
    }
    configuration.getSettings().setScriptParameters(buf.toString());
    configuration.setName(StringUtil.join(containingClasses, aClass -> aClass.getName(), "|"));
    return true;
}
Also used : ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) InheritorChooser(com.intellij.execution.junit.InheritorChooser) ArrayUtil(com.intellij.util.ArrayUtil) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ExternalSystemConstants(com.intellij.openapi.externalSystem.util.ExternalSystemConstants) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) PsiClass(com.intellij.psi.PsiClass) JavaRunConfigurationExtensionManager(com.intellij.execution.JavaRunConfigurationExtensionManager) GradleExternalTaskConfigurationType(org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType) PsiElement(com.intellij.psi.PsiElement) Module(com.intellij.openapi.module.Module) PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JUnitUtil(com.intellij.execution.junit.JUnitUtil) PsiMethod(com.intellij.psi.PsiMethod) StringUtil(com.intellij.openapi.util.text.StringUtil) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) Location(com.intellij.execution.Location) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module)

Example 10 with ExternalSystemRunConfiguration

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

the class TestMethodGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final PsiMethod psiMethod = (PsiMethod) fromContext.getSourceElement();
    final PsiClass containingClass = psiMethod.getContainingClass();
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestMethodConfiguration(configuration, context, psiMethod, ArrayUtil.toObjectArray(classes, PsiClass.class)))
                return;
            super.runForClasses(classes, method, context, performRunnable);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestMethodConfiguration(configuration, context, psiMethod, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, containingClass))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

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