Search in sources :

Example 1 with ExternalTaskExecutionInfo

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

the class AbstractExternalSystemLocalSettings method pruneOutdatedEntries.

private void pruneOutdatedEntries() {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
    assert manager != null;
    Set<String> pathsToForget = ContainerUtilRt.newHashSet();
    for (ExternalProjectPojo pojo : myAvailableProjects.get().keySet()) {
        pathsToForget.add(pojo.getPath());
    }
    for (String path : myAvailableTasks.get().keySet()) {
        pathsToForget.add(path);
    }
    for (ExternalTaskExecutionInfo taskInfo : myRecentTasks.get()) {
        pathsToForget.add(taskInfo.getSettings().getExternalProjectPath());
    }
    AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(myProject);
    for (ExternalProjectSettings projectSettings : settings.getLinkedProjectsSettings()) {
        pathsToForget.remove(projectSettings.getExternalProjectPath());
    }
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        if (!ExternalSystemApiUtil.isExternalSystemAwareModule(myExternalSystemId, module))
            continue;
        pathsToForget.remove(ExternalSystemApiUtil.getExternalProjectPath(module));
    }
    if (!pathsToForget.isEmpty()) {
        forgetExternalProjects(pathsToForget);
    }
}
Also used : ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) Module(com.intellij.openapi.module.Module) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)

Example 2 with ExternalTaskExecutionInfo

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

the class GradleExecuteTaskAction method actionPerformed.

@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    ExecuteGradleTaskHistoryService historyService = ExecuteGradleTaskHistoryService.getInstance(project);
    GradleRunTaskDialog dialog = new GradleRunTaskDialog(project, historyService.getHistory());
    String lastWorkingDirectory = historyService.getWorkDirectory();
    if (lastWorkingDirectory.length() == 0) {
        lastWorkingDirectory = obtainAppropriateWorkingDirectory(e);
    }
    dialog.setWorkDirectory(lastWorkingDirectory);
    if (StringUtil.isEmptyOrSpaces(historyService.getCanceledCommand())) {
        if (historyService.getHistory().size() > 0) {
            dialog.setCommandLine(historyService.getHistory().get(0));
        }
    } else {
        dialog.setCommandLine(historyService.getCanceledCommand());
    }
    if (!dialog.showAndGet()) {
        historyService.setCanceledCommand(dialog.getCommandLine());
        return;
    }
    historyService.setCanceledCommand(null);
    String fullCommandLine = dialog.getCommandLine();
    fullCommandLine = fullCommandLine.trim();
    String workDirectory = dialog.getWorkDirectory();
    historyService.addCommand(fullCommandLine, workDirectory);
    final ExternalTaskExecutionInfo taskExecutionInfo;
    try {
        taskExecutionInfo = buildTaskInfo(workDirectory, fullCommandLine);
    } catch (CommandLineArgumentException ex) {
        final NotificationData notificationData = new NotificationData("<b>Command-line arguments cannot be parsed</b>", "<i>" + fullCommandLine + "</i> \n" + ex.getMessage(), NotificationCategory.WARNING, NotificationSource.TASK_EXECUTION);
        notificationData.setBalloonNotification(true);
        ExternalSystemNotificationManager.getInstance(project).showNotification(GradleConstants.SYSTEM_ID, notificationData);
        return;
    }
    RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
    ExternalSystemUtil.runTask(taskExecutionInfo.getSettings(), taskExecutionInfo.getExecutorId(), project, GradleConstants.SYSTEM_ID);
    RunnerAndConfigurationSettings configuration = ExternalSystemUtil.createExternalSystemRunnerAndConfigurationSettings(taskExecutionInfo.getSettings(), project, GradleConstants.SYSTEM_ID);
    if (configuration == null)
        return;
    final RunnerAndConfigurationSettings existingConfiguration = runManager.findConfigurationByName(configuration.getName());
    if (existingConfiguration == null) {
        runManager.setTemporaryConfiguration(configuration);
    } else {
        runManager.setSelectedConfiguration(existingConfiguration);
    }
}
Also used : Project(com.intellij.openapi.project.Project) RunManagerEx(com.intellij.execution.RunManagerEx) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) GradleRunTaskDialog(org.jetbrains.plugins.gradle.service.task.GradleRunTaskDialog) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) ExecuteGradleTaskHistoryService(org.jetbrains.plugins.gradle.service.task.ExecuteGradleTaskHistoryService) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Example 3 with ExternalTaskExecutionInfo

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

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

