Thu, 15 Dec 2011 15:47:47 -0800
Added tag jdk8-b16 for changeset ec2c0973cc31
1 /*
2 * Copyright (c) 2002, 2010, 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 import java.text.SimpleDateFormat;
25 import java.util.Date;
27 import com.sun.tools.doclets.formats.html.ConfigurationImpl;
28 import com.sun.tools.doclets.internal.toolkit.Configuration;
30 /*
31 * @test
32 * @bug 4034096 4764726 6235799
33 * @summary Add support for HTML keywords via META tag for
34 * class and member names to improve API search
35 * @author dkramer
36 * @library ../lib/
37 * @build JavadocTester
38 * @build MetaTag
39 * @run main MetaTag
40 */
42 public class MetaTag extends JavadocTester {
44 //Test information.
45 private static final String BUG_ID = "4034096-4764726-6235799";
46 private static final String OUTPUT_DIR = "docs-" + BUG_ID;
47 private static final SimpleDateFormat m_dateFormat = new SimpleDateFormat("yyyy-MM-dd");
49 //Javadoc arguments.
50 private static final String[] ARGS = new String[] {
51 "-d", OUTPUT_DIR,
52 "-sourcepath", SRC_DIR,
53 "-keywords",
54 "-doctitle", "Sample Packages",
55 "p1", "p2"
56 };
58 private static final String[] ARGS_NO_TIMESTAMP_NO_KEYWORDS = new String[] {
59 "-d", OUTPUT_DIR + "-2",
60 "-sourcepath", SRC_DIR,
61 "-notimestamp",
62 "-doctitle", "Sample Packages",
63 "p1", "p2"
64 };
66 //Input for string search tests.
67 private static final String[][] TEST = {
69 { OUTPUT_DIR + FS + "p1" + FS + "C1.html",
70 "<meta name=\"keywords\" content=\"p1.C1 class\">" },
72 { OUTPUT_DIR + FS + "p1" + FS + "C1.html",
73 "<meta name=\"keywords\" content=\"field1\">" },
75 { OUTPUT_DIR + FS + "p1" + FS + "C1.html",
76 "<meta name=\"keywords\" content=\"field2\">" },
78 { OUTPUT_DIR + FS + "p1" + FS + "C1.html",
79 "<meta name=\"keywords\" content=\"method1()\">" },
81 { OUTPUT_DIR + FS + "p1" + FS + "C1.html",
82 "<meta name=\"keywords\" content=\"method2()\">" },
84 { OUTPUT_DIR + FS + "p1" + FS + "package-summary.html",
85 "<meta name=\"keywords\" content=\"p1 package\">" },
87 { OUTPUT_DIR + FS + "overview-summary.html",
88 "<meta name=\"keywords\" content=\"Overview, Sample Packages\">" },
90 //NOTE: Hopefully, this regression test is not run at midnight. If the output
91 //was generated yesterday and this test is run today, the test will fail.
92 {OUTPUT_DIR + FS + "overview-summary.html",
93 "<meta name=\"date\" "
94 + "content=\"" + m_dateFormat.format(new Date()) + "\">"},
95 };
97 private static final String[][] NEGATED_TEST = NO_TEST;
99 private static final String[][] TEST2 = NO_TEST;
100 private static final String[][] NEGATED_TEST2 = {
101 //No keywords when -keywords is not used.
102 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "C1.html",
103 "<META NAME=\"keywords\" CONTENT=\"p1.C1 class\">" },
105 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "C1.html",
106 "<META NAME=\"keywords\" CONTENT=\"field1\">" },
108 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "C1.html",
109 "<META NAME=\"keywords\" CONTENT=\"field2\">" },
111 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "C1.html",
112 "<META NAME=\"keywords\" CONTENT=\"method1()\">" },
114 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "C1.html",
115 "<META NAME=\"keywords\" CONTENT=\"method2()\">" },
117 { OUTPUT_DIR + "-2" + FS + "p1" + FS + "package-summary.html",
118 "<META NAME=\"keywords\" CONTENT=\"p1 package\">" },
120 { OUTPUT_DIR + "-2" + FS + "overview-summary.html",
121 "<META NAME=\"keywords\" CONTENT=\"Overview Summary, Sample Packages\">" },
123 //The date metatag should not show up when -notimestamp is used.
125 //NOTE: Hopefully, this regression test is not run at midnight. If the output
126 //was generated yesterday and this test is run today, the test will fail.
127 {OUTPUT_DIR + "-2" + FS + "overview-summary.html",
128 "<META NAME=\"date\" "
129 + "CONTENT=\"" + m_dateFormat.format(new Date()) + "\">"},
130 };
132 /**
133 * The entry point of the test.
134 * @param args the array of command line arguments.
135 */
136 public static void main(String[] args) {
137 MetaTag tester = new MetaTag();
138 Configuration config = ConfigurationImpl.getInstance();
139 boolean defaultKeywordsSetting = config.keywords;
140 boolean defaultTimestampSetting = config.notimestamp;
141 run(tester, ARGS, TEST, NEGATED_TEST);
142 //Variable needs to be reset because Configuration is a singleton.
143 config.keywords = defaultKeywordsSetting;
144 config.notimestamp = defaultTimestampSetting;
145 run(tester, ARGS_NO_TIMESTAMP_NO_KEYWORDS, TEST2, NEGATED_TEST2);
146 tester.printSummary();
147 }
149 /**
150 * {@inheritDoc}
151 */
152 public String getBugId() {
153 return BUG_ID;
154 }
156 /**
157 * {@inheritDoc}
158 */
159 public String getBugName() {
160 return getClass().getName();
161 }
162 }