Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/doclet/testDocFiles/TestDocFiles.java
40971 views
1
/*
2
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8008949 8234051 8245696
27
* @summary doclet crashes if HTML files in module doc-files directories
28
* @library /tools/lib ../../lib
29
* @modules jdk.javadoc/jdk.javadoc.internal.tool
30
* @build toolbox.ToolBox javadoc.tester.*
31
* @run main TestDocFiles
32
*/
33
34
import java.io.IOException;
35
import java.nio.file.Path;
36
import java.util.ArrayList;
37
import java.util.List;
38
39
import toolbox.ToolBox;
40
import javadoc.tester.JavadocTester;
41
42
public class TestDocFiles extends JavadocTester {
43
44
public static void main(String... args) throws Exception {
45
TestDocFiles tester = new TestDocFiles();
46
tester.runTests(m -> new Object[] { Path.of(m.getName()) });
47
}
48
49
ToolBox tb = new ToolBox();
50
51
/**
52
* Check doc-files support for a package that is not in a module.
53
* @param base the base directory for scratch files
54
* @throws IOException if an exception occurs
55
*/
56
@Test
57
public void testPackage(Path base) throws IOException {
58
Path src = base.resolve("src");
59
60
// write the skeletal Java files
61
tb.writeJavaFiles(src,
62
"package p; public class C { }\n");
63
64
// write the doc files for the package
65
Path pkgDocFiles = src.resolve("p").resolve("doc-files");
66
tb.writeFile(pkgDocFiles.resolve("pkg-file.txt"),
67
"package text file\n");
68
tb.writeFile(pkgDocFiles.resolve("pkg-file.html"),
69
"""
70
<html>
71
<head><title>Package HTML file</title></head>
72
<body><h1>Package HTML file</h1>File content</body>
73
</html>
74
""");
75
76
javadoc("-d", base.resolve("out").toString(),
77
"--source-path", src.toString(),
78
"p");
79
checkExit(Exit.OK);
80
81
checkOutput("p/doc-files/pkg-file.txt", true,
82
"package text file");
83
checkOutput("p/doc-files/pkg-file.html", true,
84
"Package HTML file");
85
}
86
87
/**
88
* Check doc-files support for a module and a package that is in a module.
89
* @param base the base directory for scratch files
90
* @throws IOException if an exception occurs
91
*/
92
@Test
93
public void testModules(Path base) throws IOException {
94
Path src = base.resolve("src");
95
96
// write the skeletal Java files
97
tb.writeJavaFiles(src,
98
"module m { exports p; }\n",
99
"package p; public class C { }\n");
100
101
// write the doc files for the module
102
Path mdlDocFiles = src.resolve("doc-files");
103
tb.writeFile(mdlDocFiles.resolve("mdl-file.txt"),
104
"module text file\n");
105
tb.writeFile(mdlDocFiles.resolve("mdl-file.html"),
106
"""
107
<html>
108
<head><title>Module HTML file</title></head>
109
<body><h1>Module HTML file</h1>File content</body>
110
</html>
111
""");
112
113
// write the doc files for a package in the module
114
Path pkgDocFiles = src.resolve("p").resolve("doc-files");
115
tb.writeFile(pkgDocFiles.resolve("pkg-file.txt"),
116
"package text file\n");
117
tb.writeFile(pkgDocFiles.resolve("pkg-file.html"),
118
"""
119
<html>
120
<head><title>Package HTML file</title></head>
121
<body><h1>Package HTML file</h1>File content</body>
122
</html>
123
""");
124
125
javadoc("-d", base.resolve("out").toString(),
126
"--source-path", src.toString(),
127
"--module", "m");
128
checkExit(Exit.OK);
129
130
checkOutput("m/doc-files/mdl-file.txt", true,
131
"module text file");
132
checkOutput("m/doc-files/mdl-file.html", true,
133
"Module HTML file");
134
checkOutput("m/p/doc-files/pkg-file.txt", true,
135
"package text file");
136
checkOutput("m/p/doc-files/pkg-file.html", true,
137
"Package HTML file");
138
}
139
140
@Test
141
public void testBadFiles(Path base) throws IOException {
142
Path src = base.resolve("src");
143
144
tb.writeJavaFiles(src,
145
"package p; public class C { }");
146
Path df = src.resolve("p").resolve("doc-files");
147
148
// note that '?' may be an illegal filename character on some systems (e.g. Windows)
149
List<String> cases = List.of("valid", "#bad#", "#bad", "bad#bad", "bad?bad");
150
List<Path> files = new ArrayList<>();
151
for (String s : cases) {
152
try {
153
Path f = df.resolve(s);
154
tb.writeFile(f, "dummy contents");
155
files.add(f);
156
} catch (Throwable t) {
157
out.println("Cannot write doc-file " + s);
158
}
159
}
160
161
javadoc("-d", base.resolve("out").toString(),
162
"--source-path", src.toString(),
163
"p");
164
checkExit(Exit.OK);
165
166
// only check for those files
167
for (Path f : files) {
168
if (f.getFileName().toString().contains("valid")) {
169
checkOutput("p/doc-files/" + f.getFileName(), true,
170
"dummy contents");
171
} else {
172
// be careful handing file separator characters in the message
173
checkOutput(Output.OUT, true,
174
"warning: File " + f + " not copied: invalid name");
175
}
176
}
177
}
178
}
179
180