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);
}
}
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;
}
}
Aggregations