changeset 2163:3114d240cf64

8000418: javadoc should used a standard "generated by javadoc" string Reviewed-by: bpatel
author jjg
date Wed, 10 Oct 2012 18:34:46 -0700
parents 5d0d1fbcec86
children ef4ac41874cf
files src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java test/com/sun/javadoc/VersionNumber/VersionNumber.java test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java test/com/sun/javadoc/testGeneratedBy/pkg/MyClass.java
diffstat 6 files changed, 149 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Sep 27 21:20:01 2013 +0400
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Oct 10 18:34:46 2012 -0700
@@ -346,66 +346,6 @@
     }
 
     /**
-     * Print the html file header. Also print Html page title and stylesheet
-     * default properties.
-     *
-     * @param title         String window title to go in the <TITLE> tag
-     * @param metakeywords  Array of String keywords for META tag.  Each element
-     *                      of the array is assigned to a separate META tag.
-     *                      Pass in null for no array.
-     * @param includeScript boolean true if printing windowtitle script.
-     *             False for files that appear in the left-hand frames.
-     */
-    public void printHtmlHeader(String title, String[] metakeywords,
-            boolean includeScript) {
-        println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " +
-                    "Transitional//EN\" " +
-                    "\"http://www.w3.org/TR/html4/loose.dtd\">");
-        println("<!--NewPage-->");
-        html();
-        head();
-        if (! configuration.notimestamp) {
-            print("<!-- Generated by javadoc (build " + ConfigurationImpl.BUILD_DATE + ") on ");
-            print(today());
-            println(" -->");
-        }
-        if (configuration.charset.length() > 0) {
-            println("<META http-equiv=\"Content-Type\" content=\"text/html; "
-                        + "charset=" + configuration.charset + "\">");
-        }
-        if ( configuration.windowtitle.length() > 0 ) {
-            title += " (" + configuration.windowtitle  + ")";
-        }
-        title(title);
-        println(title);
-        titleEnd();
-        println("");
-        if (! configuration.notimestamp) {
-                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-                println("<META NAME=\"date\" "
-                                    + "CONTENT=\"" + dateFormat.format(new Date()) + "\">");
-        }
-        if ( metakeywords != null ) {
-            for ( int i=0; i < metakeywords.length; i++ ) {
-                println("<META NAME=\"keywords\" "
-                            + "CONTENT=\"" + metakeywords[i] + "\">");
-            }
-        }
-        println("");
-        printStyleSheetProperties();
-        println("");
-        // Don't print windowtitle script for overview-frame, allclasses-frame
-        // and package-frame
-        if (includeScript) {
-            printWinTitleScript(title);
-        }
-        println("");
-        headEnd();
-        println("");
-        body("white", includeScript);
-    }
-
-    /**
      * Generates the HTML document tree and prints it out.
      *
      * @param metakeywords Array of String keywords for META tag. Each element
@@ -421,8 +361,7 @@
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
         if (!configuration.notimestamp) {
-            Content headComment = new Comment("Generated by javadoc (version " +
-                    ConfigurationImpl.BUILD_DATE + ") on " + today());
+            Content headComment = new Comment(getGeneratedByString());
             head.addContent(headComment);
         }
         if (configuration.charset.length() > 0) {
--- a/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Fri Sep 27 21:20:01 2013 +0400
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/SerializedFormWriterImpl.java	Wed Oct 10 18:34:46 2012 -0700
@@ -49,23 +49,6 @@
     }
 
     /**
-     * Writes the given header.
-     *
-     * @param header the header to write.
-     */
-    public void writeHeader(String header) {
-        printHtmlHeader(header, null, true);
-        printTop();
-        navLinks(true);
-        hr();
-        center();
-        h1();
-        print(header);
-        h1End();
-        centerEnd();
-    }
-
-    /**
      * Get the given header.
      *
      * @param header the header to write
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Fri Sep 27 21:20:01 2013 +0400
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Wed Oct 10 18:34:46 2012 -0700
@@ -29,6 +29,7 @@
 import java.util.*;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.ConfigurationImpl;
 import com.sun.tools.doclets.internal.toolkit.*;
 
 
@@ -328,7 +329,7 @@
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
         if (! noTimeStamp) {
-            Content headComment = new Comment("Generated by javadoc on " + today());
+            Content headComment = new Comment(getGeneratedByString());
             head.addContent(headComment);
         }
         if (configuration.charset.length() > 0) {
@@ -390,16 +391,9 @@
         print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
     }
 
-    /**
-     * Get the day and date information for today, depending upon user option.
-     *
-     * @return String Today.
-     * @see java.util.Calendar
-     * @see java.util.GregorianCalendar
-     * @see java.util.TimeZone
-     */
-    public String today() {
+    protected String getGeneratedByString() {
         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
-        return calendar.getTime().toString();
+        Date today = calendar.getTime();
+        return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
     }
 }
