use of org.jetbrains.plugins.gradle.service.execution.cmd.GradleCommandLineOptionsConverter 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);
}
Aggregations