Mon, 17 Nov 2014 12:40:43 -0800
Added tag jdk8u31-b09 for changeset 26c46688ce4a
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 */
24 /*
25 * @test
26 * @bug 6493690
27 * @summary javadoc should have a javax.tools.Tool service provider
28 * @build APITest
29 * @run main Task_reuseTest
30 */
32 import java.io.File;
33 import java.util.Arrays;
34 import java.util.Locale;
35 import javax.tools.DocumentationTool;
36 import javax.tools.DocumentationTool.DocumentationTask;
37 import javax.tools.JavaFileObject;
38 import javax.tools.StandardJavaFileManager;
39 import javax.tools.ToolProvider;
41 /**
42 * Tests for reusing a documentation task.
43 */
44 public class Task_reuseTest extends APITest {
45 public static void main(String... args) throws Exception {
46 new Task_reuseTest().run();
47 }
49 /**
50 * Verify that call can only be called once.
51 */
52 @Test
53 public void testReuse() throws Exception {
54 DocumentationTask t = getAndRunTask();
55 try {
56 t.call();
57 error("task was reused without exception");
58 } catch (IllegalStateException e) {
59 System.err.println("caught exception " + e);
60 }
61 }
63 /**
64 * Verify that cannot update task after call
65 */
66 @Test
67 public void testUpdateSetLocale() throws Exception {
68 DocumentationTask t = getAndRunTask();
69 try {
70 t.setLocale(Locale.getDefault());
71 error("task was reused without exception");
72 } catch (IllegalStateException e) {
73 System.err.println("caught exception " + e);
74 }
75 }
77 private DocumentationTask getAndRunTask() throws Exception {
78 JavaFileObject srcFile = createSimpleJavaFileObject();
79 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
80 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
81 File outDir = getOutDir();
82 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
83 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
84 DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
85 if (t.call()) {
86 System.err.println("task succeeded");
87 return t;
88 } else {
89 throw new Exception("task failed");
90 }
91 }
92 }