Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/tool/api/basic/DocletPathTest.java
40983 views
1
/*
2
* Copyright (c) 2012, 2015, 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 6493690
27
* @summary javadoc should have a javax.tools.Tool service provider
28
* @modules java.compiler
29
* jdk.compiler
30
* @build APITest
31
* @run main DocletPathTest
32
*/
33
34
import java.io.File;
35
import java.io.PrintWriter;
36
import java.io.StringWriter;
37
import java.util.Arrays;
38
39
import javax.tools.DocumentationTool;
40
import javax.tools.DocumentationTool.DocumentationTask;
41
import javax.tools.JavaCompiler;
42
import javax.tools.JavaFileObject;
43
import javax.tools.StandardJavaFileManager;
44
import javax.tools.StandardLocation;
45
import javax.tools.ToolProvider;
46
47
/**
48
* Tests for locating a doclet via the file manager's DOCLET_PATH.
49
*/
50
public class DocletPathTest extends APITest {
51
public static void main(String... args) throws Exception {
52
new DocletPathTest().run();
53
}
54
55
/**
56
* Verify that an alternate doclet can be specified, and located via
57
* the file manager's DOCLET_PATH.
58
*/
59
@Test
60
public void testDocletPath() throws Exception {
61
JavaFileObject docletSrc =
62
createSimpleJavaFileObject("DocletOnDocletPath", docletSrcText);
63
File docletDir = getOutDir("classes");
64
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
65
try (StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null)) {
66
cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(docletDir));
67
Iterable<? extends JavaFileObject> cfiles = Arrays.asList(docletSrc);
68
if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
69
throw new Exception("cannot compile doclet");
70
}
71
72
JavaFileObject srcFile = createSimpleJavaFileObject();
73
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
74
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
75
File outDir = getOutDir("api");
76
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
77
fm.setLocation(DocumentationTool.Location.DOCLET_PATH, Arrays.asList(docletDir));
78
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
79
Iterable<String> options = Arrays.asList("-doclet", "DocletOnDocletPath");
80
StringWriter sw = new StringWriter();
81
PrintWriter pw = new PrintWriter(sw);
82
DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
83
boolean ok = t.call();
84
String out = sw.toString();
85
System.err.println(">>" + out + "<<");
86
if (ok) {
87
if (out.contains(TEST_STRING)) {
88
System.err.println("doclet executed as expected");
89
} else {
90
error("test string not found in doclet output");
91
}
92
} else {
93
error("task failed");
94
}
95
}
96
}
97
98
private static final String TEST_STRING = "DocletOnDocletPath found and running";
99
100
private static final String docletSrcText =
101
"""
102
import jdk.javadoc.doclet.*;
103
import javax.lang.model.SourceVersion;
104
import java.util.List;
105
import java.util.Collections;
106
import java.util.Set;
107
import jdk.javadoc.doclet.Doclet;
108
import java.util.Locale;
109
import jdk.javadoc.doclet.Reporter;
110
public class DocletOnDocletPath implements Doclet {
111
public boolean run(DocletEnvironment doc) {
112
reporter.print(javax.tools.Diagnostic.Kind.NOTE, \"""" + TEST_STRING + """
113
");
114
return true;
115
}
116
public Set<Doclet.Option> getSupportedOptions() {return Collections.emptySet();}
117
public SourceVersion getSupportedSourceVersion() {
118
return SourceVersion.latestSupported();
119
}
120
Reporter reporter;
121
public void init(Locale locale, Reporter reporter) {
122
this.reporter = reporter;
123
return;
124
} public String getName() { return "DocletOnPath"; }
125
}
126
""";
127
}
128
129
130