Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/tool/EnsureNewOldDoclet.java
40957 views
1
/*
2
* Copyright (c) 2015, 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 8035473 8154482 8154399 8159096 8176131 8176331 8177511
27
* @summary make sure the javadoc tool responds correctly,
28
* to old and new doclet implementations.
29
* @library /tools/lib
30
* @build toolbox.ToolBox toolbox.TestRunner
31
* @run main EnsureNewOldDoclet
32
*/
33
34
import java.io.*;
35
import java.nio.file.Path;
36
import java.util.Arrays;
37
import java.util.Collections;
38
import java.util.List;
39
import java.util.Set;
40
import java.util.regex.Pattern;
41
import java.util.stream.Collectors;
42
import javax.lang.model.element.Element;
43
44
import com.sun.source.doctree.DocTree;
45
46
import toolbox.*;
47
48
49
/**
50
* This test ensures the doclet responds correctly when given
51
* various conditions that force a fall back to the old javadoc
52
* tool.
53
*/
54
public class EnsureNewOldDoclet extends TestRunner {
55
56
final ToolBox tb;
57
final File testSrc;
58
final Path javadocPath;
59
final ExecTask task;
60
final String testClasses;
61
final PrintStream ostream;
62
63
final static String CLASS_NAME = "EnsureNewOldDoclet";
64
final static String OLD_DOCLET_CLASS_NAME = CLASS_NAME + "$OldDoclet";
65
final static String NEW_DOCLET_CLASS_NAME = CLASS_NAME + "$NewDoclet"; //unused
66
final static String NEW_TAGLET_CLASS_NAME = CLASS_NAME + "$NewTaglet";
67
68
final static Pattern OLD_HEADER = Pattern.compile(".*This is not the Standard Doclet.*");
69
final static Pattern NEW_HEADER = Pattern.compile("^Standard Doclet version.*");
70
71
72
final static String OLD_DOCLET_MARKER = "OLD_DOCLET_MARKER";
73
74
final static String NEW_DOCLET_MARKER = "NEW_DOCLET_MARKER";
75
final static String NEW_TAGLET_MARKER = "Registered Taglet " + CLASS_NAME + "\\$NewTaglet";
76
77
final static String NEW_STDDOCLET = "jdk.javadoc.doclet.StandardDoclet";
78
79
80
public EnsureNewOldDoclet() throws Exception {
81
super(System.err);
82
ostream = System.err;
83
testClasses = System.getProperty("test.classes");
84
tb = new ToolBox();
85
javadocPath = tb.getJDKTool("javadoc");
86
task = new ExecTask(tb, javadocPath);
87
testSrc = new File("Foo.java");
88
generateSample(testSrc);
89
}
90
91
void generateSample(File testSrc) throws Exception {
92
String nl = System.getProperty("line.separator");
93
String src = Arrays.asList(
94
"/**",
95
" * A test class to test javadoc. Nothing more nothing less.",
96
" */",
97
" public class Foo{}").stream().collect(Collectors.joining(nl));
98
tb.writeFile(testSrc.getPath(), src);
99
}
100
101
public static void main(String... args) throws Exception {
102
new EnsureNewOldDoclet().runTests();
103
}
104
105
// input: nothing, default mode
106
// outcome: new tool and new doclet
107
@Test
108
public void testDefault() throws Exception {
109
setArgs("-classpath", ".", // insulates us from ambient classpath
110
testSrc.toString());
111
Task.Result tr = task.run(Task.Expect.SUCCESS);
112
List<String> err = tr.getOutputLines(Task.OutputKind.STDERR);
113
checkOutput(testName, err, NEW_HEADER);
114
}
115
116
// input: new doclet and new taglet
117
// outcome: new doclet and new taglet should register
118
@Test
119
public void testNewDocletNewTaglet() throws Exception {
120
setArgs("-classpath", ".", // ambient classpath insulation
121
"-doclet",
122
NEW_STDDOCLET,
123
"-taglet",
124
NEW_TAGLET_CLASS_NAME,
125
"-tagletpath",
126
testClasses,
127
testSrc.toString());
128
Task.Result tr = task.run(Task.Expect.SUCCESS);
129
List<String> out = tr.getOutputLines(Task.OutputKind.STDOUT);
130
List<String> err = tr.getOutputLines(Task.OutputKind.STDERR);
131
checkOutput(testName, err, NEW_HEADER);
132
checkOutput(testName, err, NEW_TAGLET_MARKER);
133
}
134
135
void setArgs(String... args) {
136
ostream.println("cmds: " + Arrays.asList(args));
137
task.args(args);
138
}
139
140
void checkOutput(String testCase, List<String> content, String toFind) throws Exception {
141
checkOutput(testCase, content, Pattern.compile(".*" + toFind + ".*"));
142
}
143
144
void checkOutput(String testCase, List<String> content, Pattern toFind) throws Exception {
145
ostream.println("---" + testCase + "---");
146
content.stream().forEach(x -> System.out.println(x));
147
for (String x : content) {
148
ostream.println(x);
149
if (toFind.matcher(x).matches()) {
150
return;
151
}
152
}
153
throw new Exception(testCase + ": Expected string not found: " + toFind);
154
}
155
156
public static class NewTaglet implements jdk.javadoc.doclet.Taglet {
157
158
@Override
159
public Set<Location> getAllowedLocations() {
160
return Collections.emptySet();
161
}
162
163
@Override
164
public boolean isInlineTag() {
165
return true;
166
}
167
168
@Override
169
public String getName() {
170
return "NewTaglet";
171
}
172
173
@Override
174
public String toString(List<? extends DocTree> tags, Element element) {
175
return tags.toString();
176
}
177
178
}
179
}
180
181