JavadocTaskImplTest.java revision 3233:b5d08bc0d224
1109998Smarkm/* 2280304Sjkim * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3280304Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4280304Sjkim * 5109998Smarkm * This code is free software; you can redistribute it and/or modify it 6109998Smarkm * under the terms of the GNU General Public License version 2 only, as 7160814Ssimon * published by the Free Software Foundation. 8109998Smarkm * 9109998Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT 10109998Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11109998Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12109998Smarkm * version 2 for more details (a copy is included in the LICENSE file that 13109998Smarkm * accompanied this code). 14280304Sjkim * 15109998Smarkm * You should have received a copy of the GNU General Public License version 16109998Smarkm * 2 along with this work; if not, write to the Free Software Foundation, 17109998Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18109998Smarkm * 19109998Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20109998Smarkm * or visit www.oracle.com if you need additional information or have any 21109998Smarkm * questions. 22109998Smarkm */ 23109998Smarkm 24109998Smarkm/* 25109998Smarkm * @test 26109998Smarkm * @bug 6493690 27109998Smarkm * @summary javadoc should have a javax.tools.Tool service provider 28109998Smarkm * @modules jdk.compiler/com.sun.tools.javac.file 29109998Smarkm * jdk.compiler/com.sun.tools.javac.util 30109998Smarkm * jdk.javadoc/com.sun.tools.javadoc.api 31109998Smarkm * @build APITest 32109998Smarkm * @run main JavadocTaskImplTest 33109998Smarkm */ 34109998Smarkm 35109998Smarkmimport java.io.File; 36109998Smarkmimport java.util.Arrays; 37109998Smarkmimport java.util.concurrent.Callable; 38109998Smarkm 39109998Smarkmimport javax.tools.DocumentationTool; 40109998Smarkmimport javax.tools.DocumentationTool.DocumentationTask; 41109998Smarkmimport javax.tools.JavaFileObject; 42109998Smarkmimport javax.tools.StandardJavaFileManager; 43109998Smarkmimport javax.tools.ToolProvider; 44109998Smarkm 45109998Smarkmimport com.sun.tools.javac.file.JavacFileManager; 46109998Smarkmimport com.sun.tools.javac.util.Context; 47109998Smarkmimport jdk.javadoc.internal.api.JavadocTaskImpl; 48109998Smarkmimport jdk.javadoc.internal.tool.Messager; 49109998Smarkm 50109998Smarkm/** 51109998Smarkm * Misc tests for JavacTaskImpl. 52109998Smarkm */ 53109998Smarkmpublic class JavadocTaskImplTest extends APITest { 54109998Smarkm public static void main(String... args) throws Exception { 55109998Smarkm new JavadocTaskImplTest().run(); 56109998Smarkm } 57109998Smarkm 58109998Smarkm @Test 59109998Smarkm public void testRawCall() throws Exception { 60109998Smarkm JavaFileObject srcFile = createSimpleJavaFileObject(); 61109998Smarkm DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); 62109998Smarkm try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { 63109998Smarkm File outDir = getOutDir(); 64109998Smarkm fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); 65109998Smarkm Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); 66109998Smarkm 67160814Ssimon @SuppressWarnings("rawtypes") 68280304Sjkim Callable t = tool.getTask(null, fm, null, null, null, files); 69109998Smarkm 70109998Smarkm if (t.call() == Boolean.TRUE) { 71238405Sjkim System.err.println("task succeeded"); 72109998Smarkm } else { 73109998Smarkm throw new Exception("task failed"); 74280304Sjkim } 75280304Sjkim } 76280304Sjkim } 77280304Sjkim 78280304Sjkim @Test 79280304Sjkim public void testDirectAccess1() throws Exception { 80109998Smarkm JavaFileObject srcFile = createSimpleJavaFileObject(); 81109998Smarkm Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); 82109998Smarkm Context c = new Context(); 83109998Smarkm Messager.preRegister(c, "javadoc"); 84280304Sjkim try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) { 85280304Sjkim File outDir = getOutDir(); 86280304Sjkim fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); 87109998Smarkm DocumentationTask t = new JavadocTaskImpl(c, null, null, files); 88160814Ssimon if (t.call()) { 89280304Sjkim System.err.println("task succeeded"); 90280304Sjkim } else { 91280304Sjkim throw new Exception("task failed"); 92280304Sjkim } 93280304Sjkim } 94280304Sjkim } 95280304Sjkim 96280304Sjkim @Test 97280304Sjkim public void testDirectAccess2() throws Exception { 98280304Sjkim JavaFileObject srcFile = null; // error, provokes NPE 99280304Sjkim Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile); 100280304Sjkim Context c = new Context(); 101280304Sjkim Messager.preRegister(c, "javadoc"); 102109998Smarkm try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) { 103109998Smarkm File outDir = getOutDir(); 104280304Sjkim fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); 105280304Sjkim try { 106109998Smarkm DocumentationTask t = new JavadocTaskImpl(c, null, null, files);; 107109998Smarkm error("getTask succeeded, no exception thrown"); 108280304Sjkim } catch (NullPointerException e) { 109109998Smarkm System.err.println("exception caught as expected: " + e); 110280304Sjkim } 111280304Sjkim } 112280304Sjkim } 113280304Sjkim} 114280304Sjkim 115280304Sjkim