Path: blob/master/test/langtools/jdk/javadoc/tool/api/basic/JavadocTaskImplTest.java
40983 views
/*1* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 649369026* @summary javadoc should have a javax.tools.Tool service provider27* @modules jdk.compiler/com.sun.tools.javac.file28* jdk.compiler/com.sun.tools.javac.util29* jdk.javadoc/jdk.javadoc.internal.api30* jdk.javadoc/jdk.javadoc.internal.tool31* @build APITest32* @run main JavadocTaskImplTest33*/3435import java.io.File;36import java.util.Arrays;37import java.util.concurrent.Callable;3839import javax.tools.DocumentationTool;40import javax.tools.DocumentationTool.DocumentationTask;41import javax.tools.JavaFileObject;42import javax.tools.StandardJavaFileManager;43import javax.tools.ToolProvider;4445import com.sun.tools.javac.file.JavacFileManager;46import com.sun.tools.javac.util.Context;47import jdk.javadoc.internal.api.JavadocTaskImpl;48import jdk.javadoc.internal.tool.Messager;4950/**51* Misc tests for JavacTaskImpl.52*/53public class JavadocTaskImplTest extends APITest {54public static void main(String... args) throws Exception {55new JavadocTaskImplTest().run();56}5758@Test59public void testRawCall() throws Exception {60JavaFileObject srcFile = createSimpleJavaFileObject();61DocumentationTool tool = ToolProvider.getSystemDocumentationTool();62try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {63File outDir = getOutDir();64fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));65Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);6667@SuppressWarnings("rawtypes")68Callable t = tool.getTask(null, fm, null, null, null, files);6970if (t.call() == Boolean.TRUE) {71System.err.println("task succeeded");72} else {73throw new Exception("task failed");74}75}76}7778@Test79public void testDirectAccess1() throws Exception {80JavaFileObject srcFile = createSimpleJavaFileObject();81Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);82Context c = new Context();83Messager.preRegister(c, "javadoc");84try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {85File outDir = getOutDir();86fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));87DocumentationTask t = new JavadocTaskImpl(c, null, null, files);88if (t.call()) {89System.err.println("task succeeded");90} else {91throw new Exception("task failed");92}93}94}9596@Test97public void testDirectAccess2() throws Exception {98JavaFileObject srcFile = null; // error, provokes NPE99Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);100Context c = new Context();101Messager.preRegister(c, "javadoc");102try (StandardJavaFileManager fm = new JavacFileManager(c, true, null)) {103File outDir = getOutDir();104fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));105try {106DocumentationTask t = new JavadocTaskImpl(c, null, null, files);;107error("getTask succeeded, no exception thrown");108} catch (NullPointerException e) {109System.err.println("exception caught as expected: " + e);110}111}112}113}114115116117