the class ExternalSystemTasksTreeModel method buildTaskInfo.

@NotNull
private ExternalTaskExecutionInfo buildTaskInfo(@NotNull ExternalTaskPojo task) {
    ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
    settings.setExternalProjectPath(task.getLinkedExternalProjectPath());
    settings.setTaskNames(Collections.singletonList(task.getName()));
    settings.setTaskDescriptions(Collections.singletonList(task.getDescription()));
    settings.setExternalSystemIdString(myExternalSystemId.toString());
    return new ExternalTaskExecutionInfo(settings, DefaultRunExecutor.EXECUTOR_ID);
}
Also used : ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ExternalTaskExecutionInfo

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

the class ExternalSystemTasksTree method produce.

@Nullable
@Override
public ExternalTaskExecutionInfo produce() {
    TreePath[] selectionPaths = getSelectionPaths();
    if (selectionPaths == null || selectionPaths.length == 0) {
        return null;
    }
    Map<String, ExternalTaskExecutionInfo> map = ContainerUtil.newHashMap();
    for (TreePath selectionPath : selectionPaths) {
        Object component = selectionPath.getLastPathComponent();
        if (!(component instanceof ExternalSystemNode)) {
            continue;
        }
        Object element = ((ExternalSystemNode) component).getDescriptor().getElement();
        if (element instanceof ExternalTaskExecutionInfo) {
            ExternalTaskExecutionInfo taskExecutionInfo = (ExternalTaskExecutionInfo) element;
            ExternalSystemTaskExecutionSettings executionSettings = taskExecutionInfo.getSettings();
            String key = executionSettings.getExternalSystemIdString() + executionSettings.getExternalProjectPath() + executionSettings.getVmOptions();
            ExternalTaskExecutionInfo executionInfo = map.get(key);
            if (executionInfo == null) {
                ExternalSystemTaskExecutionSettings taskExecutionSettings = new ExternalSystemTaskExecutionSettings();
                taskExecutionSettings.setExternalProjectPath(executionSettings.getExternalProjectPath());
                taskExecutionSettings.setExternalSystemIdString(executionSettings.getExternalSystemIdString());
                taskExecutionSettings.setVmOptions(executionSettings.getVmOptions());
                taskExecutionSettings.setScriptParameters(executionSettings.getScriptParameters());
                taskExecutionSettings.setExecutionName(executionSettings.getExecutionName());
                executionInfo = new ExternalTaskExecutionInfo(taskExecutionSettings, taskExecutionInfo.getExecutorId());
                map.put(key, executionInfo);
            }
            executionInfo.getSettings().getTaskNames().addAll(executionSettings.getTaskNames());
            executionInfo.getSettings().getTaskDescriptions().addAll(executionSettings.getTaskDescriptions());
        }
    }
    // Disable tasks execution if it comes from different projects
    if (map.values().size() != 1)
        return null;
    return map.values().iterator().next();
}
Also used : TreePath(javax.swing.tree.TreePath) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)16 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)7 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)6 Nullable (org.jetbrains.annotations.Nullable)5 RunManagerEx (com.intellij.execution.RunManagerEx)4 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)4 Project (com.intellij.openapi.project.Project)4 NotNull (org.jetbrains.annotations.NotNull)4 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)3 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)3 RunManager (com.intellij.execution.RunManager)2 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 ExternalTaskPojo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo)2 ExternalSystemNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager)2 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)2 NotificationSource (com.intellij.openapi.externalSystem.service.notification.NotificationSource)2 ExternalSystemUtil (com.intellij.openapi.externalSystem.util.ExternalSystemUtil)2