8306980: Generated docs should contain correct Legal Documents

Reviewed-by: ihse, mchung
This commit is contained in:
Jonathan Gibbons 2023-10-31 22:03:35 +00:00
parent 11394828b3
commit b3fec6b5f3
7 changed files with 89 additions and 2 deletions

View File

@ -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)

View File

@ -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)
################################################################################

View File

@ -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" -> {

View File

@ -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");

View File

@ -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<Path> getExpectFiles(OptionKind optionKind, IndexKind indexKind, Path legal) throws IOException {

View File

@ -839,6 +839,11 @@ First line // @highlight :
return delegate.getJavaFileObjects(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... files) {
return delegate.getJavaFileObjects(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
return delegate.getJavaFileObjectsFromStrings(names);

View File

@ -132,6 +132,11 @@ public class GetTask_FileManagerTest extends APITest {
return fileManager.getJavaFileObjects(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... files) {
return fileManager.getJavaFileObjects(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
return fileManager.getJavaFileObjectsFromStrings(names);