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 jdk.javadoc
29 * @build APITest
30 * @run main GetTask_DocletClassTest
31 * @key randomness
32 */
33
34 import com.sun.javadoc.DocErrorReporter;
35 import com.sun.javadoc.LanguageVersion;
36 import com.sun.javadoc.RootDoc;
37 import java.io.File;
38 import java.util.Arrays;
39 import java.util.Collections;
40 import java.util.Random;
41 import javax.tools.DocumentationTool;
42 import javax.tools.DocumentationTool.DocumentationTask;
43 import javax.tools.JavaFileObject;
44 import javax.tools.StandardJavaFileManager;
45 import javax.tools.ToolProvider;
46
47 /**
48 * Tests for DocumentationTool.getTask docletClass parameter.
49 */
50 public class GetTask_DocletClassTest extends APITest {
51 public static void main(String... args) throws Exception {
52 new GetTask_DocletClassTest().run();
53 }
54
55 /**
56 * Verify that an alternate doclet can be specified.
57 *
58 * There is no standard interface or superclass for a doclet;
59 * the only requirement is that it provides static methods that
60 * can be invoked via reflection. So, for now, the doclet is
61 * specified as a class.
62 * Because we cannot create and use a unique instance of the class,
63 * we verify that the doclet has been called by having it record
64 * (in a static field!) the comment from the last time it was invoked,
65 * which is randomly generated each time the test is run.
66 */
110 return LanguageVersion.JAVA_1_1;
111 }
112 }
113
114 /**
115 * Verify that exceptions from a doclet are thrown as expected.
116 */
117 @Test
118 public void testBadDoclet() throws Exception {
119 JavaFileObject srcFile = createSimpleJavaFileObject();
120 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
121 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
122 File outDir = getOutDir();
123 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
124 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
125 DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
126 try {
127 t.call();
128 error("call completed without exception");
129 } catch (RuntimeException e) {
130 Throwable c = e.getCause();
131 if (c.getClass() == UnexpectedError.class)
132 System.err.println("exception caught as expected: " + c);
133 else
134 throw e;
135 }
136 }
137 }
138
139 public static class UnexpectedError extends Error { }
140
141 public static class BadDoclet {
142 public static boolean start(RootDoc root) {
143 throw new UnexpectedError();
144 }
145
146 public static int optionLength(String option) {
147 return 0; // default is option unknown
148 }
149
|
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 jdk.javadoc
29 * @build APITest
30 * @run main GetTask_DocletClassTest
31 * @key randomness
32 */
33
34 import java.io.File;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.Random;
38 import javax.tools.DocumentationTool;
39 import javax.tools.DocumentationTool.DocumentationTask;
40 import javax.tools.JavaFileObject;
41 import javax.tools.StandardJavaFileManager;
42 import javax.tools.ToolProvider;
43
44 import com.sun.javadoc.DocErrorReporter;
45 import com.sun.javadoc.LanguageVersion;
46 import com.sun.javadoc.RootDoc;
47
48 /**
49 * Tests for DocumentationTool.getTask docletClass parameter.
50 */
51 public class GetTask_DocletClassTest extends APITest {
52 public static void main(String... args) throws Exception {
53 new GetTask_DocletClassTest().run();
54 }
55
56 /**
57 * Verify that an alternate doclet can be specified.
58 *
59 * There is no standard interface or superclass for a doclet;
60 * the only requirement is that it provides static methods that
61 * can be invoked via reflection. So, for now, the doclet is
62 * specified as a class.
63 * Because we cannot create and use a unique instance of the class,
64 * we verify that the doclet has been called by having it record
65 * (in a static field!) the comment from the last time it was invoked,
66 * which is randomly generated each time the test is run.
67 */
111 return LanguageVersion.JAVA_1_1;
112 }
113 }
114
115 /**
116 * Verify that exceptions from a doclet are thrown as expected.
117 */
118 @Test
119 public void testBadDoclet() throws Exception {
120 JavaFileObject srcFile = createSimpleJavaFileObject();
121 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
122 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
123 File outDir = getOutDir();
124 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
125 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
126 DocumentationTask t = tool.getTask(null, fm, null, BadDoclet.class, null, files);
127 try {
128 t.call();
129 error("call completed without exception");
130 } catch (RuntimeException e) {
131 e.printStackTrace();
132 Throwable c = e.getCause();
133 if (c.getClass() == UnexpectedError.class)
134 System.err.println("exception caught as expected: " + c);
135 else
136 throw e;
137 }
138 }
139 }
140
141 public static class UnexpectedError extends Error { }
142
143 public static class BadDoclet {
144 public static boolean start(RootDoc root) {
145 throw new UnexpectedError();
146 }
147
148 public static int optionLength(String option) {
149 return 0; // default is option unknown
150 }
151
|