aoqi@0: /* aoqi@0: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 6493690 aoqi@0: * @summary javadoc should have a javax.tools.Tool service provider aoqi@0: * @build APITest aoqi@0: * @run main TagletPathTest aoqi@0: */ aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.io.PrintWriter; aoqi@0: import java.io.StringWriter; aoqi@0: import java.nio.charset.Charset; aoqi@0: import java.nio.file.Files; aoqi@0: import java.util.Arrays; aoqi@0: import java.util.List; aoqi@0: import javax.tools.DocumentationTool; aoqi@0: import javax.tools.DocumentationTool.DocumentationTask; aoqi@0: import javax.tools.JavaCompiler; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: import javax.tools.StandardJavaFileManager; aoqi@0: import javax.tools.StandardLocation; aoqi@0: import javax.tools.ToolProvider; aoqi@0: aoqi@0: /** aoqi@0: * Tests for locating a doclet via the file manager's DOCLET_PATH. aoqi@0: */ aoqi@0: public class TagletPathTest extends APITest { aoqi@0: public static void main(String... args) throws Exception { aoqi@0: new TagletPathTest().run(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Verify that a taglet can be specified, and located via aoqi@0: * the file manager's TAGLET_PATH. aoqi@0: */ aoqi@0: @Test aoqi@0: public void testTagletPath() throws Exception { aoqi@0: File testSrc = new File(System.getProperty("test.src")); aoqi@0: File tagletSrcFile = new File(testSrc, "taglets/UnderlineTaglet.java"); aoqi@0: File tagletDir = getOutDir("classes"); aoqi@0: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); aoqi@0: StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null); aoqi@0: cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir)); aoqi@0: Iterable cfiles = cfm.getJavaFileObjects(tagletSrcFile); aoqi@0: if (!compiler.getTask(null, cfm, null, null, null, cfiles).call()) aoqi@0: throw new Exception("cannot compile taglet"); aoqi@0: aoqi@0: JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", testSrcText); aoqi@0: DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); aoqi@0: StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); aoqi@0: File outDir = getOutDir("api"); aoqi@0: fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir)); aoqi@0: fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir)); aoqi@0: Iterable files = Arrays.asList(srcFile); aoqi@0: Iterable options = Arrays.asList("-taglet", "UnderlineTaglet"); aoqi@0: StringWriter sw = new StringWriter(); aoqi@0: PrintWriter pw = new PrintWriter(sw); aoqi@0: DocumentationTask t = tool.getTask(pw, fm, null, null, options, files); aoqi@0: boolean ok = t.call(); aoqi@0: String out = sw.toString(); aoqi@0: System.err.println(">>" + out + "<<"); aoqi@0: if (ok) { aoqi@0: File f = new File(outDir, "pkg/C.html"); aoqi@0: List doc = Files.readAllLines(f.toPath(), Charset.defaultCharset()); aoqi@0: for (String line: doc) { aoqi@0: if (line.contains("" + TEST_STRING + "")) { aoqi@0: System.err.println("taglet executed as expected"); aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: error("expected text not found in output " + f); aoqi@0: } else { aoqi@0: error("task failed"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static final String TEST_STRING = "xyzzy"; aoqi@0: static final String testSrcText = aoqi@0: "package pkg;\n" + aoqi@0: "/** {@underline " + TEST_STRING + "} */\n" + aoqi@0: "public class C { }"; aoqi@0: } aoqi@0: