1/* 2 * Copyright (c) 2002, 2015, 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 */ 23 24/* 25 * @test 26 * @bug 4034096 4764726 6235799 27 * @summary Add support for HTML keywords via META tag for 28 * class and member names to improve API search 29 * @author dkramer 30 * @library ../lib 31 * @modules jdk.javadoc 32 * @build JavadocTester 33 * @run main MetaTag 34 */ 35 36import java.text.SimpleDateFormat; 37import java.util.Date; 38 39public class MetaTag extends JavadocTester { 40 41 /** 42 * The entry point of the test. 43 * @param args the array of command line arguments 44 * @throws Exception if the test fails 45 */ 46 public static void main(String... args) throws Exception { 47 MetaTag tester = new MetaTag(); 48 tester.runTests(); 49 } 50 51 @Test 52 void testStandard() { 53 javadoc("-d", "out-1", 54 "-sourcepath", testSrc, 55 "-keywords", 56 "-doctitle", "Sample Packages", 57 "p1", "p2"); 58 59 checkExit(Exit.OK); 60 61 checkOutput("p1/C1.html", true, 62 "<meta name=\"keywords\" content=\"p1.C1 class\">", 63 "<meta name=\"keywords\" content=\"field1\">", 64 "<meta name=\"keywords\" content=\"field2\">", 65 "<meta name=\"keywords\" content=\"method1()\">", 66 "<meta name=\"keywords\" content=\"method2()\">"); 67 68 checkOutput("p1/package-summary.html", true, 69 "<meta name=\"keywords\" content=\"p1 package\">"); 70 71 checkOutput("overview-summary.html", true, 72 "<meta name=\"keywords\" content=\"Overview, Sample Packages\">"); 73 74 // NOTE: Hopefully, this regression test is not run at midnight. If the output 75 // was generated yesterday and this test is run today, the test will fail. 76 checkOutput("overview-summary.html", true, 77 "<meta name=\"date\" content=\"" + date() + "\">"); 78 } 79 80 @Test 81 void testNoTimestamp() { 82 javadoc("-d", "out-2", 83 "-sourcepath", testSrc, 84 "-notimestamp", 85 "-doctitle", "Sample Packages", 86 "p1", "p2"); 87 checkExit(Exit.OK); 88 89 // No keywords when -keywords is not used. 90 checkOutput("p1/C1.html", false, 91 "<META NAME=\"keywords\" CONTENT=\"p1.C1 class\">", 92 "<META NAME=\"keywords\" CONTENT=\"field1\">", 93 "<META NAME=\"keywords\" CONTENT=\"field2\">", 94 "<META NAME=\"keywords\" CONTENT=\"method1()\">", 95 "<META NAME=\"keywords\" CONTENT=\"method2()\">"); 96 97 checkOutput("p1/package-summary.html", false, 98 "<META NAME=\"keywords\" CONTENT=\"p1 package\">"); 99 100 checkOutput("overview-summary.html", false, 101 "<META NAME=\"keywords\" CONTENT=\"Overview Summary, Sample Packages\">"); 102 103 // The date metatag should not show up when -notimestamp is used. 104 // NOTE: Hopefully, this regression test is not run at midnight. If the output 105 // was generated yesterday and this test is run today, the test will fail. 106 checkOutput("overview-summary.html", false, 107 "<META NAME=\"date\" CONTENT=\"" + date() + "\">"); 108 } 109 110 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 111 112 String date() { 113 return dateFormat.format(new Date()); 114 } 115} 116