Search in sources :

Example 16 with ExternalSystemTaskExecutionSettings

use of com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings in project intellij-community by JetBrains.

the class ExternalSystemBeforeRunTaskProvider method canExecuteTask.

@Override
public boolean canExecuteTask(RunConfiguration configuration, ExternalSystemBeforeRunTask beforeRunTask) {
    final ExternalSystemTaskExecutionSettings executionSettings = beforeRunTask.getTaskExecutionSettings();
    final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
    for (String taskName : executionSettings.getTaskNames()) {
        tasks.add(new ExternalTaskPojo(taskName, executionSettings.getExternalProjectPath(), null));
    }
    if (tasks.isEmpty())
        return true;
    ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(myProject, mySystemId, executionSettings, DefaultRunExecutor.EXECUTOR_ID);
    if (environment == null)
        return false;
    return environment.getRunner().canRun(DefaultRunExecutor.EXECUTOR_ID, environment.getRunProfile());
}
Also used : ExternalTaskPojo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 17 with ExternalSystemTaskExecutionSettings

use of com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings in project intellij-community by JetBrains.

the class GradleManager method patchRecentTasks.

private static void patchRecentTasks(@NotNull Map<String, String> adjustedPaths, @NotNull GradleLocalSettings localSettings) {
    for (ExternalTaskExecutionInfo taskInfo : localSettings.getRecentTasks()) {
        ExternalSystemTaskExecutionSettings s = taskInfo.getSettings();
        String newPath = adjustedPaths.get(s.getExternalProjectPath());
        if (newPath != null) {
            s.setExternalProjectPath(newPath);
        }
    }
}
Also used : ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 18 with ExternalSystemTaskExecutionSettings

use of com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings 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 19 with ExternalSystemTaskExecutionSettings

use of com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings in project intellij-community by JetBrains.

the class GradleProjectTaskRunner method run.

@Override
public void run(@NotNull Project project, @NotNull ProjectTaskContext context, @Nullable ProjectTaskNotification callback, @NotNull Collection<? extends ProjectTask> tasks) {
    String executionName = "Gradle build";
    MultiMap<String, String> buildTasksMap = MultiMap.createLinkedSet();
    MultiMap<String, String> cleanTasksMap = MultiMap.createLinkedSet();
    Map<Class<? extends ProjectTask>, List<ProjectTask>> taskMap = InternalProjectTaskRunner.groupBy(tasks);
    addModulesBuildTasks(taskMap.get(ModuleBuildTask.class), cleanTasksMap, buildTasksMap);
    // TODO there should be 'gradle' way to build files instead of related modules entirely
    addModulesBuildTasks(taskMap.get(ModuleFilesBuildTask.class), cleanTasksMap, buildTasksMap);
    addArtifactsBuildTasks(taskMap.get(ArtifactBuildTask.class), cleanTasksMap, buildTasksMap);
    // TODO send a message if nothing to build
    Set<String> rootPaths = buildTasksMap.keySet();
    AtomicInteger successCounter = new AtomicInteger();
    AtomicInteger errorCounter = new AtomicInteger();
    TaskCallback taskCallback = callback == null ? null : new TaskCallback() {

        @Override
        public void onSuccess() {
            handle(true);
        }

        @Override
        public void onFailure() {
            handle(false);
        }

        private void handle(boolean success) {
            int successes = success ? successCounter.incrementAndGet() : successCounter.get();
            int errors = success ? errorCounter.get() : errorCounter.incrementAndGet();
            if (successes + errors == rootPaths.size()) {
                callback.finished(new ProjectTaskResult(false, errors, 0));
            }
        }
    };
    String gradleVmOptions = GradleSettings.getInstance(project).getGradleVmOptions();
    for (String rootProjectPath : rootPaths) {
        Collection<String> buildTasks = buildTasksMap.get(rootProjectPath);
        if (buildTasks.isEmpty())
            continue;
        Collection<String> cleanTasks = cleanTasksMap.get(rootProjectPath);
        ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
        settings.setExecutionName(executionName);
        settings.setExternalProjectPath(rootProjectPath);
        settings.setTaskNames(ContainerUtil.collect(ContainerUtil.concat(cleanTasks, buildTasks).iterator()));
        //settings.setScriptParameters(scriptParameters);
        settings.setVmOptions(gradleVmOptions);
        settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
        ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, project, GradleConstants.SYSTEM_ID, taskCallback, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false);
    }
}
Also used : TaskCallback(com.intellij.openapi.externalSystem.task.TaskCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Aggregations

ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)19 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)7 ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)6 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)6 NotNull (org.jetbrains.annotations.NotNull)5 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 RunManagerEx (com.intellij.execution.RunManagerEx)2 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 ExternalTaskPojo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo)2 Phase (com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator.Phase)2 TaskCallback (com.intellij.openapi.externalSystem.task.TaskCallback)2 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)2 Nullable (org.jetbrains.annotations.Nullable)2 CantRunException (com.intellij.execution.CantRunException)1 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1