diff --git a/make/Main.gmk b/make/Main.gmk index 22efccb8d7e..f054a89fb95 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -1053,6 +1053,9 @@ else # All modules include the main license files from java.base. $(JMOD_TARGETS): java.base-copy + # jdk.javadoc uses an internal copy of the main license files from java.base. + jdk.javadoc-copy: java.base-copy + zip-security: $(filter jdk.crypto%, $(JAVA_TARGETS)) ifeq ($(ENABLE_GENERATE_CLASSLIST), true) diff --git a/make/modules/jdk.javadoc/Copy.gmk b/make/modules/jdk.javadoc/Copy.gmk new file mode 100644 index 00000000000..031b4a91d33 --- /dev/null +++ b/make/modules/jdk.javadoc/Copy.gmk @@ -0,0 +1,47 @@ +# +# Copyright (c) 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 +# 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. +# + +include CopyCommon.gmk + +JDK_JAVADOC_DIR := $(JDK_OUTPUTDIR)/modules/jdk.javadoc +JDK_JAVADOC_DOCLET_RESOURCE_DIR := $(JDK_JAVADOC_DIR)/jdk/javadoc/internal/doclets/formats/html/resources + +################################################################################ + +$(eval $(call SetupCopyFiles, COPY_JAVADOC_MODULE_LEGAL_RESOURCES, \ + DEST := $(JDK_JAVADOC_DOCLET_RESOURCE_DIR)/legal, \ + FILES := $(wildcard $(MODULE_SRC)/share/legal/*.md), \ +)) +TARGETS += $(COPY_JAVADOC_MODULE_LEGAL_RESOURCES) + +################################################################################ + +$(eval $(call SetupCopyFiles, COPY_JAVADOC_COMMON_LEGAL_RESOURCES, \ + DEST := $(JDK_JAVADOC_DOCLET_RESOURCE_DIR)/legal, \ + FILES := $(wildcard $(COMMON_LEGAL_DST_DIR)/*), \ +)) +TARGETS += $(COPY_JAVADOC_COMMON_LEGAL_RESOURCES) + +################################################################################ diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java index 75e60be8cf3..93fdbad6eb5 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDoclet.java @@ -27,6 +27,7 @@ package jdk.javadoc.internal.doclets.formats.html; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -342,8 +343,19 @@ public class HtmlDoclet extends AbstractDoclet { String legalNotices = configuration.getOptions().legalNotices(); switch (legalNotices) { case "", "default" -> { - Path javaHome = Path.of(System.getProperty("java.home")); - legalNoticesDir = javaHome.resolve("legal").resolve(getClass().getModule().getName()); + // use a known resource as a stand-in, because we cannot get the URL for a resources directory + var url = HtmlDoclet.class.getResource( + DocPaths.RESOURCES.resolve(DocPaths.LEGAL).resolve(DocPaths.JQUERY_MD).getPath()); + if (url != null) { + try { + legalNoticesDir = Path.of(url.toURI()).getParent(); + } catch (URISyntaxException e) { + // should not happen when running javadoc from a system image + return; + } + } else { + return; + } } case "none" -> { diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java index 9388566ea3d..4f3c10df887 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPaths.java @@ -112,6 +112,9 @@ public class DocPaths { /** The name of the default jQuery UI javascript file. */ public static final DocPath JQUERY_UI_JS = DocPath.create("jquery-ui.min.js"); + /** The name of the default jQuery file for legal notices. */ + public static final DocPath JQUERY_MD = DocPath.create("jquery.md"); + /** The name of the directory for legal files. */ public static final DocPath LEGAL = DocPath.create("legal"); diff --git a/test/langtools/jdk/javadoc/doclet/testLegalNotices/TestLegalNotices.java b/test/langtools/jdk/javadoc/doclet/testLegalNotices/TestLegalNotices.java index cf77d793512..148accdbfd4 100644 --- a/test/langtools/jdk/javadoc/doclet/testLegalNotices/TestLegalNotices.java +++ b/test/langtools/jdk/javadoc/doclet/testLegalNotices/TestLegalNotices.java @@ -112,6 +112,18 @@ public class TestLegalNotices extends JavadocTester { if (foundFiles.equals(expectFiles)) { passed("Found all expected files"); } + + // See JDK-8306980 + for (Path p : foundFiles) { + // Somewhat unusually, the dominant test is that the string "Please see..." + // does _not_ appear in the generated legal-notice files. + // The string is used by jlink when creating the legal files for a module + // on platforms that do not support symbolic links. + // The test verifies that javadoc is not using any such files. + checkOutput("legal/" + p, false, + "Please see"); + } + } Set getExpectFiles(OptionKind optionKind, IndexKind indexKind, Path legal) throws IOException { diff --git a/test/langtools/jdk/javadoc/doclet/testSnippetTag/TestSnippetMarkup.java b/test/langtools/jdk/javadoc/doclet/testSnippetTag/TestSnippetMarkup.java index ed9b1dc7cb5..c7936bcb7e2 100644 --- a/test/langtools/jdk/javadoc/doclet/testSnippetTag/TestSnippetMarkup.java +++ b/test/langtools/jdk/javadoc/doclet/testSnippetTag/TestSnippetMarkup.java @@ -839,6 +839,11 @@ First line // @highlight : return delegate.getJavaFileObjects(files); } + @Override + public Iterable getJavaFileObjects(Path... files) { + return delegate.getJavaFileObjects(files); + } + @Override public Iterable getJavaFileObjectsFromStrings(Iterable names) { return delegate.getJavaFileObjectsFromStrings(names); diff --git a/test/langtools/jdk/javadoc/tool/api/basic/GetTask_FileManagerTest.java b/test/langtools/jdk/javadoc/tool/api/basic/GetTask_FileManagerTest.java index 46925df338c..e98638a3aed 100644 --- a/test/langtools/jdk/javadoc/tool/api/basic/GetTask_FileManagerTest.java +++ b/test/langtools/jdk/javadoc/tool/api/basic/GetTask_FileManagerTest.java @@ -132,6 +132,11 @@ public class GetTask_FileManagerTest extends APITest { return fileManager.getJavaFileObjects(files); } + @Override + public Iterable getJavaFileObjects(Path... files) { + return fileManager.getJavaFileObjects(files); + } + @Override public Iterable getJavaFileObjectsFromStrings(Iterable names) { return fileManager.getJavaFileObjectsFromStrings(names);