8203792: Remove "compatibility" features from Head.java
Reviewed-by: jjg, sundar
This commit is contained in:
parent
bc62b3a40e
commit
f1173ad06c
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html
test/langtools/jdk/javadoc/doclet/testHeadTag
@ -131,7 +131,7 @@ public class FrameOutputWriter extends HtmlDocletWriter {
|
||||
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())
|
||||
|
@ -75,7 +75,7 @@ public class IndexRedirectWriter extends HtmlDocletWriter {
|
||||
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)
|
||||
|
@ -58,8 +58,6 @@ public class Head {
|
||||
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 @@ public class Head {
|
||||
// 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 @@ public class Head {
|
||||
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",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user