8203792: Remove "compatibility" features from Head.java
authorpmuthuswamy
Tue, 21 Aug 2018 11:41:54 +0530
changeset 51468 d48a852983eb
parent 51467 12997ebbc0d8
child 51469 8a9e5819eab5
8203792: Remove "compatibility" features from Head.java Reviewed-by: jjg, sundar
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java
test/langtools/jdk/javadoc/doclet/testHeadTag/TestHeadTag.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Mon Aug 20 13:58:23 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Tue Aug 21 11:41:54 2018 +0530
@@ -131,7 +131,7 @@
         DocType htmlDocType = DocType.forVersion(configuration.htmlVersion);
         Content htmlComment = contents.newPage;
         Head head = new Head(path, configuration.htmlVersion, configuration.docletVersion)
-                .setTimestamp(!configuration.notimestamp, false)
+                .setTimestamp(!configuration.notimestamp)
                 .setTitle(title)
                 .setCharset(configuration.charset)
                 .setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets())
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java	Mon Aug 20 13:58:23 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/IndexRedirectWriter.java	Tue Aug 21 11:41:54 2018 +0530
@@ -75,7 +75,7 @@
         DocType htmlDocType = DocType.forVersion(configuration.htmlVersion);
         Content htmlComment = contents.newPage;
         Head head = new Head(path, configuration.htmlVersion, configuration.docletVersion)
-                .setTimestamp(true, false)
+                .setTimestamp(true)
                 .addDefaultScript(false);
 
         String title = (configuration.windowtitle.length() > 0)
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java	Mon Aug 20 13:58:23 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java	Tue Aug 21 11:41:54 2018 +0530
@@ -58,8 +58,6 @@
     private String charset;
     private final List<String> keywords;
     private boolean showTimestamp;
-    private boolean showGeneratedBy;    // temporary: for compatibility
-    private boolean showMetaCreated;    // temporary: for compatibility
     private boolean useModuleDirectories;
     private DocFile mainStylesheetFile;
     private List<DocFile> additionalStylesheetFiles = Collections.emptyList();
@@ -140,26 +138,6 @@
     // no 'Generated by javadoc' comment will be added.
     public Head setTimestamp(boolean timestamp) {
         showTimestamp = timestamp;
-        showGeneratedBy = true;
-        showMetaCreated = timestamp;
-        return this;
-    }
-
-    /**
-     * Sets whether or not timestamps should be recorded in the HEAD element.
-     * The timestamp will be recorded in a comment, and possibly in an appropriate META
-     * element, depending on the HTML version specified when this object was created.
-     *
-     * @param timestamp true if timestamps should be be added.
-     * @param metaCreated  true if a META element should be added containing the timestamp
-     * @return this object
-     */
-    // This method is for temporary compatibility. In time, all clients should use
-    // {@code setTimestamp(boolean)}.
-    public Head setTimestamp(boolean timestamp, boolean metaCreated) {
-        showTimestamp = timestamp;
-        showGeneratedBy = true;
-        showMetaCreated = metaCreated;
         return this;
     }
 
@@ -258,16 +236,14 @@
         Date now = showTimestamp ? calendar.getTime() : null;
 
         HtmlTree tree = new HtmlTree(HtmlTag.HEAD);
-        if (showGeneratedBy) {
-            tree.addContent(getGeneratedBy(showTimestamp, now));
-        }
+        tree.addContent(getGeneratedBy(showTimestamp, now));
         tree.addContent(HtmlTree.TITLE(title));
 
         if (charset != null) { // compatibility; should this be allowed?
             tree.addContent(HtmlTree.META("Content-Type", "text/html", charset));
         }
 
-        if (showMetaCreated) {
+        if (showTimestamp) {
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
             tree.addContent(HtmlTree.META(
                     (htmlVersion == HtmlVersion.HTML5) ? "dc.created" : "date",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/jdk/javadoc/doclet/testHeadTag/TestHeadTag.java	Tue Aug 21 11:41:54 2018 +0530
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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 8203792
+ * @summary Remove "compatibility" features from Head.java
+ * @library /tools/lib ../lib
+ * @modules jdk.javadoc/jdk.javadoc.internal.tool
+ * @build JavadocTester toolbox.ToolBox builder.ClassBuilder
+ * @run main TestHeadTag
+ */
+
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.LocalDate;
+
+import builder.ClassBuilder;
+import toolbox.ToolBox;
+
+public class TestHeadTag extends JavadocTester {
+
+    final ToolBox tb;
+
+    public static void main(String... args) throws Exception {
+        TestHeadTag tester = new TestHeadTag();
+        tester.runTests(m -> new Object[]{Paths.get(m.getName())});
+    }
+
+    TestHeadTag() {
+        tb = new ToolBox();
+    }
+
+    @Test
+    void test(Path base) throws Exception {
+        Path srcDir = base.resolve("src");
+        createTestClass(srcDir);
+
+        Path outDir = base.resolve("out");
+        javadoc("-d", outDir.toString(),
+                "-sourcepath", srcDir.toString(),
+                "pkg");
+
+        checkExit(Exit.OK);
+
+        checkOrder("pkg/A.html",
+                "Generated by javadoc",
+                "<meta name=\"dc.created\"");
+    }
+
+    @Test
+    void testWithNoTimestamp(Path base) throws Exception {
+        Path srcDir = base.resolve("src");
+        createTestClass(srcDir);
+
+        Path outDir = base.resolve("out-1");
+        javadoc("-d", outDir.toString(),
+                "-notimestamp",
+                "-sourcepath", srcDir.toString(),
+                "pkg");
+
+        checkExit(Exit.OK);
+
+        checkOutput("pkg/A.html", true,
+                "<!-- Generated by javadoc -->");
+        checkOutput("pkg/A.html", false,
+                "<meta name=\"dc.created\"");
+    }
+
+    void createTestClass(Path srcDir) throws Exception {
+        new ClassBuilder(tb, "pkg.A")
+                .setModifiers("public", "class")
+                .write(srcDir);
+    }
+}