Search in sources :

Example 1 with GradleRunTaskDialog

use of org.jetbrains.plugins.gradle.service.task.GradleRunTaskDialog 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)

Aggregations

RunManagerEx (com.intellij.execution.RunManagerEx)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)1 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)1 Project (com.intellij.openapi.project.Project)1 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)1 ExecuteGradleTaskHistoryService (org.jetbrains.plugins.gradle.service.task.ExecuteGradleTaskHistoryService)1 GradleRunTaskDialog (org.jetbrains.plugins.gradle.service.task.GradleRunTaskDialog)1