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 GetTask_DiagListenerTest
30 */
32 import java.io.File;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import javax.tools.Diagnostic;
37 import javax.tools.DiagnosticCollector;
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;
44 /**
45 * Tests for DocumentationTool.getTask diagnosticListener parameter.
46 */
47 public class GetTask_DiagListenerTest extends APITest {
48 public static void main(String... args) throws Exception {
49 new GetTask_DiagListenerTest().run();
50 }
52 /**
53 * Verify that a diagnostic listener can be specified.
54 * Note that messages from the tool and doclet are imperfectly modeled
55 * because the DocErrorReporter API works in terms of localized strings
56 * and file:line positions. Therefore, messages reported via DocErrorReporter
57 * and simply wrapped and passed through.
58 */
59 @Test
60 public void testDiagListener() throws Exception {
61 JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }");
62 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
63 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
64 File outDir = getOutDir();
65 fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
66 Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
67 DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
68 DocumentationTask t = tool.getTask(null, fm, dc, null, null, files);
69 if (t.call()) {
70 throw new Exception("task succeeded unexpectedly");
71 } else {
72 List<String> diagCodes = new ArrayList<String>();
73 for (Diagnostic d: dc.getDiagnostics()) {
74 System.err.println(d);
75 diagCodes.add(d.getCode());
76 }
77 List<String> expect = Arrays.asList(
78 "javadoc.note.msg", // Loading source file
79 "compiler.err.expected3", // class, interface, or enum expected
80 "javadoc.note.msg"); // 1 error
81 if (!diagCodes.equals(expect))
82 throw new Exception("unexpected diagnostics occurred");
83 System.err.println("diagnostics received as expected");
84 }
85 }
87 }