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 8141492 |
|
27 * @summary javadoc should have a javax.tools.Tool service provider |
|
28 * @modules java.compiler |
|
29 * jdk.compiler |
|
30 * @build APITest |
|
31 * @run main GetTask_OptionsTest |
|
32 */ |
|
33 |
|
34 import java.io.File; |
|
35 import java.util.Arrays; |
|
36 import java.util.Set; |
|
37 import java.util.TreeSet; |
|
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 /** |
|
45 * Tests for DocumentationTool.getTask options parameter. |
|
46 */ |
|
47 public class GetTask_OptionsTest extends APITest { |
|
48 public static void main(String... args) throws Exception { |
|
49 new GetTask_OptionsTest().run(); |
|
50 } |
|
51 |
|
52 /** |
|
53 * Verify that expected output files are written for given options. |
|
54 */ |
|
55 @Test |
|
56 public void testNoIndex() throws Exception { |
|
57 JavaFileObject srcFile = createSimpleJavaFileObject(); |
|
58 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
|
59 try (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 Iterable<String> options = Arrays.asList("-noindex"); |
|
64 DocumentationTask t = tool.getTask(null, fm, null, null, options, files); |
|
65 if (t.call()) { |
|
66 System.err.println("task succeeded"); |
|
67 Set<String> expectFiles = new TreeSet<String>(noIndexFiles); |
|
68 checkFiles(outDir, expectFiles); |
|
69 } else { |
|
70 error("task failed"); |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * Verify null is handled correctly. |
|
77 */ |
|
78 @Test |
|
79 public void testNull() throws Exception { |
|
80 JavaFileObject srcFile = createSimpleJavaFileObject(); |
|
81 DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
|
82 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
|
83 File outDir = getOutDir(); |
|
84 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
|
85 Iterable<String> options = Arrays.asList((String) null); |
|
86 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
|
87 try { |
|
88 DocumentationTask t = tool.getTask(null, fm, null, null, options, files); |
|
89 error("getTask succeeded, no exception thrown"); |
|
90 } catch (NullPointerException e) { |
|
91 System.err.println("exception caught as expected: " + e); |
|
92 } |
|
93 } |
|
94 } |
|
95 |
|
96 } |
|
97 |
|