test/tools/javadoc/api/basic/GetTask_FileManagerTest.java

changeset 1413
bdcef2ef52d2
child 2010
64328fe5e4a6
equal deleted inserted replaced
1412:400a4e8accd3 1413:bdcef2ef52d2
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 GetTask_FileManagerTest
30 */
31
32 import java.io.IOException;
33 import java.nio.file.Path;
34 import java.util.Arrays;
35 import java.util.Set;
36
37 import javax.tools.DocumentationTool;
38 import javax.tools.DocumentationTool.DocumentationTask;
39 import javax.tools.JavaFileObject;
40 import javax.tools.JavaFileObject.Kind;
41 import javax.tools.ToolProvider;
42
43 import com.sun.tools.javac.nio.JavacPathFileManager;
44 import com.sun.tools.javac.nio.PathFileManager;
45 import com.sun.tools.javac.util.Context;
46
47 /**
48 * Tests for DocumentationTool.getTask fileManager parameter.
49 */
50 public class GetTask_FileManagerTest extends APITest {
51 public static void main(String... args) throws Exception {
52 new GetTask_FileManagerTest().run();
53 }
54
55 /**
56 * Verify that an alternate file manager can be specified:
57 * in this case, a PathFileManager.
58 */
59 @Test
60 public void testFileManager() throws Exception {
61 JavaFileObject srcFile = createSimpleJavaFileObject();
62 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
63 PathFileManager fm = new JavacPathFileManager(new Context(), false, null);
64 Path outDir = getOutDir().toPath();
65 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
66 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
67 DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
68 if (t.call()) {
69 System.err.println("task succeeded");
70 checkFiles(outDir, standardExpectFiles);
71 } else {
72 throw new Exception("task failed");
73 }
74 }
75
76 /**
77 * Verify that exceptions from a bad file manager are thrown as expected.
78 */
79 @Test
80 public void testBadFileManager() throws Exception {
81 JavaFileObject srcFile = createSimpleJavaFileObject();
82 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
83 PathFileManager fm = new JavacPathFileManager(new Context(), false, null) {
84 @Override
85 public Iterable<JavaFileObject> list(Location location,
86 String packageName,
87 Set<Kind> kinds,
88 boolean recurse)
89 throws IOException {
90 throw new UnexpectedError();
91 }
92 };
93 Path outDir = getOutDir().toPath();
94 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
95 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
96 DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
97 try {
98 t.call();
99 error("call completed without exception");
100 } catch (RuntimeException e) {
101 Throwable c = e.getCause();
102 if (c.getClass() == UnexpectedError.class)
103 System.err.println("exception caught as expected: " + c);
104 else
105 throw e;
106 }
107 }
108
109 public static class UnexpectedError extends Error { }
110
111 }

mercurial