GetTask_WriterTest.java revision 3233:b5d08bc0d224
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
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_WriterTest
32 */
33
34import java.io.File;
35import java.io.PrintWriter;
36import java.io.StringWriter;
37import java.util.Arrays;
38import javax.tools.DocumentationTool;
39import javax.tools.DocumentationTool.DocumentationTask;
40import javax.tools.JavaFileObject;
41import javax.tools.StandardJavaFileManager;
42import javax.tools.ToolProvider;
43
44/**
45 * Tests for DocumentationTool.getTask  writer  parameter.
46 */
47public class GetTask_WriterTest extends APITest {
48    public static void main(String... args) throws Exception {
49        new GetTask_WriterTest().run();
50    }
51
52    /**
53     * Verify that a writer can be provided.
54     */
55    @Test
56    public void testWriter() 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            StringWriter sw = new StringWriter();
64            PrintWriter pw = new PrintWriter(sw);
65            DocumentationTask t = tool.getTask(pw, fm, null, null, null, files);
66            if (t.call()) {
67                System.err.println("task succeeded");
68                checkFiles(outDir, standardExpectFiles);
69                String out = sw.toString();
70                System.err.println(">>" + out + "<<");
71                for (String f: standardExpectFiles) {
72                    String f1 = f.replace('/', File.separatorChar);
73                    if (f1.endsWith(".html") && !out.contains(f1))
74                        throw new Exception("expected string not found: " + f1);
75                }
76            } else {
77                throw new Exception("task failed");
78            }
79        }
80    }
81}
82
83