Mon, 19 Sep 2016 09:50:03 -0700
Merge
jjg@1413 | 1 | /* |
jjg@2010 | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
jjg@1413 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1413 | 4 | * |
jjg@1413 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1413 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1413 | 7 | * published by the Free Software Foundation. |
jjg@1413 | 8 | * |
jjg@1413 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1413 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1413 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1413 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1413 | 13 | * accompanied this code). |
jjg@1413 | 14 | * |
jjg@1413 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@1413 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1413 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1413 | 18 | * |
jjg@1413 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1413 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@1413 | 21 | * questions. |
jjg@1413 | 22 | */ |
jjg@1413 | 23 | |
jjg@1413 | 24 | /* |
jjg@1413 | 25 | * @test |
jjg@2010 | 26 | * @bug 6493690 8024434 |
jjg@1413 | 27 | * @summary javadoc should have a javax.tools.Tool service provider |
jjg@1413 | 28 | * @build APITest |
jjg@1413 | 29 | * @run main GetTask_FileManagerTest |
jjg@1413 | 30 | */ |
jjg@1413 | 31 | |
jjg@1413 | 32 | import java.io.IOException; |
jjg@1413 | 33 | import java.nio.file.Path; |
jjg@1413 | 34 | import java.util.Arrays; |
jjg@1413 | 35 | import java.util.Set; |
jjg@1413 | 36 | |
jjg@1413 | 37 | import javax.tools.DocumentationTool; |
jjg@1413 | 38 | import javax.tools.DocumentationTool.DocumentationTask; |
jjg@1413 | 39 | import javax.tools.JavaFileObject; |
jjg@1413 | 40 | import javax.tools.JavaFileObject.Kind; |
jjg@1413 | 41 | import javax.tools.ToolProvider; |
jjg@1413 | 42 | |
jjg@1413 | 43 | import com.sun.tools.javac.nio.JavacPathFileManager; |
jjg@1413 | 44 | import com.sun.tools.javac.nio.PathFileManager; |
jjg@1413 | 45 | import com.sun.tools.javac.util.Context; |
jjg@1413 | 46 | |
jjg@1413 | 47 | /** |
jjg@1413 | 48 | * Tests for DocumentationTool.getTask fileManager parameter. |
jjg@1413 | 49 | */ |
jjg@1413 | 50 | public class GetTask_FileManagerTest extends APITest { |
jjg@1413 | 51 | public static void main(String... args) throws Exception { |
jjg@1413 | 52 | new GetTask_FileManagerTest().run(); |
jjg@1413 | 53 | } |
jjg@1413 | 54 | |
jjg@1413 | 55 | /** |
jjg@1413 | 56 | * Verify that an alternate file manager can be specified: |
jjg@1413 | 57 | * in this case, a PathFileManager. |
jjg@1413 | 58 | */ |
jjg@1413 | 59 | @Test |
jjg@1413 | 60 | public void testFileManager() throws Exception { |
jjg@1413 | 61 | JavaFileObject srcFile = createSimpleJavaFileObject(); |
jjg@1413 | 62 | DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
jjg@1413 | 63 | PathFileManager fm = new JavacPathFileManager(new Context(), false, null); |
jjg@1413 | 64 | Path outDir = getOutDir().toPath(); |
jjg@1413 | 65 | fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
jjg@1413 | 66 | Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
jjg@1413 | 67 | DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
jjg@1413 | 68 | if (t.call()) { |
jjg@1413 | 69 | System.err.println("task succeeded"); |
jjg@1413 | 70 | checkFiles(outDir, standardExpectFiles); |
jjg@1413 | 71 | } else { |
jjg@1413 | 72 | throw new Exception("task failed"); |
jjg@1413 | 73 | } |
jjg@1413 | 74 | } |
jjg@1413 | 75 | |
jjg@1413 | 76 | /** |
jjg@1413 | 77 | * Verify that exceptions from a bad file manager are thrown as expected. |
jjg@1413 | 78 | */ |
jjg@1413 | 79 | @Test |
jjg@1413 | 80 | public void testBadFileManager() throws Exception { |
jjg@1413 | 81 | JavaFileObject srcFile = createSimpleJavaFileObject(); |
jjg@1413 | 82 | DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
jjg@1413 | 83 | PathFileManager fm = new JavacPathFileManager(new Context(), false, null) { |
jjg@1413 | 84 | @Override |
jjg@1413 | 85 | public Iterable<JavaFileObject> list(Location location, |
jjg@1413 | 86 | String packageName, |
jjg@1413 | 87 | Set<Kind> kinds, |
jjg@1413 | 88 | boolean recurse) |
jjg@1413 | 89 | throws IOException { |
jjg@1413 | 90 | throw new UnexpectedError(); |
jjg@1413 | 91 | } |
jjg@1413 | 92 | }; |
jjg@1413 | 93 | Path outDir = getOutDir().toPath(); |
jjg@1413 | 94 | fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); |
jjg@1413 | 95 | Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); |
jjg@1413 | 96 | DocumentationTask t = tool.getTask(null, fm, null, null, null, files); |
jjg@1413 | 97 | try { |
jjg@1413 | 98 | t.call(); |
jjg@1413 | 99 | error("call completed without exception"); |
jjg@1413 | 100 | } catch (RuntimeException e) { |
jjg@1413 | 101 | Throwable c = e.getCause(); |
jjg@1413 | 102 | if (c.getClass() == UnexpectedError.class) |
jjg@1413 | 103 | System.err.println("exception caught as expected: " + c); |
jjg@1413 | 104 | else |
jjg@1413 | 105 | throw e; |
jjg@1413 | 106 | } |
jjg@1413 | 107 | } |
jjg@1413 | 108 | |
jjg@1413 | 109 | public static class UnexpectedError extends Error { } |
jjg@1413 | 110 | |
jjg@1413 | 111 | } |