Search in sources :

Example 1 with ConfigGroup

use of org.apache.flink.annotation.docs.ConfigGroup in project flink by apache.

the class ConfigOptionsDocGenerator method generateTablesForClass.

@VisibleForTesting
static List<Tuple2<ConfigGroup, String>> generateTablesForClass(Class<?> optionsClass) {
    ConfigGroups configGroups = optionsClass.getAnnotation(ConfigGroups.class);
    List<OptionWithMetaInfo> allOptions = extractConfigOptions(optionsClass);
    if (allOptions.isEmpty()) {
        return Collections.emptyList();
    }
    List<Tuple2<ConfigGroup, String>> tables;
    if (configGroups != null) {
        tables = new ArrayList<>(configGroups.groups().length + 1);
        Tree tree = new Tree(configGroups.groups(), allOptions);
        for (ConfigGroup group : configGroups.groups()) {
            List<OptionWithMetaInfo> configOptions = tree.findConfigOptions(group);
            if (!configOptions.isEmpty()) {
                sortOptions(configOptions);
                tables.add(Tuple2.of(group, toHtmlTable(configOptions)));
            }
        }
        List<OptionWithMetaInfo> configOptions = tree.getDefaultOptions();
        if (!configOptions.isEmpty()) {
            sortOptions(configOptions);
            tables.add(Tuple2.of(null, toHtmlTable(configOptions)));
        }
    } else {
        sortOptions(allOptions);
        tables = Collections.singletonList(Tuple2.of(null, toHtmlTable(allOptions)));
    }
    return tables;
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) ConfigGroups(org.apache.flink.annotation.docs.ConfigGroups) ConfigGroup(org.apache.flink.annotation.docs.ConfigGroup) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting)

Example 2 with ConfigGroup

use of org.apache.flink.annotation.docs.ConfigGroup in project flink by apache.

the class ConfigOptionsDocGenerator method createTable.

private static void createTable(String rootDir, String module, String packageName, String outputDirectory, String pathPrefix) throws IOException, ClassNotFoundException {
    processConfigOptions(rootDir, module, packageName, pathPrefix, optionsClass -> {
        List<Tuple2<ConfigGroup, String>> tables = generateTablesForClass(optionsClass);
        for (Tuple2<ConfigGroup, String> group : tables) {
            String name;
            if (group.f0 == null) {
                Matcher matcher = CLASS_NAME_PATTERN.matcher(optionsClass.getSimpleName());
                if (!matcher.matches()) {
                    throw new RuntimeException("Pattern did not match for " + optionsClass.getSimpleName() + '.');
                }
                name = matcher.group(CLASS_PREFIX_GROUP);
            } else {
                name = group.f0.name();
            }
            String outputFile = toSnakeCase(name) + "_configuration.html";
            Files.write(Paths.get(outputDirectory, outputFile), group.f1.getBytes(StandardCharsets.UTF_8));
        }
    });
}
Also used : Matcher(java.util.regex.Matcher) Tuple2(org.apache.flink.api.java.tuple.Tuple2) ConfigGroup(org.apache.flink.annotation.docs.ConfigGroup)

Aggregations

ConfigGroup (org.apache.flink.annotation.docs.ConfigGroup)2 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 Matcher (java.util.regex.Matcher)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 ConfigGroups (org.apache.flink.annotation.docs.ConfigGroups)1