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);
}
}
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);
}
use of com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo in project intellij-community by JetBrains.
the class ExternalProjectsViewImpl method extractLocation.
@Nullable
private ExternalSystemTaskLocation extractLocation() {
final List<ExternalSystemNode> selectedNodes = getSelectedNodes(ExternalSystemNode.class);
if (selectedNodes.isEmpty())
return null;
List<TaskData> tasks = ContainerUtil.newSmartList();
ExternalTaskExecutionInfo taskExecutionInfo = new ExternalTaskExecutionInfo();
String projectPath = null;
for (ExternalSystemNode node : selectedNodes) {
final Object data = node.getData();
if (data instanceof TaskData) {
final TaskData taskData = (TaskData) data;
if (projectPath == null) {
projectPath = taskData.getLinkedExternalProjectPath();
} else if (!taskData.getLinkedExternalProjectPath().equals(projectPath)) {
return null;
}
taskExecutionInfo.getSettings().getTaskNames().add(taskData.getName());
taskExecutionInfo.getSettings().getTaskDescriptions().add(taskData.getDescription());
tasks.add(taskData);
}
}
if (tasks.isEmpty())
return null;
taskExecutionInfo.getSettings().setExternalSystemIdString(myExternalSystemId.toString());
taskExecutionInfo.getSettings().setExternalProjectPath(projectPath);
return ExternalSystemTaskLocation.create(myProject, myExternalSystemId, projectPath, taskExecutionInfo);
}
use of com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo in project intellij-community by JetBrains.
the class AbstractExternalSystemLocalSettings method forgetExternalProjects.
/**
* Asks current settings to drop all information related to external projects which root configs are located at the given paths.
*
* @param linkedProjectPathsToForget target root external project paths
*/
public void forgetExternalProjects(@NotNull Set<String> linkedProjectPathsToForget) {
Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = myAvailableProjects.get();
for (Iterator<Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>>> it = projects.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey().getPath())) {
it.remove();
}
}
for (Iterator<Map.Entry<String, Collection<ExternalTaskPojo>>> it = myAvailableTasks.get().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Collection<ExternalTaskPojo>> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey()) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(entry.getKey(), myExternalSystemId, myProject))) {
it.remove();
}
}
for (Iterator<ExternalTaskExecutionInfo> it = myRecentTasks.get().iterator(); it.hasNext(); ) {
ExternalTaskExecutionInfo taskInfo = it.next();
String path = taskInfo.getSettings().getExternalProjectPath();
if (linkedProjectPathsToForget.contains(path) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(path, myExternalSystemId, myProject))) {
it.remove();
}
}
for (Iterator<Map.Entry<String, ExternalProjectBuildClasspathPojo>> it = myProjectBuildClasspath.get().entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, ExternalProjectBuildClasspathPojo> entry = it.next();
if (linkedProjectPathsToForget.contains(entry.getKey()) || linkedProjectPathsToForget.contains(ExternalSystemApiUtil.getRootProjectPath(entry.getKey(), myExternalSystemId, myProject))) {
it.remove();
}
}
Map<String, Long> modificationStamps = myExternalConfigModificationStamps.get();
for (String path : linkedProjectPathsToForget) {
modificationStamps.remove(path);
}
}
use of com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo in project intellij-community by JetBrains.
the class ExternalSystemActionUtil method buildTaskInfo.
@NotNull
public static ExternalTaskExecutionInfo buildTaskInfo(@NotNull TaskData task) {
ExternalSystemTaskExecutionSettings settings = new ExternalSystemTaskExecutionSettings();
settings.setExternalProjectPath(task.getLinkedExternalProjectPath());
settings.setTaskNames(Collections.singletonList(task.getName()));
settings.setTaskDescriptions(Collections.singletonList(task.getDescription()));
settings.setExternalSystemIdString(task.getOwner().toString());
return new ExternalTaskExecutionInfo(settings, DefaultRunExecutor.EXECUTOR_ID);
}
Aggregations