/* * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 8218998 8219946 * @summary Add metadata to generated API documentation files * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * jdk.javadoc/jdk.javadoc.internal.api * jdk.javadoc/jdk.javadoc.internal.tool * @build toolbox.ToolBox toolbox.JavacTask javadoc.tester.* * @run main TestMetadata */ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import toolbox.ModuleBuilder; import toolbox.ToolBox; import javadoc.tester.JavadocTester; public class TestMetadata extends JavadocTester { public static void main(String... args) throws Exception { TestMetadata tester = new TestMetadata(); tester.runTests(); } enum Index { SINGLE, SPLIT }; enum Source { PACKAGES, MODULES }; final ToolBox tb = new ToolBox(); final Set allBodyClassesFound = new HashSet<>(); final Set allGeneratorsFound = new HashSet<>(); public void runTests() throws Exception { for (Source s : Source.values()) { Path src = genSource(s); for (Index i : Index.values()) { List args = new ArrayList<>(); args.add("-d"); args.add(String.format("out-%s-%s", s, i)); args.add("-use"); if (s != Source.MODULES) { args.add("-linksource"); // broken, with modules: JDK-8219060 } if (i == Index.SPLIT) { args.add("-splitIndex"); } if (s == Source.PACKAGES) { args.add("-sourcepath"); args.add(src.toString()); args.add("pA"); args.add("pB"); } else { args.add("--module-source-path"); args.add(src.toString()); args.add("--module"); args.add("mA,mB"); } javadoc(args.toArray(new String[args.size()])); checkExit(Exit.OK); checkBodyClasses(); checkMetadata(); // spot check the descriptions for declarations switch (s) { case PACKAGES: checkOutput("pA/package-summary.html", true, ""); checkOutput("pA/CA.html", true, ""); break; case MODULES: checkOutput("mA/module-summary.html", true, ""); checkOutput("mA/pA/package-summary.html", true, ""); checkOutput("mA/pA/CA.html", true, ""); break; } } } checking ("all generators"); if (allGeneratorsFound.equals(allGenerators)) { passed("all generators found"); } else { Set notFound = new TreeSet<>(allGenerators); notFound.removeAll(allGeneratorsFound); failed("not found: " + notFound); } checking ("all body classes"); if (allBodyClassesFound.equals(allBodyClasses)) { passed("all gbody classes found"); } else { Set notFound = new TreeSet<>(allBodyClasses); notFound.removeAll(allBodyClassesFound); failed("not found: " + notFound); } printSummary(); } final Pattern nl = Pattern.compile("[\\r\\n]+"); final Pattern bodyPattern = Pattern.compile("]*class=\"([^\"]+)\""); final Set allBodyClasses = Set.of( "all-classes-index", "all-packages-index", "class-declaration", "class-use", "constants-summary", "deprecated-list", "doc-file", "help", "index-redirect", "module-declaration", "module-index", "package-declaration", "package-index", "package-tree", "package-use", "serialized-form", "single-index", "source", "split-index", "tree" ); void checkBodyClasses() throws IOException { Path outputDirPath = outputDir.toPath(); for (Path p : tb.findFiles(".html", outputDirPath)) { checkBodyClass(outputDirPath.relativize(p)); } } void checkBodyClass(Path p) { checking("Check body: " + p); List bodyLines = nl.splitAsStream(readOutputFile(p.toString())) .filter(s -> s.contains(""); final Pattern generatorPattern = Pattern.compile("content=\"javadoc/([^\"]+)\">"); final Set allGenerators = Set.of( "AllClassesIndexWriter", "AllPackagesIndexWriter", "AnnotationTypeWriterImpl", "ClassUseWriter", "ClassWriterImpl", "ConstantsSummaryWriterImpl", "DeprecatedListWriter", "DocFileWriter", "HelpWriter", "IndexRedirectWriter", "ModuleIndexWriter", "ModuleWriterImpl", "PackageIndexWriter", "PackageTreeWriter", "PackageUseWriter", "PackageWriterImpl", "SerializedFormWriterImpl", "SingleIndexWriter", "SourceToHTMLConverter", "SplitIndexWriter", "TreeWriter" ); void checkMetadata() throws IOException { Path outputDirPath = outputDir.toPath(); for (Path p : tb.findFiles(".html", outputDirPath)) { checkMetadata(outputDirPath.relativize(p)); } } void checkMetadata(Path p) { checking("Check generator: " + p); List generators = nl.splitAsStream(readOutputFile(p.toString())) .filter(s -> s.contains(" descriptions = nl.splitAsStream(readOutputFile(p.toString())) .filter(s -> s.contains("\nExtra"); break; case MODULES: new ModuleBuilder(tb, "mA") .exports("pA") .classes("/** Package mA/pA. */ package pA;") .classes("/** Class mA/pA.CA. */ package pA; public class CA { }") .write(src); new ModuleBuilder(tb, "mB") .exports("pB") .classes("/** Package mB/pB. */ package pB;") .classes("/** Class mB/pB.CB. */ package pB; public class CB { }") .write(src); break; } return src; } }