Search in sources :

Example 6 with ExternalSystemTaskExecutionSettings

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

the class ExternalSystemBeforeRunTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, 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;
    final ProgramRunner runner = environment.getRunner();
    environment.setExecutionId(env.getExecutionId());
    return RunConfigurationBeforeRunProvider.doRunTask(DefaultRunExecutor.getRunExecutorInstance().getId(), environment, runner);
}
Also used : ExternalTaskPojo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 7 with ExternalSystemTaskExecutionSettings

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

the class ToggleTaskActivationAction method getTasks.

@NotNull
private static List<TaskData> getTasks(AnActionEvent e) {
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    if (selectedNodes == null)
        return Collections.emptyList();
    List<TaskData> tasks = new SmartList<>();
    for (ExternalSystemNode node : selectedNodes) {
        if (node instanceof TaskNode && !node.isIgnored()) {
            tasks.add((TaskData) node.getData());
        } else if (node instanceof RunConfigurationNode) {
            final RunnerAndConfigurationSettings configurationSettings = ((RunConfigurationNode) node).getSettings();
            final ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) configurationSettings.getConfiguration();
            final ExternalSystemTaskExecutionSettings taskExecutionSettings = runConfiguration.getSettings();
            tasks.add(new TaskData(taskExecutionSettings.getExternalSystemId(), RUN_CONFIGURATION_TASK_PREFIX + configurationSettings.getName(), taskExecutionSettings.getExternalProjectPath(), null));
        } else {
            return Collections.emptyList();
        }
    }
    return tasks;
}
Also used : TaskNode(com.intellij.openapi.externalSystem.view.TaskNode) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) SmartList(com.intellij.util.SmartList) RunConfigurationNode(com.intellij.openapi.externalSystem.view.RunConfigurationNode) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ExternalSystemTaskExecutionSettings

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

the class GradleExecuteTaskAction method buildTaskInfo.

private static ExternalTaskExecutionInfo buildTaskInfo(@NotNull String projectPath, @NotNull String fullCommandLine) throws CommandLineArgumentException {
    CommandLineParser gradleCmdParser = new CommandLineParser();
    GradleCommandLineOptionsConverter commandLineConverter = new GradleCommandLineOptionsConverter();
    commandLineConverter.configure(gradleCmdParser);
    ParsedCommandLine parsedCommandLine = gradleCmdParser.parse(ParametersListUtil.parse(fullCommandLine, true));
    final Map<String, List<String>> optionsMap = commandLineConverter.convert(parsedCommandLine, new HashMap<>());
    final List<String> systemProperties = optionsMap.remove("system-prop");
    final String vmOptions = systemProperties == null ? "" : StringUtil.join(systemProperties, entry -> "-D" + entry, " ");
    final String scriptParameters = StringUtil.join(optionsMap.entrySet(), entry -> {
        final List<String> values = entry.getValue();
        final String longOptionName = entry.getKey();
        if (values != null && !values.isEmpty()) {
            return StringUtil.join(values, entry1 -> "--" + longOptionName + ' ' + entry1, " ");
        } else {
            return "--" + longOptionName;
        }
    }, " ");
    final List<String> tasks = parsedCommandLine.getExtraArguments();
    ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
    settings.setExternalProjectPath(projectPath);
    settings.setTaskNames(tasks);
    settings.setScriptParameters(scriptParameters);
    settings.setVmOptions(vmOptions);
    settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.toString());
    return new ExternalTaskExecutionInfo(settings, DefaultRunExecutor.EXECUTOR_ID);
}
Also used : ExternalSystemActionUtil(com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Presentation(com.intellij.openapi.actionSystem.Presentation) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) ExecuteGradleTaskHistoryService(org.jetbrains.plugins.gradle.service.task.ExecuteGradleTaskHistoryService) HashMap(java.util.HashMap) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) ExternalSystemAction(com.intellij.openapi.externalSystem.action.ExternalSystemAction) ExternalSystemDataKeys(com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) Project(com.intellij.openapi.project.Project) RunManagerEx(com.intellij.execution.RunManagerEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Module(com.intellij.openapi.module.Module) ParametersListUtil(com.intellij.util.execution.ParametersListUtil) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ExternalSystemNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager) GradleRunTaskDialog(org.jetbrains.plugins.gradle.service.task.GradleRunTaskDialog) StringUtil(com.intellij.openapi.util.text.StringUtil) GradleCommandLineOptionsConverter(org.jetbrains.plugins.gradle.service.execution.cmd.GradleCommandLineOptionsConverter) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) ExternalSystemUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUtil) List(java.util.List) ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) NotificationSource(com.intellij.openapi.externalSystem.service.notification.NotificationSource) ExternalProjectsView(com.intellij.openapi.externalSystem.view.ExternalProjectsView) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) NotNull(org.jetbrains.annotations.NotNull) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) List(java.util.List) CommandLineParser(org.gradle.cli.CommandLineParser) GradleCommandLineOptionsConverter(org.jetbrains.plugins.gradle.service.execution.cmd.GradleCommandLineOptionsConverter) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 9 with ExternalSystemTaskExecutionSettings

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

