Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/api/basic/GetTask_FileManagerTest.java
38828 views
/*1* Copyright (c) 2012, 2013, 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 6493690 802443426* @summary javadoc should have a javax.tools.Tool service provider27* @build APITest28* @run main GetTask_FileManagerTest29*/3031import java.io.IOException;32import java.nio.file.Path;33import java.util.Arrays;34import java.util.Set;3536import javax.tools.DocumentationTool;37import javax.tools.DocumentationTool.DocumentationTask;38import javax.tools.JavaFileObject;39import javax.tools.JavaFileObject.Kind;40import javax.tools.ToolProvider;4142import com.sun.tools.javac.nio.JavacPathFileManager;43import com.sun.tools.javac.nio.PathFileManager;44import com.sun.tools.javac.util.Context;4546/**47* Tests for DocumentationTool.getTask fileManager parameter.48*/49public class GetTask_FileManagerTest extends APITest {50public static void main(String... args) throws Exception {51new GetTask_FileManagerTest().run();52}5354/**55* Verify that an alternate file manager can be specified:56* in this case, a PathFileManager.57*/58@Test59public void testFileManager() throws Exception {60JavaFileObject srcFile = createSimpleJavaFileObject();61DocumentationTool tool = ToolProvider.getSystemDocumentationTool();62PathFileManager fm = new JavacPathFileManager(new Context(), false, null);63Path outDir = getOutDir().toPath();64fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));65Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);66DocumentationTask t = tool.getTask(null, fm, null, null, null, files);67if (t.call()) {68System.err.println("task succeeded");69checkFiles(outDir, standardExpectFiles);70} else {71throw new Exception("task failed");72}73}7475/**76* Verify that exceptions from a bad file manager are thrown as expected.77*/78@Test79public void testBadFileManager() throws Exception {80JavaFileObject srcFile = createSimpleJavaFileObject();81DocumentationTool tool = ToolProvider.getSystemDocumentationTool();82PathFileManager fm = new JavacPathFileManager(new Context(), false, null) {83@Override84public Iterable<JavaFileObject> list(Location location,85String packageName,86Set<Kind> kinds,87boolean recurse)88throws IOException {89throw new UnexpectedError();90}91};92Path outDir = getOutDir().toPath();93fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));94Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);95DocumentationTask t = tool.getTask(null, fm, null, null, null, files);96try {97t.call();98error("call completed without exception");99} catch (RuntimeException e) {100Throwable c = e.getCause();101if (c.getClass() == UnexpectedError.class)102System.err.println("exception caught as expected: " + c);103else104throw e;105}106}107108public static class UnexpectedError extends Error { }109110}111112113