--- a/test/com/sun/javadoc/VersionNumber/VersionNumber.java	Fri Sep 27 21:20:01 2013 +0400
+++ b/test/com/sun/javadoc/VersionNumber/VersionNumber.java	Wed Oct 10 18:34:46 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,7 @@
 
             // Test the proper DOCTYPE element is present:
             {
-                 "<!-- Generated by javadoc (version",
+                 "<!-- Generated by javadoc (",
                      TMPDEST_DIR1 + "p1" + FS + "C.html"  },
 
         };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java	Wed Oct 10 18:34:46 2012 -0700
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8000418
+ * @summary Verify that files use a common Generated By string
+ * @library ../lib/
+ * @build JavadocTester TestGeneratedBy
+ * @run main TestGeneratedBy
+ */
+
+public class TestGeneratedBy extends JavadocTester {
+
+    private static final String OUTPUT_DIR = "tmp";
+
+    private static final String[] FILES = {
+        "pkg/MyClass.html",
+        "pkg/package-summary.html",
+        "pkg/package-frame.html",
+        "pkg/package-tree.html",
+        "allclasses-noframe.html",
+        "constant-values.html",
+        "allclasses-frame.html",
+        "overview-tree.html",
+        "deprecated-list.html",
+        "serialized-form.html",
+        "help-doc.html",
+        "index-all.html",
+        "index.html"
+    };
+
+    private static final String[] ARGS =
+        new String[] {
+            "-d", OUTPUT_DIR,
+            "-sourcepath", SRC_DIR,
+            "pkg"
+        };
+    private static final String BUG_ID = "8000418";
+
+    private static String[][] getTests() {
+        String version = System.getProperty("java.version");
+        String[][] tests = new String[FILES.length][];
+        for (int i = 0; i < FILES.length; i++) {
+            tests[i] = new String[] {
+                OUTPUT_DIR + FS + FILES[i],
+                "Generated by javadoc (" + version + ") on "
+            };
+        }
+        return tests;
+    }
+
+    private static String[][] getNegatedTests() {
+        String[][] tests = new String[FILES.length][];
+        for (int i = 0; i < FILES.length; i++) {
+            tests[i] = new String[] {
+                OUTPUT_DIR + FS + FILES[i],
+                "Generated by javadoc (version",
+                "Generated by javadoc on"
+            };
+        }
+        return tests;
+    }
+
+    /**
+     * The entry point of the test.
+     * @param args the array of command line arguments.
+     */
+    public static void main(String[] args) {
+        TestGeneratedBy tester = new TestGeneratedBy();
+        int exitCode = run(tester, ARGS, getTests(), getNegatedTests());
+        tester.printSummary();
+        if (exitCode != 0) {
+            throw new Error("Error found while executing Javadoc");
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugId() {
+        return BUG_ID;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBugName() {
+        return getClass().getName();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/javadoc/testGeneratedBy/pkg/MyClass.java	Wed Oct 10 18:34:46 2012 -0700
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg;
+
+import java.io.Serializable;
+
+public class MyClass implements Serializable {
+}