use of org.gradle.cli.ParsedCommandLine 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 org.gradle.cli.ParsedCommandLine in project gradle by gradle.
the class GradleWrapperMain method main.
public static void main(String[] args) throws Exception {
File wrapperJar = wrapperJar();
File propertiesFile = wrapperProperties(wrapperJar);
File rootDir = rootDir(wrapperJar);
CommandLineParser parser = new CommandLineParser();
parser.allowUnknownOptions();
parser.option(GRADLE_USER_HOME_OPTION, GRADLE_USER_HOME_DETAILED_OPTION).hasArgument();
parser.option(GRADLE_QUIET_OPTION, GRADLE_QUIET_DETAILED_OPTION);
SystemPropertiesCommandLineConverter converter = new SystemPropertiesCommandLineConverter();
converter.configure(parser);
ParsedCommandLine options = parser.parse(args);
Properties systemProperties = System.getProperties();
systemProperties.putAll(converter.convert(options, new HashMap<String, String>()));
File gradleUserHome = gradleUserHome(options);
addSystemProperties(gradleUserHome, rootDir);
Logger logger = logger(options);
WrapperExecutor wrapperExecutor = WrapperExecutor.forWrapperPropertiesFile(propertiesFile);
wrapperExecutor.execute(args, new Install(logger, new Download(logger, "gradlew", wrapperVersion()), new PathAssembler(gradleUserHome)), new BootstrapMainStarter());
}
use of org.gradle.cli.ParsedCommandLine in project liferay-ide by liferay.
the class AbstractLiferayGradleTaskAction method _buildTaskExecutionInfo.
private ExternalTaskExecutionInfo _buildTaskExecutionInfo(Project project, @NotNull String projectPath, @NotNull String fullCommandLine) {
CommandLineParser gradleCmdParser = new CommandLineParser();
GradleCommandLineOptionsConverter commandLineConverter = new GradleCommandLineOptionsConverter();
commandLineConverter.configure(gradleCmdParser);
ParsedCommandLine parsedCommandLine = gradleCmdParser.parse(ParametersListUtil.parse(fullCommandLine, true));
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, " ");
} else {
return "--" + longOptionName;
}
}, " ");
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 clae) {
NotificationData notificationData = new NotificationData("<b>Command-line arguments cannot be parsed</b>", "<i>" + _taskName + "</i> \n" + clae.getMessage(), NotificationCategory.WARNING, NotificationSource.TASK_EXECUTION);
notificationData.setBalloonNotification(true);
ExternalSystemNotificationManager externalSystemNotificationManager = ExternalSystemNotificationManager.getInstance(project);
externalSystemNotificationManager.showNotification(GradleConstants.SYSTEM_ID, notificationData);
return null;
}
}
use of org.gradle.cli.ParsedCommandLine in project gradle by gradle.
the class CommandLineTaskConfigurer method configureTasksNow.
private List<String> configureTasksNow(Collection<Task> tasks, List<String> arguments) {
List<String> remainingArguments = null;
for (Task task : tasks) {
CommandLineParser parser = new CommandLineParser();
final List<OptionDescriptor> commandLineOptions = optionReader.getOptions(task);
for (OptionDescriptor optionDescriptor : commandLineOptions) {
String optionName = optionDescriptor.getName();
org.gradle.cli.CommandLineOption option = parser.option(optionName);
option.hasDescription(optionDescriptor.getDescription());
option.hasArgument(optionDescriptor.getArgumentType());
}
ParsedCommandLine parsed;
try {
parsed = parser.parse(arguments);
} catch (CommandLineArgumentException e) {
// we expect that all options must be applicable for each task
throw new TaskConfigurationException(task.getPath(), "Problem configuring task " + task.getPath() + " from command line.", e);
}
for (OptionDescriptor commandLineOptionDescriptor : commandLineOptions) {
final String name = commandLineOptionDescriptor.getName();
if (parsed.hasOption(name)) {
ParsedCommandLineOption o = parsed.option(name);
try {
commandLineOptionDescriptor.apply(task, o.getValues());
} catch (TypeConversionException ex) {
throw new TaskConfigurationException(task.getPath(), String.format("Problem configuring option '%s' on task '%s' from command line.", name, task.getPath()), ex);
}
}
}
assert remainingArguments == null || remainingArguments.equals(parsed.getExtraArguments()) : "we expect all options to be consumed by each task so remainingArguments should be the same for each task";
remainingArguments = parsed.getExtraArguments();
}
return remainingArguments;
}
use of org.gradle.cli.ParsedCommandLine in project gradle by gradle.
the class BuildLogLevelMixIn method getBuildLogLevel.
public LogLevel getBuildLogLevel() {
LoggingCommandLineConverter converter = new LoggingCommandLineConverter();
CommandLineParser parser = new CommandLineParser().allowUnknownOptions().allowMixedSubcommandsAndOptions();
converter.configure(parser);
List<String> arguments = parameters.getArguments();
ParsedCommandLine parsedCommandLine = parser.parse(arguments == null ? Collections.<String>emptyList() : arguments);
// configure verbosely only if arguments do not specify any log level.
if (parameters.getVerboseLogging() && !parsedCommandLine.hasAnyOption(converter.getLogLevelOptions())) {
return LogLevel.DEBUG;
}
LoggingConfiguration loggingConfiguration = converter.convert(parsedCommandLine, new DefaultLoggingConfiguration());
return loggingConfiguration.getLogLevel();
}
Aggregations