Search in sources :

Example 16 with ExternalTaskExecutionInfo

use of com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo in project liferay-ide by liferay.

the class AbstractLiferayGradleTaskAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent event) {
    Project project = event.getRequiredData(CommonDataKeys.PROJECT);
    String workingDirectory = getWorkingDirectory(event);
    if (CoreUtil.isNullOrEmpty(workingDirectory)) {
        return;
    }
    ExternalTaskExecutionInfo taskExecutionInfo = _buildTaskExecutionInfo(project, workingDirectory, _taskName);
    if (taskExecutionInfo == null) {
        return;
    }
    ExternalSystemUtil.runTask(taskExecutionInfo.getSettings(), taskExecutionInfo.getExecutorId(), project, GradleConstants.SYSTEM_ID);
    RunnerAndConfigurationSettings configuration = ExternalSystemUtil.createExternalSystemRunnerAndConfigurationSettings(taskExecutionInfo.getSettings(), project, GradleConstants.SYSTEM_ID);
    if (configuration == null) {
        return;
    }
    RunManager runManager = RunManager.getInstance(project);
    RunnerAndConfigurationSettings existingConfiguration = runManager.findConfigurationByName(configuration.getName());
    if (existingConfiguration == null) {
        runManager.setTemporaryConfiguration(configuration);
    } else {
        runManager.setSelectedConfiguration(existingConfiguration);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RunManager(com.intellij.execution.RunManager)

Example 17 with ExternalTaskExecutionInfo

use of com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo in project liferay-intellij-plugin by liferay.

the class AbstractLiferayGradleTaskAction method _buildTaskExecutionInfo.

private ExternalTaskExecutionInfo _buildTaskExecutionInfo(Project project, @NotNull String projectPath, @NotNull List<String> gradleTasks) {
    CommandLineParser gradleCmdParser = new CommandLineParser();
    GradleCommandLineOptionsConverter commandLineConverter = new GradleCommandLineOptionsConverter();
    commandLineConverter.configure(gradleCmdParser);
    ParsedCommandLine parsedCommandLine = gradleCmdParser.parse(gradleTasks);
    try {
        Map<String, List<String>> optionsMap = commandLineConverter.convert(parsedCommandLine, new HashMap<>());
        List<String> systemProperties = optionsMap.remove("system-prop");
        String vmOptions = (systemProperties == null) ? "" : StringUtil.join(systemProperties, entry -> "-D" + entry, " ");
        String scriptParameters = StringUtil.join(optionsMap.entrySet(), entry -> {
            List<String> values = entry.getValue();
            String longOptionName = entry.getKey();
            if ((values != null) && !values.isEmpty()) {
                return StringUtil.join(values, entry1 -> "--" + longOptionName + ' ' + entry1, " ");
            }
            return "--" + longOptionName;
        }, " ");
        if (continuous()) {
            scriptParameters = scriptParameters + " --continuous";
        }
        ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
        settings.setExternalProjectPath(projectPath);
        settings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.toString());
        settings.setScriptParameters(scriptParameters);
        settings.setTaskNames(parsedCommandLine.getExtraArguments());
        settings.setVmOptions(vmOptions);
        return new ExternalTaskExecutionInfo(settings, DefaultRunExecutor.EXECUTOR_ID);
    } catch (CommandLineArgumentException commandLineArgumentException) {
        NotificationData notificationData = new NotificationData("<b>Command-line arguments cannot be parsed</b>", "<i>" + _taskName + "</i> \n" + commandLineArgumentException.getMessage(), NotificationCategory.WARNING, NotificationSource.TASK_EXECUTION);
        notificationData.setBalloonNotification(true);
        ExternalSystemNotificationManager externalSystemNotificationManager = ExternalSystemNotificationManager.getInstance(project);
        externalSystemNotificationManager.showNotification(GradleConstants.SYSTEM_ID, notificationData);
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) NotificationCategory(com.intellij.openapi.externalSystem.service.notification.NotificationCategory) HashMap(java.util.HashMap) TaskCallback(com.intellij.openapi.externalSystem.task.TaskCallback) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) Lists(com.google.common.collect.Lists) ModuleUtil(com.intellij.openapi.module.ModuleUtil) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ExternalSystemNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager) StringUtil(com.intellij.openapi.util.text.StringUtil) GradleCommandLineOptionsConverter(org.jetbrains.plugins.gradle.service.execution.cmd.GradleCommandLineOptionsConverter) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Icon(javax.swing.Icon) LiferayWorkspaceSupport(com.liferay.ide.idea.util.LiferayWorkspaceSupport) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) Objects(java.util.Objects) ExternalSystemUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) CoreUtil(com.liferay.ide.idea.util.CoreUtil) NotificationSource(com.intellij.openapi.externalSystem.service.notification.NotificationSource) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) ListUtil(com.liferay.ide.idea.util.ListUtil) NotNull(org.jetbrains.annotations.NotNull) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) GradleCommandLineOptionsConverter(org.jetbrains.plugins.gradle.service.execution.cmd.GradleCommandLineOptionsConverter) ParsedCommandLine(org.gradle.cli.ParsedCommandLine) List(java.util.List) CommandLineParser(org.gradle.cli.CommandLineParser) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) ExternalSystemNotificationManager(com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) NotificationData(com.intellij.openapi.externalSystem.service.notification.NotificationData)

Aggregations

ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)17 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)8 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)7 Nullable (org.jetbrains.annotations.Nullable)6 Project (com.intellij.openapi.project.Project)5 NotNull (org.jetbrains.annotations.NotNull)5 RunManagerEx (com.intellij.execution.RunManagerEx)4 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)4 NotificationData (com.intellij.openapi.externalSystem.service.notification.NotificationData)4 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)4 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 ExternalSystemNotificationManager (com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager)3 NotificationCategory (com.intellij.openapi.externalSystem.service.notification.NotificationCategory)3 NotificationSource (com.intellij.openapi.externalSystem.service.notification.NotificationSource)3 ExternalSystemUtil (com.intellij.openapi.externalSystem.util.ExternalSystemUtil)3 Module (com.intellij.openapi.module.Module)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 HashMap (java.util.HashMap)3 List (java.util.List)3