Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/api/basic/JavadocTaskImplTest.java
38828 views
1
/*
2
* Copyright (c) 2012, 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
* @build APITest
29
* @run main JavadocTaskImplTest
30
*/
31
32
import java.io.File;
33
import java.util.Arrays;
34
import java.util.concurrent.Callable;
35
36
import javax.tools.DocumentationTool;
37
import javax.tools.DocumentationTool.DocumentationTask;
38
import javax.tools.JavaFileObject;
39
import javax.tools.StandardJavaFileManager;
40
import javax.tools.ToolProvider;
41
42
import com.sun.tools.javac.file.JavacFileManager;
43
import com.sun.tools.javac.util.Context;
44
import com.sun.tools.javadoc.Messager;
45
import com.sun.tools.javadoc.api.JavadocTaskImpl;
46
47
/**
48
* Misc tests for JavacTaskImpl.
49
*/
50
public class JavadocTaskImplTest extends APITest {
51
public static void main(String... args) throws Exception {
52
new JavadocTaskImplTest().run();
53
}
54
55
@Test
56
public void testRawCall() throws Exception {
57
JavaFileObject srcFile = createSimpleJavaFileObject();
58
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
59
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
60
File outDir = getOutDir();
61
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
62
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
63
64
@SuppressWarnings("rawtypes")
65
Callable t = tool.getTask(null, fm, null, null, null, files);
66
67
if (t.call() == Boolean.TRUE) {
68
System.err.println("task succeeded");
69
} else {
70
throw new Exception("task failed");
71
}
72
}
73
74
@Test
75
public void testDirectAccess1() throws Exception {
76
JavaFileObject srcFile = createSimpleJavaFileObject();
77
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
78
Context c = new Context();
79
Messager.preRegister(c, "javadoc");
80
StandardJavaFileManager fm = new JavacFileManager(c, true, null);
81
File outDir = getOutDir();
82
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
83
DocumentationTask t = new JavadocTaskImpl(c, null, null, files);
84
if (t.call()) {
85
System.err.println("task succeeded");
86
} else {
87
throw new Exception("task failed");
88
}
89
}
90
91
@Test
92
public void testDirectAccess2() throws Exception {
93
JavaFileObject srcFile = null; // error, provokes NPE
94
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
95
Context c = new Context();
96
Messager.preRegister(c, "javadoc");
97
StandardJavaFileManager fm = new JavacFileManager(c, true, null);
98
File outDir = getOutDir();
99
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
100
try {
101
DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;
102
error("getTask succeeded, no exception thrown");
103
} catch (NullPointerException e) {
104
System.err.println("exception caught as expected: " + e);
105
}
106
}
107
}
108
109
110