8310118: Resource files should be moved to appropriate directories

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2023-08-09 07:01:15 +00:00
parent 96304f37f8
commit 77e5739f60
44 changed files with 174 additions and 195 deletions

View File

@ -25,13 +25,14 @@
package jdk.javadoc.internal.doclets.formats.html;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
@ -61,6 +62,7 @@ import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.NewAPIBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.PreviewAPIListBuilder;
import jdk.javadoc.internal.doclets.toolkit.util.ResourceIOException;
/**
* The class with "start" method, calls individual Writers.
@ -107,12 +109,6 @@ public class HtmlDoclet extends AbstractDoclet {
*/
private WriterFactory writerFactory;
/**
* Base path for resources for this doclet.
*/
private static final DocPath DOCLET_RESOURCES = DocPath
.create("/jdk/javadoc/internal/doclets/formats/html/resources");
@Override // defined by Doclet
public void init(Locale locale, Reporter reporter) {
configuration = new HtmlConfiguration(initiatingDoclet, locale, reporter);
@ -232,13 +228,13 @@ public class HtmlDoclet extends AbstractDoclet {
return;
}
boolean nodeprecated = options.noDeprecated();
performCopy(options.helpFile(), DocPath.empty);
performCopy(options.stylesheetFile(), DocPath.empty);
copyFile(options.helpFile(), DocPath.empty);
copyFile(options.stylesheetFile(), DocPaths.RESOURCE_FILES);
for (String stylesheet : options.additionalStylesheets()) {
performCopy(stylesheet, DocPath.empty);
copyFile(stylesheet, DocPaths.RESOURCE_FILES);
}
for (String script : options.additionalScripts()) {
performCopy(script, DocPaths.SCRIPT_DIR);
copyFile(script, DocPaths.SCRIPT_FILES);
}
// do early to reduce memory footprint
if (options.classUse()) {
@ -304,31 +300,25 @@ public class HtmlDoclet extends AbstractDoclet {
// If a stylesheet file is not specified, copy the default stylesheet
// and replace newline with platform-specific newline.
DocFile f;
if (options.stylesheetFile().length() == 0) {
f = DocFile.createFileForOutput(configuration, DocPaths.STYLESHEET);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.STYLESHEET), true, true);
copyResource(DocPaths.STYLESHEET, DocPaths.RESOURCE_FILES.resolve(DocPaths.STYLESHEET), true);
}
f = DocFile.createFileForOutput(configuration, DocPaths.JAVASCRIPT);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.JAVASCRIPT), true, true);
f = DocFile.createFileForOutput(configuration, DocPaths.CLIPBOARD_SVG);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.CLIPBOARD_SVG), true, true);
f = DocFile.createFileForOutput(configuration, DocPaths.LINK_SVG);
f.copyResource(DocPaths.RESOURCES.resolve(DocPaths.LINK_SVG), true, true);
copyResource(DocPaths.SCRIPT_JS, DocPaths.SCRIPT_FILES.resolve(DocPaths.SCRIPT_JS), true);
copyResource(DocPaths.CLIPBOARD_SVG, DocPaths.RESOURCE_FILES.resolve(DocPaths.CLIPBOARD_SVG), true);
copyResource(DocPaths.LINK_SVG, DocPaths.RESOURCE_FILES.resolve(DocPaths.LINK_SVG), true);
if (options.createIndex()) {
f = DocFile.createFileForOutput(configuration, DocPaths.SEARCH_JS);
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.SEARCH_JS_TEMPLATE), configuration.docResources);
f = DocFile.createFileForOutput(configuration, DocPaths.SEARCH_PAGE_JS);
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.SEARCH_PAGE_JS), configuration.docResources);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.GLASS_IMG));
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.GLASS_IMG), true, false);
f = DocFile.createFileForOutput(configuration, DocPaths.RESOURCES.resolve(DocPaths.X_IMG));
f.copyResource(DOCLET_RESOURCES.resolve(DocPaths.X_IMG), true, false);
copyJqueryFiles();
}
copyResource(DocPaths.SEARCH_JS_TEMPLATE, DocPaths.SCRIPT_FILES.resolve(DocPaths.SEARCH_JS), true);
copyResource(DocPaths.SEARCH_PAGE_JS, DocPaths.SCRIPT_FILES.resolve(DocPaths.SEARCH_PAGE_JS), true);
copyResource(DocPaths.GLASS_IMG, DocPaths.RESOURCE_FILES.resolve(DocPaths.GLASS_IMG), false);
copyResource(DocPaths.X_IMG, DocPaths.RESOURCE_FILES.resolve(DocPaths.X_IMG), false);
// No newline replacement for JQuery files
copyResource(DocPaths.JQUERY_DIR.resolve(DocPaths.JQUERY_JS),
DocPaths.SCRIPT_FILES.resolve(DocPaths.JQUERY_JS), false);
copyResource(DocPaths.JQUERY_DIR.resolve(DocPaths.JQUERY_UI_JS),
DocPaths.SCRIPT_FILES.resolve(DocPaths.JQUERY_UI_JS), false);
copyResource(DocPaths.JQUERY_DIR.resolve(DocPaths.JQUERY_UI_CSS),
DocPaths.RESOURCE_FILES.resolve(DocPaths.JQUERY_UI_CSS), false); }
copyLegalFiles(options.createIndex());
}
@ -340,20 +330,6 @@ public class HtmlDoclet extends AbstractDoclet {
if (configuration.tagletManager != null) { // may be null, if no files generated, perhaps because of errors
configuration.tagletManager.printReport();
}
}
private void copyJqueryFiles() throws DocletException {
List<String> files = Arrays.asList(
DocPaths.JQUERY_JS.getPath(),
DocPaths.JQUERY_UI_JS.getPath(),
DocPaths.JQUERY_UI_CSS.getPath());
DocFile f;
for (String file : files) {
DocPath filePath = DocPaths.SCRIPT_DIR.resolve(file);
f = DocFile.createFileForOutput(configuration, filePath);
f.copyResource(DOCLET_RESOURCES.resolve(filePath), true, false);
}
}
private void copyLegalFiles(boolean includeJQuery) throws DocletException {
@ -444,7 +420,24 @@ public class HtmlDoclet extends AbstractDoclet {
return configuration.getOptions().getSupportedOptions();
}
private void performCopy(String filename, DocPath targetPath) throws DocFileIOException {
private void copyResource(DocPath sourcePath, DocPath targetPath, boolean replaceNewLine)
throws DocletException {
DocPath resourcePath = DocPaths.RESOURCES.resolve(sourcePath);
// Resolve resources against doclets.formats.html package
URL resourceURL = HtmlConfiguration.class.getResource(resourcePath.getPath());
if (resourceURL == null) {
throw new ResourceIOException(sourcePath, new FileNotFoundException(resourcePath.getPath()));
}
DocFile f = DocFile.createFileForOutput(configuration, targetPath);
if (sourcePath.getPath().toLowerCase(Locale.ROOT).endsWith(".template")) {
f.copyResource(resourcePath, resourceURL, configuration.docResources);
} else {
f.copyResource(resourcePath, resourceURL, replaceNewLine);
}
}
private void copyFile(String filename, DocPath targetPath) throws DocFileIOException {
if (filename.isEmpty()) {
return;
}

View File

@ -466,7 +466,6 @@ public abstract class HtmlDocletWriter {
Content body)
throws DocFileIOException {
List<DocPath> additionalStylesheets = configuration.getAdditionalStylesheets();
additionalStylesheets.addAll(localStylesheets);
Head head = new Head(path, configuration.getDocletVersion(), configuration.getBuildDate())
.setTimestamp(!options.noTimestamp())
.setDescription(description)
@ -474,7 +473,7 @@ public abstract class HtmlDocletWriter {
.setTitle(winTitle)
.setCharset(options.charset())
.addKeywords(metakeywords)
.setStylesheets(configuration.getMainStylesheet(), additionalStylesheets)
.setStylesheets(configuration.getMainStylesheet(), additionalStylesheets, localStylesheets)
.setAdditionalScripts(configuration.getAdditionalScripts())
.setIndex(options.createIndex(), mainBodyScript)
.addContent(extraHeadContent);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2023, 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
@ -74,7 +74,7 @@ public class IndexRedirectWriter extends HtmlDocletWriter {
.setTimestamp(!options.noTimestamp())
.setDescription("index redirect")
.setGenerator(getGenerator(getClass()))
.setStylesheets(configuration.getMainStylesheet(), List.of()) // avoid reference to default stylesheet
.setStylesheets(configuration.getMainStylesheet(), List.of(), List.of())
.addDefaultScript(false);
String title = (options.windowTitle().length() > 0)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, 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
@ -96,7 +96,8 @@ public class SearchWriter extends HtmlDocletWriter {
.setId(HtmlId.of("page-search-link")))
.add(new HtmlTree(TagName.BUTTON)
.add(new HtmlTree(TagName.IMG)
.put(HtmlAttr.SRC, pathToRoot.resolve(DocPaths.CLIPBOARD_SVG).getPath())
.put(HtmlAttr.SRC, pathToRoot.resolve(DocPaths.RESOURCE_FILES)
.resolve(DocPaths.CLIPBOARD_SVG).getPath())
.put(HtmlAttr.ALT, copyUrlText))
.add(HtmlTree.SPAN(Text.of(copyText))
.put(HtmlAttr.DATA_COPIED, copiedText))
@ -114,6 +115,7 @@ public class SearchWriter extends HtmlDocletWriter {
.addUnchecked(Text.EMPTY))
.setId(HtmlId.of("result-section"))
.put(HtmlAttr.STYLE, "display: none;")
.add(HtmlTree.SCRIPT(pathToRoot.resolve(DocPaths.SEARCH_PAGE_JS).getPath())));
.add(HtmlTree.SCRIPT(pathToRoot.resolve(DocPaths.SCRIPT_FILES)
.resolve(DocPaths.SEARCH_PAGE_JS).getPath())));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, 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
@ -30,6 +30,7 @@ import jdk.javadoc.internal.doclets.formats.html.markup.Head;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Reader;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.ModuleElement;
@ -232,43 +233,13 @@ public class SourceToHTMLConverter {
.setDescription(HtmlDocletWriter.getDescription("source", te))
.setGenerator(HtmlDocletWriter.getGenerator(getClass()))
.addDefaultScript(false)
.setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets());
.setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets(), List.of());
var html = HtmlTree.HTML(configuration.getLocale().getLanguage(), head, body);
HtmlDocument document = new HtmlDocument(html);
messages.notice("doclet.Generating_0", path.getPath());
document.write(DocFile.createFileForOutput(configuration, path));
}
/**
* Returns a link to the stylesheet file.
*
* @param head the content to which the stylesheet links will be added
*/
public void addStyleSheetProperties(Content head) {
String filename = options.stylesheetFile();
DocPath stylesheet;
if (filename.length() > 0) {
DocFile file = DocFile.createFileForInput(configuration, filename);
stylesheet = DocPath.create(file.getName());
} else {
stylesheet = DocPaths.STYLESHEET;
}
DocPath p = relativePath.resolve(stylesheet);
var link = HtmlTree.LINK("stylesheet", "text/css", p.getPath(), "Style");
head.add(link);
addStylesheets(head);
}
protected void addStylesheets(Content head) {
options.additionalStylesheets().forEach(css -> {
DocFile file = DocFile.createFileForInput(configuration, css);
DocPath cssPath = DocPath.create(file.getName());
var slink = HtmlTree.LINK("stylesheet", "text/css", relativePath.resolve(cssPath).getPath(),
"Style");
head.add(slink);
});
}
/**
* Get the header.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -55,6 +55,7 @@ public class Head extends Content {
private boolean showTimestamp;
private DocPath mainStylesheet;
private List<DocPath> additionalStylesheets = List.of();
private List<DocPath> localStylesheets = List.of();
private boolean index;
private Script mainBodyScript;
private final List<Script> scripts;
@ -157,11 +158,13 @@ public class Head extends Content {
*
* @param main the main stylesheet, or null to use the default
* @param additional a list of any additional stylesheets to be included
* @param local a list of module- or package-local stylesheets to be included
* @return this object
*/
public Head setStylesheets(DocPath main, List<DocPath> additional) {
public Head setStylesheets(DocPath main, List<DocPath> additional, List<DocPath> local) {
this.mainStylesheet = main;
this.additionalStylesheets = additional;
this.localStylesheets = local;
return this;
}
@ -319,14 +322,19 @@ public class Head extends Content {
if (mainStylesheet == null) {
mainStylesheet = DocPaths.STYLESHEET;
}
addStylesheet(head, mainStylesheet);
addStylesheet(head, DocPaths.RESOURCE_FILES.resolve(mainStylesheet));
for (DocPath path : additionalStylesheets) {
addStylesheet(head, DocPaths.RESOURCE_FILES.resolve(path));
}
for (DocPath path : localStylesheets) {
// Local stylesheets are contained in doc-files, so omit resource-files prefix
addStylesheet(head, path);
}
if (index) {
addStylesheet(head, DocPaths.SCRIPT_DIR.resolve(DocPaths.JQUERY_UI_CSS));
addStylesheet(head, DocPaths.RESOURCE_FILES.resolve(DocPaths.JQUERY_UI_CSS));
}
}
@ -337,7 +345,7 @@ public class Head extends Content {
private void addScripts(HtmlTree head) {
if (addDefaultScript) {
head.add(HtmlTree.SCRIPT(pathToRoot.resolve(DocPaths.JAVASCRIPT).getPath()));
addScriptElement(head, DocPaths.SCRIPT_FILES.resolve(DocPaths.SCRIPT_JS));
}
if (index) {
if (pathToRoot != null && mainBodyScript != null) {
@ -347,11 +355,11 @@ public class Head extends Content {
.append(";\n")
.append("loadScripts(document, 'script');");
}
addScriptElement(head, DocPaths.JQUERY_JS);
addScriptElement(head, DocPaths.JQUERY_UI_JS);
addScriptElement(head, DocPaths.SCRIPT_FILES.resolve(DocPaths.JQUERY_JS));
addScriptElement(head, DocPaths.SCRIPT_FILES.resolve(DocPaths.JQUERY_UI_JS));
}
for (DocPath path : additionalScripts) {
addScriptElement(head, path);
addScriptElement(head, DocPaths.SCRIPT_FILES.resolve(path));
}
for (Script script : scripts) {
head.add(script.asContent());
@ -359,7 +367,7 @@ public class Head extends Content {
}
private void addScriptElement(HtmlTree head, DocPath filePath) {
DocPath scriptFile = pathToRoot.resolve(DocPaths.SCRIPT_DIR).resolve(filePath);
DocPath scriptFile = pathToRoot.resolve(filePath);
head.add(HtmlTree.SCRIPT(scriptFile.getPath()));
}
}

View File

@ -37,7 +37,7 @@ var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
function loadScripts(doc, tag) {
createElem(doc, tag, 'search.js');
createElem(doc, tag, 'script-files/search.js');
createElem(doc, tag, 'module-search-index.js');
createElem(doc, tag, 'package-search-index.js');

View File

@ -413,7 +413,7 @@ $(function() {
var id = hdr.attr("id") || hdr.parent("section").attr("id") || hdr.children("a").attr("id");
if (id) {
hdr.append(" <a href='#" + id + "' class='anchor-link' aria-label='" + messages.linkToSection
+ "'><img src='" + pathtoroot + "link.svg' alt='" + messages.linkIcon +"' tabindex='0'"
+ "'><img src='" + pathtoroot + "resource-files/link.svg' alt='" + messages.linkIcon +"' tabindex='0'"
+ " width='16' height='16'></a>");
}
});

View File

@ -2,7 +2,7 @@
* Javadoc style sheet
*/
@import url('resources/fonts/dejavu.css');
@import url('fonts/dejavu.css');
/*
* These CSS custom properties (variables) define the core color and font
@ -757,7 +757,7 @@ li.ui-static-link a, li.ui-static-link a:visited {
font-weight:bold;
}
#search-input, #page-search-input {
background-image:url('resources/glass.png');
background-image:url('glass.png');
background-size:13px;
background-repeat:no-repeat;
background-position:2px 3px;
@ -773,7 +773,7 @@ li.ui-static-link a, li.ui-static-link a:visited {
}
#reset-button {
background-color: transparent;
background-image:url('resources/x.png');
background-image:url('x.png');
background-repeat:no-repeat;
background-size:contain;
border:0;

View File

@ -222,7 +222,8 @@ public class SnippetTaglet extends BaseTaglet {
.add(HtmlTree.SPAN(Text.of(copyText))
.put(HtmlAttr.DATA_COPIED, copiedText))
.add(new HtmlTree(TagName.IMG)
.put(HtmlAttr.SRC, pathToRoot.resolve(DocPaths.CLIPBOARD_SVG).getPath())
.put(HtmlAttr.SRC, pathToRoot.resolve(DocPaths.RESOURCE_FILES)
.resolve(DocPaths.CLIPBOARD_SVG).getPath())
.put(HtmlAttr.ALT, copySnippetText))
.addStyle(HtmlStyle.copy)
.addStyle(HtmlStyle.snippetCopy)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, 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
@ -32,6 +32,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URL;
import java.nio.file.Path;
import java.util.MissingResourceException;
import java.util.regex.Matcher;
@ -176,8 +177,8 @@ public abstract class DocFile {
/**
* Copy the contents of a resource file to this file.
*
* @param resource the path of the resource, relative to the package of this class
* @param overwrite whether or not to overwrite the file if it already exists
* @param resource the path of the resource
* @param url the URL of the resource
* @param replaceNewLine if false, the file is copied as a binary file;
* if true, the file is written line by line, using the platform line
* separator
@ -185,35 +186,31 @@ public abstract class DocFile {
* @throws DocFileIOException if there is a problem while writing the copy
* @throws ResourceIOException if there is a problem while reading the resource
*/
public void copyResource(DocPath resource, boolean overwrite, boolean replaceNewLine)
public void copyResource(DocPath resource, URL url, boolean replaceNewLine)
throws DocFileIOException, ResourceIOException {
if (exists() && !overwrite)
return;
copyResource(resource, replaceNewLine, null);
copyResource(resource, url, replaceNewLine, null);
}
/**
* Copy the contents of a resource file to this file.
*
* @param resource the path of the resource, relative to the package of this class
* @param resource the path of the resource
* @param url the URL of the resource
* @param resources if not {@code null}, substitute occurrences of {@code ##REPLACE:key##}
*
* @throws DocFileIOException if there is a problem while writing the copy
* @throws ResourceIOException if there is a problem while reading the resource
*/
public void copyResource(DocPath resource, Resources resources) throws DocFileIOException, ResourceIOException {
copyResource(resource, true, resources);
public void copyResource(DocPath resource, URL url, Resources resources) throws DocFileIOException, ResourceIOException {
copyResource(resource, url, true, resources);
}
private void copyResource(DocPath resource, boolean replaceNewLine, Resources resources)
private void copyResource(DocPath resource, URL url, boolean replaceNewLine, Resources resources)
throws DocFileIOException, ResourceIOException {
try {
InputStream in = BaseConfiguration.class.getResourceAsStream(resource.getPath());
if (in == null)
return;
InputStream in = url.openStream();
try {
try (in) {
if (replaceNewLine) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
try (Writer writer = openWriter()) {
@ -237,8 +234,6 @@ public abstract class DocFile {
throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
}
}
} finally {
in.close();
}
} catch (IOException e) {
throw new ResourceIOException(resource, e);

View File

@ -92,7 +92,7 @@ public class DocPaths {
}
/** The name of the default javascript file. */
public static final DocPath JAVASCRIPT = DocPath.create("script.js");
public static final DocPath SCRIPT_JS = DocPath.create("script.js");
/** The name of the copy-to-clipboard icon file. */
public static final DocPath CLIPBOARD_SVG = DocPath.create("copy.svg");
@ -100,6 +100,9 @@ public class DocPaths {
/** The name of the link icon file. */
public static final DocPath LINK_SVG = DocPath.create("link.svg");
/** The name of the default jQuery directory. */
public static final DocPath JQUERY_DIR = DocPath.create("jquery");
/** The name of the default jQuery javascript file. */
public static final DocPath JQUERY_JS = DocPath.create("jquery-3.6.1.min.js");
@ -145,8 +148,11 @@ public class DocPaths {
/** The name of the file for preview elements. */
public static final DocPath PREVIEW_LIST = DocPath.create("preview-list.html");
/** The name of the directory for the resource files. */
public static final DocPath RESOURCE_FILES = DocPath.create("resource-files");
/** The name of the directory for the script files. */
public static final DocPath SCRIPT_DIR = DocPath.create("script-dir");
public static final DocPath SCRIPT_FILES = DocPath.create("script-files");
/** The name of the file for search page. */
public static final DocPath SEARCH_PAGE = DocPath.create("search.html");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, 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
@ -50,7 +50,7 @@ public class AccessH1 extends JavadocTester {
checkExit(Exit.OK);
// Test the style sheet
checkOutput("stylesheet.css", true,
checkOutput("resource-files/stylesheet.css", true,
"""
h1 {
font-size:1.428em;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2023, 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
@ -73,7 +73,7 @@ public class CheckLibraryVersions {
var legalDir = rootDir.resolve("src/jdk.javadoc/share/legal");
var scriptDir = rootDir.resolve("src/jdk.javadoc/share/classes")
.resolve("jdk/javadoc/internal/doclets/formats/html")
.resolve("resources/script-dir");
.resolve("resources/jquery");
for (var legalFileName : libraries.keySet()) {
var legalFile = legalDir.resolve(legalFileName);

View File

@ -27,7 +27,7 @@
* @bug 8267574
* @summary check stylesheet names against HtmlStyle
* @modules jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.markup
* jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.resources:open
* jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.resources:open
*/
import java.io.BufferedWriter;
@ -192,7 +192,7 @@ public class CheckStylesheetClasses {
Set<String> getStylesheetNames() throws IOException {
Set<String> names = new TreeSet<>();
String stylesheet = "/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css";
String stylesheet = "/jdk/javadoc/internal/doclets/formats/html/resources/stylesheet.css";
URL url = HtmlStyle.class.getResource(stylesheet);
readStylesheet(url, names);
return names;
@ -211,4 +211,4 @@ public class CheckStylesheetClasses {
}
}
}
}
}

View File

@ -56,7 +56,7 @@ public class TestDocEncoding extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("stylesheet.css", true,
checkOutput("resource-files/stylesheet.css", true,
"""
body {
background-color:var(--body-background-color);""");
@ -64,7 +64,7 @@ public class TestDocEncoding extends JavadocTester {
// reset the charset, for a negative test, that the -docencoding
// was effective and that the output is not in UTF-8.
charset = Charset.forName("UTF-8");
checkOutput("stylesheet.css", false,
checkOutput("resource-files/stylesheet.css", false,
"""
body {
background-color:var(--page-bg-color);""");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, 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
@ -61,7 +61,7 @@ public class TestJavascript extends JavadocTester {
//-->
""");
checkOutput("script.js", false,
checkOutput("script-files/script.js", false,
"""
$(window).resize(function() {
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, 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
@ -116,9 +116,9 @@ public class TestOptions extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("custom-stylesheet.css", true, "Custom javadoc style sheet");
checkOutput("resource-files/custom-stylesheet.css", true, "Custom javadoc style sheet");
checkOutput("pkg/Foo.html", true, """
<link rel="stylesheet" type="text/css" href="../custom-stylesheet.css" title="Style">""");
<link rel="stylesheet" type="text/css" href="../resource-files/custom-stylesheet.css" title="Style">""");
}
@Test
@ -129,9 +129,9 @@ public class TestOptions extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("custom-stylesheet.css", true, "Custom javadoc style sheet");
checkOutput("resource-files/custom-stylesheet.css", true, "Custom javadoc style sheet");
checkOutput("pkg/Foo.html", true, """
<link rel="stylesheet" type="text/css" href="../custom-stylesheet.css" title="Style">""");
<link rel="stylesheet" type="text/css" href="../resource-files/custom-stylesheet.css" title="Style">""");
}
@Test
@ -144,14 +144,14 @@ public class TestOptions extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("additional-stylesheet-1.css", true, "Additional javadoc style sheet 1");
checkOutput("additional-stylesheet-2.css", true, "Additional javadoc style sheet 2");
checkOutput("additional-stylesheet-3.css", true, "Additional javadoc style sheet 3");
checkOutput("resource-files/additional-stylesheet-1.css", true, "Additional javadoc style sheet 1");
checkOutput("resource-files/additional-stylesheet-2.css", true, "Additional javadoc style sheet 2");
checkOutput("resource-files/additional-stylesheet-3.css", true, "Additional javadoc style sheet 3");
checkOutput("pkg/Foo.html", true,
"""
<link rel="stylesheet" type="text/css" href="../additional-stylesheet-1.css" title="Style">
<link rel="stylesheet" type="text/css" href="../additional-stylesheet-2.css" title="Style">
<link rel="stylesheet" type="text/css" href="../additional-stylesheet-3.css" title="Style">""");
<link rel="stylesheet" type="text/css" href="../resource-files/additional-stylesheet-1.css" title="Style">
<link rel="stylesheet" type="text/css" href="../resource-files/additional-stylesheet-2.css" title="Style">
<link rel="stylesheet" type="text/css" href="../resource-files/additional-stylesheet-3.css" title="Style">""");
}
@Test
@ -189,12 +189,12 @@ public class TestOptions extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("script-dir/additional-script-1.js", true, "Additional script file 1");
checkOutput("script-dir/additional-script-2.js", true, "Additional script file 2");
checkOutput("script-files/additional-script-1.js", true, "Additional script file 1");
checkOutput("script-files/additional-script-2.js", true, "Additional script file 2");
checkOutput("pkg/Foo.html", true,
"""
<script type="text/javascript" src="../script-dir/additional-script-1.js"></script>
<script type="text/javascript" src="../script-dir/additional-script-2.js"></script>
<script type="text/javascript" src="../script-files/additional-script-1.js"></script>
<script type="text/javascript" src="../script-files/additional-script-2.js"></script>
""");
}

View File

@ -135,7 +135,7 @@ public class TestSearch extends JavadocTester {
"index-all.html",
"allpackages-index.html",
"allclasses-index.html",
"search-page.js",
"script-files/search-page.js",
"search.html");
}
@ -179,7 +179,7 @@ public class TestSearch extends JavadocTester {
"tag-search-index.js",
"type-search-index.js",
"index-all.html",
"search-page.js",
"script-files/search-page.js",
"search.html");
}
@ -418,13 +418,13 @@ public class TestSearch extends JavadocTester {
// Test for search related markup
checkOutput(fileName, expectedOutput,
"""
<link rel="stylesheet" type="text/css" href="script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="resource-files/jquery-ui.min.css" title="Style">
""",
"""
<script type="text/javascript" src="script-dir/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="script-files/jquery-3.6.1.min.js"></script>
""",
"""
<script type="text/javascript" src="script-dir/jquery-ui.min.js"></script>""",
<script type="text/javascript" src="script-files/jquery-ui.min.js"></script>""",
"""
var pathtoroot = "./";
loadScripts(document, 'script');""",
@ -690,29 +690,29 @@ public class TestSearch extends JavadocTester {
void checkJqueryAndImageFiles(boolean expectedOutput) {
checkFiles(expectedOutput,
"search.js",
"script-dir/jquery-3.6.1.min.js",
"script-dir/jquery-ui.min.js",
"script-dir/jquery-ui.min.css",
"resources/x.png",
"resources/glass.png");
"script-files/search.js",
"script-files/jquery-3.6.1.min.js",
"script-files/jquery-ui.min.js",
"resource-files/jquery-ui.min.css",
"resource-files/x.png",
"resource-files/glass.png");
}
void checkSearchJS() {
// ensure all resource keys were resolved
checkOutput("search.js", false,
checkOutput("script-files/search.js", false,
"##REPLACE:");
checkOutput("search.js", true,
checkOutput("script-files/search.js", true,
"function searchIndex(indexArray, category) {",
"function getURLPrefix(item, category) {",
"url += item.l;");
checkOutput("search-page.js", true,
checkOutput("script-files/search-page.js", true,
"function renderResults(result) {",
"function selectTab(category) {");
checkCssClasses("search.js", "stylesheet.css");
checkCssClasses("script-files/search.js", "resource-files/stylesheet.css");
}
void checkCssClasses(String jsFile, String cssFile) {

View File

@ -115,7 +115,7 @@ public class SnippetTester extends JavadocTester {
Optional<String> id) {
// the further away from the root, the further to reach to common resources
int nComponents = (int) pathToHtmlFile.chars().filter(c -> c == '/').count();
var svgString = "../".repeat(nComponents) + "copy.svg";
var svgString = "../".repeat(nComponents) + "resource-files/copy.svg";
var idString = id.isEmpty() ? "" : " id=\"%s\"".formatted(id.get());
var langString = lang.isEmpty() ? "" : " class=\"language-%s\"".formatted(lang.get());
return """

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, 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
@ -65,7 +65,7 @@ public class TestStylesheet extends JavadocTester {
// TODO: most of this test seems a bit silly, since javadoc is simply
// copying in the stylesheet from the source directory
checkOutput("stylesheet.css", true,
checkOutput("resource-files/stylesheet.css", true,
"""
body {
background-color:var(--body-background-color);
@ -141,7 +141,7 @@ public class TestStylesheet extends JavadocTester {
overflow-x: auto;
scrollbar-width: thin;
}""",
"@import url('resources/fonts/dejavu.css');",
"@import url('fonts/dejavu.css');",
"""
.search-tag-result:target {
background-color:var(--search-tag-highlight-color);
@ -175,7 +175,7 @@ public class TestStylesheet extends JavadocTester {
"""
#reset-button {
background-color: transparent;
background-image:url('resources/x.png');
background-image:url('x.png');
background-repeat:no-repeat;
background-size:contain;
border:0;
@ -197,7 +197,7 @@ public class TestStylesheet extends JavadocTester {
// Test whether a link to the stylesheet file is inserted properly
// in the class documentation.
"""
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">""",
<link rel="stylesheet" type="text/css" href="../resource-files/stylesheet.css" title="Style">""",
"""
<div class="block">Test comment for a class which has an <a name="named_anchor">anchor_with_name</a> and
an <a id="named_anchor1">anchor_with_id</a>.</div>""");
@ -211,9 +211,9 @@ public class TestStylesheet extends JavadocTester {
checkOutput("index.html", true,
"""
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">""");
<link rel="stylesheet" type="text/css" href="resource-files/stylesheet.css" title="Style">""");
checkOutput("stylesheet.css", false,
checkOutput("resource-files/stylesheet.css", false,
"""
* {
margin:0;
@ -275,7 +275,7 @@ public class TestStylesheet extends JavadocTester {
Set<String> readStylesheet() {
// scan for class selectors, skipping '{' ... '}'
Set<String> styles = new TreeSet<>();
String stylesheet = readFile("stylesheet.css");
String stylesheet = readFile("resource-files/stylesheet.css");
for (int i = 0; i < stylesheet.length(); i++) {
char ch = stylesheet.charAt(i);
switch (ch) {

View File

@ -1,4 +1,4 @@
/* * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
/* * Copyright (c) 2018, 2023, 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
@ -58,9 +58,10 @@ public class TestStylesheetOverwrite extends JavadocTester {
createTestClass(srcDir);
Path outDir = base.resolve("out");
Path resourceDir = outDir.resolve("resource-files");
Files.createDirectories(resourceDir);
Files.createDirectory(outDir);
Path stylesheet = outDir.resolve("stylesheet.css");
Path stylesheet = resourceDir.resolve("stylesheet.css");
Files.createFile(stylesheet);
Files.write(stylesheet, List.of("/* custom stylesheet */"));
@ -71,7 +72,7 @@ public class TestStylesheetOverwrite extends JavadocTester {
"pkg");
checkExit(Exit.OK);
checkOutput("stylesheet.css", true, "Javadoc style sheet");
checkOutput("resource-files/stylesheet.css", true, "Javadoc style sheet");
}
void createTestClass(Path srcDir) throws Exception {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
@ -141,11 +141,11 @@ public class TestTerminology extends JavadocTester {
"p");
checkExit(Exit.OK);
checkOutput("search.js", sv.compareTo(SourceVersion.RELEASE_16) < 0,
checkOutput("script-files/search.js", sv.compareTo(SourceVersion.RELEASE_16) < 0,
"""
types: "Types","""
);
checkOutput("search.js", sv.compareTo(SourceVersion.RELEASE_16) >= 0,
checkOutput("script-files/search.js", sv.compareTo(SourceVersion.RELEASE_16) >= 0,
"""
types: "Classes and Interfaces","""
);

View File

@ -196,17 +196,11 @@ class APITest {
"allclasses-index.html",
"allpackages-index.html",
"constant-values.html",
"copy.svg",
"deprecated-list.html",
"help-doc.html",
"index-all.html",
"index.html",
"link.svg",
"script-dir/jquery-3.6.1.min.js",
"script-dir/jquery-ui.min.js",
"script-dir/jquery-ui.min.css",
"search.html",
"search-page.js",
"member-search-index.js",
"module-search-index.js",
"overview-tree.html",
@ -215,23 +209,32 @@ class APITest {
"pkg/C.html",
"pkg/package-summary.html",
"pkg/package-tree.html",
"resources/glass.png",
"resources/x.png",
"script.js",
"search.js",
"stylesheet.css",
"resource-files/copy.svg",
"resource-files/glass.png",
"resource-files/jquery-ui.min.css",
"resource-files/link.svg",
"resource-files/stylesheet.css",
"resource-files/x.png",
"script-files/jquery-3.6.1.min.js",
"script-files/jquery-ui.min.js",
"script-files/script.js",
"script-files/search.js",
"script-files/search-page.js",
"tag-search-index.js",
"type-search-index.js"
));
protected static Set<String> noIndexFiles = standardExpectFiles.stream()
.filter(s -> !s.startsWith("script-dir")
&& !s.startsWith("resources")
&& !s.endsWith("-search-index.js")
.filter(s ->
!s.endsWith("-search-index.js")
&& !s.equals("index-all.html")
&& !s.equals("search.js")
&& !s.equals("resource-files/glass.png")
&& !s.equals("resource-files/jquery-ui.min.css")
&& !s.equals("resource-files/x.png")
&& !s.startsWith("script-files/jquery-")
&& !s.equals("script-files/search.js")
&& !s.equals("script-files/search-page.js")
&& !s.equals("search.html")
&& !s.equals("search-page.js")
&& !s.equals("allclasses-index.html")
&& !s.equals("allpackages-index.html")
&& !s.equals("system-properties.html"))