langtools/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java
author psandoz
Mon, 25 Nov 2013 09:55:34 +0100
changeset 21846 c10feb34bc0b
parent 14545 2e7bab0639b8
child 27319 030080f03e4f
permissions -rw-r--r--
8028516: Java doc error in Int/Long/Double/Stream.peek Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14545
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     1
/*
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     4
 *
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     8
 *
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    13
 * accompanied this code).
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    14
 *
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    18
 *
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    21
 * questions.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    22
 */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    23
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    24
/*
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    25
 * @test
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    26
 * @bug 6493690
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    27
 * @summary javadoc should have a javax.tools.Tool service provider
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    28
 * @build APITest
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    29
 * @run main GetTask_FileObjectsTest
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    30
 */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    31
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    32
import java.io.File;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    33
import java.util.Arrays;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    34
import javax.tools.DocumentationTool;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    35
import javax.tools.DocumentationTool.DocumentationTask;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    36
import javax.tools.JavaFileObject;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    37
import javax.tools.StandardJavaFileManager;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    38
import javax.tools.ToolProvider;
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    39
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    40
/**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    41
 * Tests for DocumentationTool.getTask  fileObjects  parameter.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    42
 */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    43
public class GetTask_FileObjectsTest extends APITest {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    44
    public static void main(String... args) throws Exception {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    45
        new GetTask_FileObjectsTest().run();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    46
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    47
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    48
    /**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    49
     * Verify that expected output files are written via the file manager,
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    50
     * for a source file read from the file system with StandardJavaFileManager.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    51
     */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    52
    @Test
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    53
    public void testStandardFileObject() throws Exception {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    54
        File testSrc = new File(System.getProperty("test.src"));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    55
        File srcFile = new File(testSrc, "pkg/C.java");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    56
        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    57
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    58
        File outDir = getOutDir();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    59
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    60
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    61
        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    62
        if (t.call()) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    63
            System.err.println("task succeeded");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    64
            checkFiles(outDir, standardExpectFiles);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    65
        } else {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    66
            throw new Exception("task failed");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    67
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    68
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    69
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    70
    /**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    71
     * Verify that expected output files are written via the file manager,
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    72
     * for an in-memory file object.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    73
     */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    74
    @Test
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    75
    public void testMemoryFileObject() throws Exception {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    76
        JavaFileObject srcFile = createSimpleJavaFileObject();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    77
        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    78
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    79
        File outDir = getOutDir();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    80
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    81
        Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    82
        DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    83
        if (t.call()) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    84
            System.err.println("task succeeded");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    85
            checkFiles(outDir, standardExpectFiles);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    86
        } else {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    87
            throw new Exception("task failed");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    88
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    89
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    90
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    91
    /**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    92
     * Verify bad file object is handled correctly.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    93
     */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    94
    @Test
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    95
    public void testBadFileObject() throws Exception {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    96
        File testSrc = new File(System.getProperty("test.src"));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    97
        File srcFile = new File(testSrc, "pkg/C.class");  // unacceptable file kind
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    98
        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
    99
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   100
        File outDir = getOutDir();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   101
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   102
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   103
        try {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   104
            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   105
            error("getTask succeeded, no exception thrown");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   106
        } catch (IllegalArgumentException e) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   107
            System.err.println("exception caught as expected: " + e);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   108
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   109
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   110
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   111
    /**
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   112
     * Verify null is handled correctly.
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   113
     */
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   114
    @Test
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   115
    public void testNull() throws Exception {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   116
        DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   117
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   118
        File outDir = getOutDir();
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   119
        fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   120
        Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   121
        try {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   122
            DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   123
            error("getTask succeeded, no exception thrown");
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   124
        } catch (NullPointerException e) {
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   125
            System.err.println("exception caught as expected: " + e);
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   126
        }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   127
    }
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   128
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   129
}
2e7bab0639b8 6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff changeset
   130