the class GradleDependenciesImportingTest method assertCompileClasspathOrdering.

protected void assertCompileClasspathOrdering(String moduleName) {
    Module module = getModule(moduleName);
    String sourceSetName = getSourceSetName(module);
    assertNotNull("Can not find the sourceSet for the module", sourceSetName);
    ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
    settings.setExternalProjectPath(getExternalProjectPath(module));
    String id = getExternalProjectId(module);
    String gradlePath = id.startsWith(":") ? trimEnd(id, sourceSetName) : "";
    settings.setTaskNames(Collections.singletonList(gradlePath + ":print" + capitalize(sourceSetName) + "CompileDependencies"));
    settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
    settings.setScriptParameters("--quiet");
    ExternalSystemProgressNotificationManager notificationManager = ServiceManager.getService(ExternalSystemProgressNotificationManager.class);
    StringBuilder gradleClasspath = new StringBuilder();
    ExternalSystemTaskNotificationListenerAdapter listener = new ExternalSystemTaskNotificationListenerAdapter() {

        @Override
        public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
            gradleClasspath.append(text);
        }
    };
    notificationManager.addNotificationListener(listener);
    ExternalSystemUtil.runTask(settings, DefaultRunExecutor.EXECUTOR_ID, myProject, GradleConstants.SYSTEM_ID, null, ProgressExecutionMode.NO_PROGRESS_SYNC);
    notificationManager.removeNotificationListener(listener);
    List<String> ideClasspath = ContainerUtil.newArrayList();
    ModuleRootManager.getInstance(module).orderEntries().withoutSdk().withoutModuleSourceEntries().compileOnly().productionOnly().forEach(entry -> {
        if (entry instanceof ModuleOrderEntry) {
            Module moduleDep = ((ModuleOrderEntry) entry).getModule();
            String sourceSetDepName = getSourceSetName(moduleDep);
            assert sourceSetDepName != "main";
            String gradleProjectDepName = trimStart(trimEnd(getExternalProjectId(moduleDep), ":main"), ":");
            String version = getExternalProjectVersion(moduleDep);
            version = "unspecified".equals(version) ? "" : "-" + version;
            ideClasspath.add(gradleProjectDepName + version + ".jar");
        } else {
            ideClasspath.add(entry.getFiles(OrderRootType.CLASSES)[0].getName());
        }
        return true;
    });
    assertEquals(join(ideClasspath, " "), gradleClasspath.toString().trim());
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) Module(com.intellij.openapi.module.Module) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemProgressNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemProgressNotificationManager) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 10 with ExternalSystemTaskExecutionSettings

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

the class ExternalSystemTaskActivator method runTasksQueue.

private boolean runTasksQueue(final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue) {
    final Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings> pair = tasksQueue.poll();
    if (pair == null)
        return true;
    final ProjectSystemId systemId = pair.first;
    final ExternalSystemTaskExecutionSettings executionSettings = pair.getSecond();
    final Semaphore targetDone = new Semaphore();
    targetDone.down();
    final Ref<Boolean> result = new Ref<>(false);
    ExternalSystemUtil.runTask(executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, systemId, new TaskCallback() {

        @Override
        public void onSuccess() {
            result.set(runTasksQueue(tasksQueue));
            targetDone.up();
        }

        @Override
        public void onFailure() {
            targetDone.up();
        }
    }, ProgressExecutionMode.IN_BACKGROUND_ASYNC, false);
    targetDone.waitFor();
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) TaskCallback(com.intellij.openapi.externalSystem.task.TaskCallback) Semaphore(com.intellij.util.concurrency.Semaphore) 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