aoqi@0: /* aoqi@0: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 6493690 aoqi@0: * @summary javadoc should have a javax.tools.Tool service provider aoqi@0: * @build APITest aoqi@0: * @run main GetTask_DiagListenerTest aoqi@0: */ aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Arrays; aoqi@0: import java.util.List; aoqi@0: import javax.tools.Diagnostic; aoqi@0: import javax.tools.DiagnosticCollector; aoqi@0: import javax.tools.DocumentationTool; aoqi@0: import javax.tools.DocumentationTool.DocumentationTask; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: import javax.tools.StandardJavaFileManager; aoqi@0: import javax.tools.ToolProvider; aoqi@0: aoqi@0: /** aoqi@0: * Tests for DocumentationTool.getTask diagnosticListener parameter. aoqi@0: */ aoqi@0: public class GetTask_DiagListenerTest extends APITest { aoqi@0: public static void main(String... args) throws Exception { aoqi@0: new GetTask_DiagListenerTest().run(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Verify that a diagnostic listener can be specified. aoqi@0: * Note that messages from the tool and doclet are imperfectly modeled aoqi@0: * because the DocErrorReporter API works in terms of localized strings aoqi@0: * and file:line positions. Therefore, messages reported via DocErrorReporter aoqi@0: * and simply wrapped and passed through. aoqi@0: */ aoqi@0: @Test aoqi@0: public void testDiagListener() throws Exception { aoqi@0: JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", "package pkg; public error { }"); aoqi@0: DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); aoqi@0: StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); aoqi@0: File outDir = getOutDir(); aoqi@0: fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); aoqi@0: Iterable files = Arrays.asList(srcFile); aoqi@0: DiagnosticCollector dc = new DiagnosticCollector(); aoqi@0: DocumentationTask t = tool.getTask(null, fm, dc, null, null, files); aoqi@0: if (t.call()) { aoqi@0: throw new Exception("task succeeded unexpectedly"); aoqi@0: } else { aoqi@0: List diagCodes = new ArrayList(); aoqi@0: for (Diagnostic d: dc.getDiagnostics()) { aoqi@0: System.err.println(d); aoqi@0: diagCodes.add(d.getCode()); aoqi@0: } aoqi@0: List expect = Arrays.asList( aoqi@0: "javadoc.note.msg", // Loading source file aoqi@0: "compiler.err.expected3", // class, interface, or enum expected aoqi@0: "javadoc.note.msg"); // 1 error aoqi@0: if (!diagCodes.equals(expect)) aoqi@0: throw new Exception("unexpected diagnostics occurred"); aoqi@0: System.err.println("diagnostics received as expected"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: