test/langtools/tools/javadoc/api/basic/GetTask_FileObjectsTest.java
branchniosocketimpl-branch
changeset 57208 7a45c67e73d0
parent 57207 30695f27d7ea
parent 53902 7a6fd71449e7
child 57210 a67ea4f53e56
equal deleted inserted replaced
57207:30695f27d7ea 57208:7a45c67e73d0
     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_FileObjectsTest
       
    32  */
       
    33 
       
    34 import java.io.File;
       
    35 import java.util.Arrays;
       
    36 import javax.tools.DocumentationTool;
       
    37 import javax.tools.DocumentationTool.DocumentationTask;
       
    38 import javax.tools.JavaFileObject;
       
    39 import javax.tools.StandardJavaFileManager;
       
    40 import javax.tools.ToolProvider;
       
    41 
       
    42 /**
       
    43  * Tests for DocumentationTool.getTask  fileObjects  parameter.
       
    44  */
       
    45 public class GetTask_FileObjectsTest extends APITest {
       
    46     public static void main(String... args) throws Exception {
       
    47         new GetTask_FileObjectsTest().run();
       
    48     }
       
    49 
       
    50     /**
       
    51      * Verify that expected output files are written via the file manager,
       
    52      * for a source file read from the file system with StandardJavaFileManager.
       
    53      */
       
    54     @Test
       
    55     public void testStandardFileObject() throws Exception {
       
    56         File testSrc = new File(System.getProperty("test.src"));
       
    57         File srcFile = new File(testSrc, "pkg/C.java");
       
    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 = fm.getJavaFileObjects(srcFile);
       
    63             DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
       
    64             if (t.call()) {
       
    65                 System.err.println("task succeeded");
       
    66                 checkFiles(outDir, standardExpectFiles);
       
    67             } else {
       
    68                 throw new Exception("task failed");
       
    69             }
       
    70         }
       
    71     }
       
    72 
       
    73     /**
       
    74      * Verify that expected output files are written via the file manager,
       
    75      * for an in-memory file object.
       
    76      */
       
    77     @Test
       
    78     public void testMemoryFileObject() throws Exception {
       
    79         JavaFileObject srcFile = createSimpleJavaFileObject();
       
    80         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
       
    81         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
       
    82             File outDir = getOutDir();
       
    83             fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
       
    84             Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
       
    85             DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
       
    86             if (t.call()) {
       
    87                 System.err.println("task succeeded");
       
    88                 checkFiles(outDir, standardExpectFiles);
       
    89             } else {
       
    90                 throw new Exception("task failed");
       
    91             }
       
    92         }
       
    93     }
       
    94 
       
    95     /**
       
    96      * Verify bad file object is handled correctly.
       
    97      */
       
    98     @Test
       
    99     public void testBadFileObject() throws Exception {
       
   100         File testSrc = new File(System.getProperty("test.src"));
       
   101         File srcFile = new File(testSrc, "pkg/C.class");  // unacceptable file kind
       
   102         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
       
   103         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
       
   104             File outDir = getOutDir();
       
   105             fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
       
   106             Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
       
   107             try {
       
   108                 DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
       
   109                 error("getTask succeeded, no exception thrown");
       
   110             } catch (IllegalArgumentException e) {
       
   111                 System.err.println("exception caught as expected: " + e);
       
   112             }
       
   113         }
       
   114     }
       
   115 
       
   116     /**
       
   117      * Verify null is handled correctly.
       
   118      */
       
   119     @Test
       
   120     public void testNull() throws Exception {
       
   121         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
       
   122         try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
       
   123             File outDir = getOutDir();
       
   124             fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
       
   125             Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
       
   126             try {
       
   127                 DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
       
   128                 error("getTask succeeded, no exception thrown");
       
   129             } catch (NullPointerException e) {
       
   130                 System.err.println("exception caught as expected: " + e);
       
   131             }
       
   132         }
       
   133     }
       
   134 
       
   135 }
       
   136