21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8218998 |
26 * @bug 8218998 8219946 |
27 * @summary Add metadata to generated API documentation files |
27 * @summary Add metadata to generated API documentation files |
28 * @library /tools/lib ../../lib |
28 * @library /tools/lib ../../lib |
29 * @modules jdk.javadoc/jdk.javadoc.internal.tool |
29 * @modules jdk.javadoc/jdk.javadoc.internal.tool |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
30 * @modules jdk.compiler/com.sun.tools.javac.api |
31 * jdk.compiler/com.sun.tools.javac.main |
31 * jdk.compiler/com.sun.tools.javac.main |
60 enum Frames { NO_FRAMES, FRAMES }; |
60 enum Frames { NO_FRAMES, FRAMES }; |
61 enum Index { SINGLE, SPLIT }; |
61 enum Index { SINGLE, SPLIT }; |
62 enum Source { PACKAGES, MODULES }; |
62 enum Source { PACKAGES, MODULES }; |
63 |
63 |
64 final ToolBox tb = new ToolBox(); |
64 final ToolBox tb = new ToolBox(); |
|
65 final Set<String> allBodyClassesFound = new HashSet<>(); |
65 final Set<String> allGeneratorsFound = new HashSet<>(); |
66 final Set<String> allGeneratorsFound = new HashSet<>(); |
66 |
67 |
67 public void runTests() throws Exception { |
68 public void runTests() throws Exception { |
68 for (Source s : Source.values()) { |
69 for (Source s : Source.values()) { |
69 Path src = genSource(s); |
70 Path src = genSource(s); |
124 Set<String> notFound = new TreeSet<>(allGenerators); |
126 Set<String> notFound = new TreeSet<>(allGenerators); |
125 notFound.removeAll(allGeneratorsFound); |
127 notFound.removeAll(allGeneratorsFound); |
126 failed("not found: " + notFound); |
128 failed("not found: " + notFound); |
127 } |
129 } |
128 |
130 |
|
131 checking ("all body classes"); |
|
132 if (allBodyClassesFound.equals(allBodyClasses)) { |
|
133 passed("all gbody classes found"); |
|
134 } else { |
|
135 Set<String> notFound = new TreeSet<>(allBodyClasses); |
|
136 notFound.removeAll(allBodyClassesFound); |
|
137 failed("not found: " + notFound); |
|
138 } |
|
139 |
129 printSummary(); |
140 printSummary(); |
130 } |
141 } |
131 |
142 |
132 final Pattern nl = Pattern.compile("[\\r\\n]+"); |
143 final Pattern nl = Pattern.compile("[\\r\\n]+"); |
|
144 final Pattern bodyPattern = Pattern.compile("<body [^>]*class=\"([^\"]+)\""); |
|
145 final Set<String> allBodyClasses = Set.of( |
|
146 "all-classes-frame", |
|
147 "all-classes-index", |
|
148 "all-packages-index", |
|
149 "class-declaration", |
|
150 "class-use", |
|
151 "constants-summary", |
|
152 "deprecated-list", |
|
153 "doc-file", |
|
154 "frames", |
|
155 "help", |
|
156 "index-redirect", |
|
157 "module-declaration", |
|
158 "module-frame", |
|
159 "module-index", |
|
160 "module-index-frame", |
|
161 "module-package-index-frame", |
|
162 "package-declaration", |
|
163 "package-frame", |
|
164 "package-index", |
|
165 "package-index-frame", |
|
166 "package-tree", |
|
167 "package-use", |
|
168 "serialized-form", |
|
169 "single-index", |
|
170 "source", |
|
171 "split-index", |
|
172 "tree" |
|
173 ); |
|
174 |
|
175 void checkBodyClasses() throws IOException { |
|
176 Path outputDirPath = outputDir.toPath(); |
|
177 for (Path p : tb.findFiles(".html", outputDirPath)) { |
|
178 checkBodyClass(outputDirPath.relativize(p)); |
|
179 } |
|
180 } |
|
181 |
|
182 void checkBodyClass(Path p) { |
|
183 checking("Check body: " + p); |
|
184 |
|
185 List<String> bodyLines = nl.splitAsStream(readOutputFile(p.toString())) |
|
186 .filter(s -> s.contains("<body class=")) |
|
187 .collect(Collectors.toList()); |
|
188 |
|
189 String bodyLine; |
|
190 switch (bodyLines.size()) { |
|
191 case 0: |
|
192 failed("Not found: <body class="); |
|
193 return; |
|
194 case 1: |
|
195 bodyLine = bodyLines.get(0); |
|
196 break; |
|
197 default: |
|
198 failed("Multiple found: <body class="); |
|
199 return; |
|
200 } |
|
201 |
|
202 Matcher m = bodyPattern.matcher(bodyLine); |
|
203 if (m.find()) { |
|
204 String bodyClass = m.group(1); |
|
205 if (allBodyClasses.contains(bodyClass)) { |
|
206 passed("found: " + bodyClass); |
|
207 allBodyClassesFound.add(bodyClass); |
|
208 } else { |
|
209 failed("Unrecognized body class: " + bodyClass); |
|
210 } |
|
211 } else { |
|
212 failed("Unrecognized line:\n" + bodyLine); |
|
213 } |
|
214 } |
|
215 |
133 final Pattern contentPattern = Pattern.compile("content=\"([^\"]+)\">"); |
216 final Pattern contentPattern = Pattern.compile("content=\"([^\"]+)\">"); |
134 final Pattern generatorPattern = Pattern.compile("content=\"javadoc/([^\"]+)\">"); |
217 final Pattern generatorPattern = Pattern.compile("content=\"javadoc/([^\"]+)\">"); |
135 final Set<String> allGenerators = Set.of( |
218 final Set<String> allGenerators = Set.of( |
136 "AllClassesFrameWriter", |
219 "AllClassesFrameWriter", |
137 "AllClassesIndexWriter", |
220 "AllClassesIndexWriter", |