changeset 2005:044721d4d359

8024288: javadoc generated-by comment should always be present Reviewed-by: bpatel
author jjg
date Wed, 04 Sep 2013 14:44:05 -0700
parents b94824ddcbb6
children a76c663a9cac
files src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java
diffstat 3 files changed, 34 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Sep 04 11:53:09 2013 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Sep 04 14:44:05 2013 -0700
@@ -406,10 +406,7 @@
         Content htmlDocType = DocType.TRANSITIONAL;
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
-        if (!configuration.notimestamp) {
-            Content headComment = new Comment(getGeneratedByString());
-            head.addContent(headComment);
-        }
+        head.addContent(getGeneratedBy(!configuration.notimestamp));
         if (configuration.charset.length() > 0) {
             Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
                     configuration.charset);
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Wed Sep 04 11:53:09 2013 +0100
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Wed Sep 04 14:44:05 2013 -0700
@@ -191,10 +191,7 @@
         Content htmlDocType = DocType.FRAMESET;
         Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
         Content head = new HtmlTree(HtmlTag.HEAD);
-        if (! noTimeStamp) {
-            Content headComment = new Comment(getGeneratedByString());
-            head.addContent(headComment);
-        }
+        head.addContent(getGeneratedBy(!noTimeStamp));
         if (configuration.charset.length() > 0) {
             Content meta = HtmlTree.META("Content-Type", CONTENT_TYPE,
                     configuration.charset);
@@ -210,9 +207,13 @@
         write(htmlDocument);
     }
 
-    protected String getGeneratedByString() {
-        Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
-        Date today = calendar.getTime();
-        return "Generated by javadoc ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
+    protected Comment getGeneratedBy(boolean timestamp) {
+        String text = "Generated by javadoc"; // marker string, deliberately not localized
+        if (timestamp) {
+            Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
+            Date today = calendar.getTime();
+            text += " ("+ ConfigurationImpl.BUILD_DATE + ") on " + today;
+        }
+        return new Comment(text);
     }
 }
--- a/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java	Wed Sep 04 11:53:09 2013 +0100
+++ b/test/com/sun/javadoc/testGeneratedBy/TestGeneratedBy.java	Wed Sep 04 14:44:05 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8000418
+ * @bug 8000418 8024288
  * @summary Verify that files use a common Generated By string
  * @library ../lib/
  * @build JavadocTester TestGeneratedBy
@@ -50,32 +50,44 @@
         "index.html"
     };
 
-    private static final String[] ARGS =
+    private static final String[] STD_ARGS =
         new String[] {
             "-d", OUTPUT_DIR,
             "-sourcepath", SRC_DIR,
             "pkg"
         };
-    private static final String BUG_ID = "8000418";
 
-    private static String[][] getTests() {
+    private static final String[] NO_TIMESTAMP_ARGS =
+        new String[] {
+            "-notimestamp",
+            "-d", OUTPUT_DIR,
+            "-sourcepath", SRC_DIR,
+            "pkg"
+        };
+
+    private static final String BUG_ID = "8000418-8024288";
+
+    private static String[][] getTests(boolean timestamp) {
         String version = System.getProperty("java.version");
         String[][] tests = new String[FILES.length][];
         for (int i = 0; i < FILES.length; i++) {
+            String genBy = "Generated by javadoc";
+            if (timestamp) genBy += " (" + version + ") on ";
             tests[i] = new String[] {
-                OUTPUT_DIR + FS + FILES[i],
-                "Generated by javadoc (" + version + ") on "
+                OUTPUT_DIR + FS + FILES[i], genBy
             };
         }
         return tests;
     }
 
-    private static String[][] getNegatedTests() {
+    private static String[][] getNegatedTests(boolean timestamp) {
         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",
+                (timestamp
+                    ? "Generated by javadoc (version"
+                    : "Generated by javadoc ("),
                 "Generated by javadoc on"
             };
         }
@@ -88,9 +100,10 @@
      */
     public static void main(String[] args) {
         TestGeneratedBy tester = new TestGeneratedBy();
-        int exitCode = run(tester, ARGS, getTests(), getNegatedTests());
+        int ec1 = run(tester, STD_ARGS, getTests(true), getNegatedTests(true));
+        int ec2 = run(tester, NO_TIMESTAMP_ARGS, getTests(false), getNegatedTests(false));
         tester.printSummary();
-        if (exitCode != 0) {
+        if (ec1 != 0 || ec2 != 0) {
             throw new Error("Error found while executing Javadoc");
         }
     }