jjg@1413: /* jjg@2010: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. jjg@1413: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1413: * jjg@1413: * This code is free software; you can redistribute it and/or modify it jjg@1413: * under the terms of the GNU General Public License version 2 only, as jjg@1413: * published by the Free Software Foundation. jjg@1413: * jjg@1413: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1413: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1413: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1413: * version 2 for more details (a copy is included in the LICENSE file that jjg@1413: * accompanied this code). jjg@1413: * jjg@1413: * You should have received a copy of the GNU General Public License version jjg@1413: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1413: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1413: * jjg@1413: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1413: * or visit www.oracle.com if you need additional information or have any jjg@1413: * questions. jjg@1413: */ jjg@1413: jjg@1413: /* jjg@1413: * @test jjg@2010: * @bug 6493690 8024434 jjg@1413: * @summary javadoc should have a javax.tools.Tool service provider jjg@1413: * @build APITest jjg@1413: * @run main GetTask_FileManagerTest jjg@1413: */ jjg@1413: jjg@1413: import java.io.IOException; jjg@1413: import java.nio.file.Path; jjg@1413: import java.util.Arrays; jjg@1413: import java.util.Set; jjg@1413: jjg@1413: import javax.tools.DocumentationTool; jjg@1413: import javax.tools.DocumentationTool.DocumentationTask; jjg@1413: import javax.tools.JavaFileObject; jjg@1413: import javax.tools.JavaFileObject.Kind; jjg@1413: import javax.tools.ToolProvider; jjg@1413: jjg@1413: import com.sun.tools.javac.nio.JavacPathFileManager; jjg@1413: import com.sun.tools.javac.nio.PathFileManager; jjg@1413: import com.sun.tools.javac.util.Context; jjg@1413: jjg@1413: /** jjg@1413: * Tests for DocumentationTool.getTask fileManager parameter. jjg@1413: */ jjg@1413: public class GetTask_FileManagerTest extends APITest { jjg@1413: public static void main(String... args) throws Exception { jjg@1413: new GetTask_FileManagerTest().run(); jjg@1413: } jjg@1413: jjg@1413: /** jjg@1413: * Verify that an alternate file manager can be specified: jjg@1413: * in this case, a PathFileManager. jjg@1413: */ jjg@1413: @Test jjg@1413: public void testFileManager() throws Exception { jjg@1413: JavaFileObject srcFile = createSimpleJavaFileObject(); jjg@1413: DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); jjg@1413: PathFileManager fm = new JavacPathFileManager(new Context(), false, null); jjg@1413: Path outDir = getOutDir().toPath(); jjg@1413: fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); jjg@1413: Iterable files = Arrays.asList(srcFile); jjg@1413: DocumentationTask t = tool.getTask(null, fm, null, null, null, files); jjg@1413: if (t.call()) { jjg@1413: System.err.println("task succeeded"); jjg@1413: checkFiles(outDir, standardExpectFiles); jjg@1413: } else { jjg@1413: throw new Exception("task failed"); jjg@1413: } jjg@1413: } jjg@1413: jjg@1413: /** jjg@1413: * Verify that exceptions from a bad file manager are thrown as expected. jjg@1413: */ jjg@1413: @Test jjg@1413: public void testBadFileManager() throws Exception { jjg@1413: JavaFileObject srcFile = createSimpleJavaFileObject(); jjg@1413: DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); jjg@1413: PathFileManager fm = new JavacPathFileManager(new Context(), false, null) { jjg@1413: @Override jjg@1413: public Iterable list(Location location, jjg@1413: String packageName, jjg@1413: Set kinds, jjg@1413: boolean recurse) jjg@1413: throws IOException { jjg@1413: throw new UnexpectedError(); jjg@1413: } jjg@1413: }; jjg@1413: Path outDir = getOutDir().toPath(); jjg@1413: fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); jjg@1413: Iterable files = Arrays.asList(srcFile); jjg@1413: DocumentationTask t = tool.getTask(null, fm, null, null, null, files); jjg@1413: try { jjg@1413: t.call(); jjg@1413: error("call completed without exception"); jjg@1413: } catch (RuntimeException e) { jjg@1413: Throwable c = e.getCause(); jjg@1413: if (c.getClass() == UnexpectedError.class) jjg@1413: System.err.println("exception caught as expected: " + c); jjg@1413: else jjg@1413: throw e; jjg@1413: } jjg@1413: } jjg@1413: jjg@1413: public static class UnexpectedError extends Error { } jjg@1413: jjg@1413: }