use of org.gradle.cli.ParsedCommandLineOption 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;
}
Aggregations