use of org.gradle.api.internal.tasks.options.OptionDescriptor in project gradle by gradle.
the class TaskDetailPrinter method optionToAvailableValues.
@SuppressWarnings("unchecked")
private Map<String, Set<String>> optionToAvailableValues(List<OptionDescriptor> allOptions) {
Map<String, Set<String>> result = new LinkedHashMap<String, Set<String>>();
for (OptionDescriptor optionDescriptor : allOptions) {
if (result.containsKey(optionDescriptor.getName())) {
Collection<String> commonValues = intersection(optionDescriptor.getAvailableValues(), result.get(optionDescriptor.getName()));
result.put(optionDescriptor.getName(), new TreeSet<String>(commonValues));
} else {
result.put(optionDescriptor.getName(), optionDescriptor.getAvailableValues());
}
}
return result;
}
use of org.gradle.api.internal.tasks.options.OptionDescriptor in project gradle by gradle.
the class TaskDetailPrinter method printlnCommandlineOptions.
private void printlnCommandlineOptions(StyledTextOutput output, List<Task> tasks) {
List<OptionDescriptor> allOptions = new ArrayList<OptionDescriptor>();
for (Task task : tasks) {
allOptions.addAll(optionReader.getOptions(task));
}
if (!allOptions.isEmpty()) {
output.println();
output.text("Options").println();
}
Map<String, Set<String>> optionToAvailableOptionsValues = optionToAvailableValues(allOptions);
Map<String, String> optionToDescription = optionToDescription(allOptions);
Iterator<String> optionNames = optionToAvailableOptionsValues.keySet().iterator();
while (optionNames.hasNext()) {
String currentOption = optionNames.next();
Set<String> availableValues = optionToAvailableOptionsValues.get(currentOption);
String optionString = "--" + currentOption;
output.text(INDENT).withStyle(UserInput).text(optionString);
output.text(INDENT).text(optionToDescription.get(currentOption));
if (!availableValues.isEmpty()) {
final int optionDescriptionOffset = 2 * INDENT.length() + optionString.length();
final LinePrefixingStyledTextOutput prefixedOutput = createIndentedOutput(output, optionDescriptionOffset);
prefixedOutput.println();
prefixedOutput.println("Available values are:");
for (String value : availableValues) {
prefixedOutput.text(INDENT);
prefixedOutput.withStyle(UserInput).println(value);
}
} else {
output.println();
}
if (optionNames.hasNext()) {
output.println();
}
}
}
use of org.gradle.api.internal.tasks.options.OptionDescriptor 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