Merge branch '3.4.x'
Closes gh-44882
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
package org.springframework.boot.build.bom;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -40,9 +42,12 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.boot.build.bom.Library.Group;
|
||||
import org.springframework.boot.build.bom.Library.Link;
|
||||
import org.springframework.boot.build.bom.Library.Module;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.Bom;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.Id;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.JavadocLink;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.Links;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.ResolvedLibrary;
|
||||
|
||||
/**
|
||||
@@ -85,15 +90,23 @@ class BomResolver {
|
||||
imports.add(bom);
|
||||
}
|
||||
}
|
||||
List<JavadocLink> javadocLinks = javadocLinksOf(library).stream()
|
||||
.map((link) -> new JavadocLink(URI.create(link.url(library)), link.packages()))
|
||||
.toList();
|
||||
ResolvedLibrary resolvedLibrary = new ResolvedLibrary(library.getName(),
|
||||
library.getVersion().getVersion().toString(), library.getVersionProperty(), managedDependencies,
|
||||
imports);
|
||||
imports, new Links(javadocLinks));
|
||||
libraries.add(resolvedLibrary);
|
||||
}
|
||||
String[] idComponents = bomExtension.getId().split(":");
|
||||
return new ResolvedBom(new Id(idComponents[0], idComponents[1], idComponents[2]), libraries);
|
||||
}
|
||||
|
||||
private List<Link> javadocLinksOf(Library library) {
|
||||
List<Link> javadocLinks = library.getLinks("javadoc");
|
||||
return (javadocLinks != null) ? javadocLinks : Collections.emptyList();
|
||||
}
|
||||
|
||||
Bom resolveMavenBom(String coordinates) {
|
||||
return bomFrom(resolveBom(coordinates));
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public abstract class CreateResolvedBom extends DefaultTask {
|
||||
public abstract RegularFileProperty getOutputFile();
|
||||
|
||||
@TaskAction
|
||||
void describeDependencyManagement() throws IOException {
|
||||
ResolvedBom dependencyManagement = this.bomResolver.resolve(this.bomExtension);
|
||||
void createResolvedBom() throws IOException {
|
||||
ResolvedBom resolvedBom = this.bomResolver.resolve(this.bomExtension);
|
||||
try (FileWriter writer = new FileWriter(getOutputFile().get().getAsFile())) {
|
||||
dependencyManagement.writeTo(writer);
|
||||
resolvedBom.writeTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -66,7 +67,7 @@ public record ResolvedBom(Id id, List<ResolvedLibrary> libraries) {
|
||||
}
|
||||
|
||||
public record ResolvedLibrary(String name, String version, String versionProperty, List<Id> managedDependencies,
|
||||
List<Bom> importedBoms) {
|
||||
List<Bom> importedBoms, Links links) {
|
||||
|
||||
}
|
||||
|
||||
@@ -109,4 +110,12 @@ public record ResolvedBom(Id id, List<ResolvedLibrary> libraries) {
|
||||
|
||||
}
|
||||
|
||||
public record Links(List<JavadocLink> javadoc) {
|
||||
|
||||
}
|
||||
|
||||
public record JavadocLink(URI uri, List<String> packages) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.docs;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.external.javadoc.StandardJavadocDocletOptions;
|
||||
|
||||
import org.springframework.boot.build.bom.ResolvedBom;
|
||||
import org.springframework.boot.build.bom.ResolvedBom.JavadocLink;
|
||||
|
||||
/**
|
||||
* An {@link Action} to configure the links option of a {@link Javadoc} task.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConfigureJavadocLinks implements Action<Javadoc> {
|
||||
|
||||
private final FileCollection resolvedBoms;
|
||||
|
||||
private final Collection<String> includedLibraries;
|
||||
|
||||
public ConfigureJavadocLinks(FileCollection resolvedBoms, Collection<String> includedLibraries) {
|
||||
this.resolvedBoms = resolvedBoms;
|
||||
this.includedLibraries = includedLibraries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Javadoc javadoc) {
|
||||
javadoc.options((options) -> {
|
||||
if (options instanceof StandardJavadocDocletOptions standardOptions) {
|
||||
configureLinks(standardOptions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void configureLinks(StandardJavadocDocletOptions options) {
|
||||
ResolvedBom resolvedBom = ResolvedBom.readFrom(this.resolvedBoms.getSingleFile());
|
||||
List<String> links = new ArrayList<>();
|
||||
links.add("https://docs.oracle.com/en/java/javase/17/docs/api/");
|
||||
links.add("https://jakarta.ee/specifications/platform/9/apidocs/");
|
||||
resolvedBom.libraries()
|
||||
.stream()
|
||||
.filter((candidate) -> this.includedLibraries.contains(candidate.name()))
|
||||
.flatMap((library) -> library.links().javadoc().stream())
|
||||
.map(JavadocLink::uri)
|
||||
.map(URI::toString)
|
||||
.forEach(links::add);
|
||||
options.setLinks(links);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user