@Test public void testCommonOptions() throws IOException, ClassNotFoundException { final String projectRootDir = System.getProperty("rootDir"); final String outputDirectory = TMP.newFolder().getAbsolutePath(); final OptionsClassLocation[] locations = new OptionsClassLocation[] { new OptionsClassLocation("flink-docs", TestCommonOptions.class.getPackage().getName()) }; ConfigOptionsDocGenerator.generateCommonSection(projectRootDir, outputDirectory, locations, "src/test/java"); Formatter formatter = new HtmlFormatter(); String expected = "<table class=\"table table-bordered\">\n" + " <thead>\n" + " <tr>\n" + " <th class=\"text-left\" style=\"width: 20%\">Key</th>\n" + " <th class=\"text-left\" style=\"width: 15%\">Default</th>\n" + " <th class=\"text-left\" style=\"width: 65%\">Description</th>\n" + " </tr>\n" + " </thead>\n" + " <tbody>\n" + " <tr>\n" + " <td><h5>" + TestCommonOptions.COMMON_POSITIONED_OPTION.key() + "</h5></td>\n" + " <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_POSITIONED_OPTION.defaultValue() + "</td>\n" + " <td>" + formatter.format(TestCommonOptions.COMMON_POSITIONED_OPTION.description()) + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td><h5>" + TestCommonOptions.COMMON_OPTION.key() + "</h5></td>\n" + " <td style=\"word-wrap: break-word;\">" + TestCommonOptions.COMMON_OPTION.defaultValue() + "</td>\n" + " <td>" + formatter.format(TestCommonOptions.COMMON_OPTION.description()) + "</td>\n" + " </tr>\n" + " </tbody>\n" + "</table>\n"; String output = FileUtils.readFile(Paths.get(outputDirectory, ConfigOptionsDocGenerator.COMMON_SECTION_FILE_NAME).toFile(), StandardCharsets.UTF_8.name()); assertEquals(expected, output); }
@VisibleForTesting static void generateCommonSection(String rootDir, String outputDirectory, OptionsClassLocation[] locations, String pathPrefix) throws IOException, ClassNotFoundException { List<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); for (OptionsClassLocation location : locations) { commonOptions.addAll(findCommonOptions(rootDir, location.getModule(), location.getPackage(), pathPrefix)); } commonOptions.sort((o1, o2) -> { int position1 = o1.field.getAnnotation(Documentation.CommonOption.class).position(); int position2 = o2.field.getAnnotation(Documentation.CommonOption.class).position(); if (position1 == position2) { return o1.option.key().compareTo(o2.option.key()); } else { return Integer.compare(position1, position2); } }); String commonHtmlTable = toHtmlTable(commonOptions); Files.write(Paths.get(outputDirectory, COMMON_SECTION_FILE_NAME), commonHtmlTable.getBytes(StandardCharsets.UTF_8)); }
ConfigOptionsDocGenerator { @VisibleForTesting static void generateCommonSection(String rootDir, String outputDirectory, OptionsClassLocation[] locations, String pathPrefix) throws IOException, ClassNotFoundException { List<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); for (OptionsClassLocation location : locations) { commonOptions.addAll(findCommonOptions(rootDir, location.getModule(), location.getPackage(), pathPrefix)); } commonOptions.sort((o1, o2) -> { int position1 = o1.field.getAnnotation(Documentation.CommonOption.class).position(); int position2 = o2.field.getAnnotation(Documentation.CommonOption.class).position(); if (position1 == position2) { return o1.option.key().compareTo(o2.option.key()); } else { return Integer.compare(position1, position2); } }); String commonHtmlTable = toHtmlTable(commonOptions); Files.write(Paths.get(outputDirectory, COMMON_SECTION_FILE_NAME), commonHtmlTable.getBytes(StandardCharsets.UTF_8)); } }
ConfigOptionsDocGenerator { @VisibleForTesting static void generateCommonSection(String rootDir, String outputDirectory, OptionsClassLocation[] locations, String pathPrefix) throws IOException, ClassNotFoundException { List<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); for (OptionsClassLocation location : locations) { commonOptions.addAll(findCommonOptions(rootDir, location.getModule(), location.getPackage(), pathPrefix)); } commonOptions.sort((o1, o2) -> { int position1 = o1.field.getAnnotation(Documentation.CommonOption.class).position(); int position2 = o2.field.getAnnotation(Documentation.CommonOption.class).position(); if (position1 == position2) { return o1.option.key().compareTo(o2.option.key()); } else { return Integer.compare(position1, position2); } }); String commonHtmlTable = toHtmlTable(commonOptions); Files.write(Paths.get(outputDirectory, COMMON_SECTION_FILE_NAME), commonHtmlTable.getBytes(StandardCharsets.UTF_8)); } private  ConfigOptionsDocGenerator(); }
ConfigOptionsDocGenerator { @VisibleForTesting static void generateCommonSection(String rootDir, String outputDirectory, OptionsClassLocation[] locations, String pathPrefix) throws IOException, ClassNotFoundException { List<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); for (OptionsClassLocation location : locations) { commonOptions.addAll(findCommonOptions(rootDir, location.getModule(), location.getPackage(), pathPrefix)); } commonOptions.sort((o1, o2) -> { int position1 = o1.field.getAnnotation(Documentation.CommonOption.class).position(); int position2 = o2.field.getAnnotation(Documentation.CommonOption.class).position(); if (position1 == position2) { return o1.option.key().compareTo(o2.option.key()); } else { return Integer.compare(position1, position2); } }); String commonHtmlTable = toHtmlTable(commonOptions); Files.write(Paths.get(outputDirectory, COMMON_SECTION_FILE_NAME), commonHtmlTable.getBytes(StandardCharsets.UTF_8)); } private  ConfigOptionsDocGenerator(); static void main(String[] args); }
ConfigOptionsDocGenerator { @VisibleForTesting static void generateCommonSection(String rootDir, String outputDirectory, OptionsClassLocation[] locations, String pathPrefix) throws IOException, ClassNotFoundException { List<OptionWithMetaInfo> commonOptions = new ArrayList<>(32); for (OptionsClassLocation location : locations) { commonOptions.addAll(findCommonOptions(rootDir, location.getModule(), location.getPackage(), pathPrefix)); } commonOptions.sort((o1, o2) -> { int position1 = o1.field.getAnnotation(Documentation.CommonOption.class).position(); int position2 = o2.field.getAnnotation(Documentation.CommonOption.class).position(); if (position1 == position2) { return o1.option.key().compareTo(o2.option.key()); } else { return Integer.compare(position1, position2); } }); String commonHtmlTable = toHtmlTable(commonOptions); Files.write(Paths.get(outputDirectory, COMMON_SECTION_FILE_NAME), commonHtmlTable.getBytes(StandardCharsets.UTF_8)); } private  ConfigOptionsDocGenerator(); static void main(String[] args);  }