test/tools/javadoc/api/basic/TagletPathTest.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6493690
    27  * @summary javadoc should have a javax.tools.Tool service provider
    28  * @build APITest
    29  * @run main TagletPathTest
    30  */
    32 import java.io.File;
    33 import java.io.PrintWriter;
    34 import java.io.StringWriter;
    35 import java.nio.charset.Charset;
    36 import java.nio.file.Files;
    37 import java.util.Arrays;
    38 import java.util.List;
    39 import javax.tools.DocumentationTool;
    40 import javax.tools.DocumentationTool.DocumentationTask;
    41 import javax.tools.JavaCompiler;
    42 import javax.tools.JavaFileObject;
    43 import javax.tools.StandardJavaFileManager;
    44 import javax.tools.StandardLocation;
    45 import javax.tools.ToolProvider;
    47 /**
    48  * Tests for locating a doclet via the file manager's DOCLET_PATH.
    49  */
    50 public class TagletPathTest extends APITest {
    51     public static void main(String... args) throws Exception {
    52         new TagletPathTest().run();
    53     }
    55     /**
    56      * Verify that a taglet can be specified, and located via
    57      * the file manager's TAGLET_PATH.
    58      */
    59     @Test
    60     public void testTagletPath() throws Exception {
    61         File testSrc = new File(System.getProperty("test.src"));
    62         File tagletSrcFile = new File(testSrc, "taglets/UnderlineTaglet.java");
    63         File tagletDir = getOutDir("classes");
    64         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    65         StandardJavaFileManager cfm = compiler.getStandardFileManager(null, null, null);
    66         cfm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tagletDir));
    67         Iterable<? extends JavaFileObject> cfiles = cfm.getJavaFileObjects(tagletSrcFile);
    68         if (!compiler.getTask(null, cfm, null, null, null, cfiles).call())
    69             throw new Exception("cannot compile taglet");
    71         JavaFileObject srcFile = createSimpleJavaFileObject("pkg/C", testSrcText);
    72         DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    73         StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
    74         File outDir = getOutDir("api");
    75         fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
    76         fm.setLocation(DocumentationTool.Location.TAGLET_PATH, Arrays.asList(tagletDir));
    77         Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    78         Iterable<String> options = Arrays.asList("-taglet", "UnderlineTaglet");
    79         StringWriter sw = new StringWriter();
    80         PrintWriter pw = new PrintWriter(sw);
    81         DocumentationTask t = tool.getTask(pw, fm, null, null, options, files);
    82         boolean ok = t.call();
    83         String out = sw.toString();
    84         System.err.println(">>" + out + "<<");
    85         if (ok) {
    86             File f = new File(outDir, "pkg/C.html");
    87             List<String> doc = Files.readAllLines(f.toPath(), Charset.defaultCharset());
    88             for (String line: doc) {
    89                 if (line.contains("<u>" + TEST_STRING + "</u>")) {
    90                     System.err.println("taglet executed as expected");
    91                     return;
    92                 }
    93             }
    94             error("expected text not found in output " + f);
    95         } else {
    96             error("task failed");
    97         }
    98     }
   100     static final String TEST_STRING = "xyzzy";
   101     static final String testSrcText =
   102             "package pkg;\n" +
   103             "/** {@underline " + TEST_STRING + "} */\n" +
   104             "public class C { }";
   105 }

mercurial