use of org.apache.beam.sdk.options.Description in project beam by apache.
the class PipelineOptionsTableGenerator method extractOptions.
/**
* Returns the extracted list of options via reflections on FlinkPipelineOptions. Options are
* returned sorted in alphabetical order since Java does not guarantee any consistent order on the
* class methods.
*/
private static List<Option> extractOptions(boolean isPython) {
List<Option> options = new ArrayList<>();
for (Method method : FlinkPipelineOptions.class.getDeclaredMethods()) {
String name;
String description;
String defaultValue = null;
name = method.getName();
if (name.matches("^(get|is).*")) {
name = name.replaceFirst("^(get|is)", "");
if (isPython) {
name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
} else {
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
}
Description descriptionAnnotation = method.getAnnotation(Description.class);
if (descriptionAnnotation == null) {
throw new RuntimeException("All pipeline options should have a description. Please add one for " + name);
}
description = descriptionAnnotation.value();
Optional<String> defaultValueFromAnnotation = getDefaultValueFromAnnotation(method);
if (defaultValueFromAnnotation.isPresent()) {
defaultValue = defaultValueFromAnnotation.get();
}
options.add(new Option(name, description, defaultValue));
}
}
options.sort(Comparator.comparing(option -> option.name));
return options;
}
Aggregations