Skip to content

Commit

Permalink
Refine links in spring-boot-dependencies
Browse files Browse the repository at this point in the history
Add support for a root name and change `reference` to `docs`.

See gh-39779
  • Loading branch information
philwebb committed Mar 9, 2024
1 parent 7a41750 commit 8b4f411
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void library(String name, String version, Action<LibraryHandler> action)
: null;
addLibrary(new Library(name, libraryHandler.calendarName, libraryVersion, libraryHandler.groups,
libraryHandler.prohibitedVersions, libraryHandler.considerSnapshots, versionAlignment,
libraryHandler.links));
libraryHandler.linkRootName, libraryHandler.links));
}

public void effectiveBomArtifact() {
Expand Down Expand Up @@ -232,6 +232,8 @@ public static class LibraryHandler {

private AlignWithVersionHandler alignWithVersion;

private String linkRootName;

private final Map<String, Function<LibraryVersion, String>> links = new HashMap<>();

@Inject
Expand Down Expand Up @@ -271,8 +273,13 @@ public void alignWithVersion(Action<AlignWithVersionHandler> action) {
}

public void links(Action<LinksHandler> action) {
links(null, action);
}

public void links(String linkRootName, Action<LinksHandler> action) {
LinksHandler handler = new LinksHandler();
action.execute(handler);
this.linkRootName = linkRootName;
this.links.putAll(handler.links);
}

Expand Down Expand Up @@ -431,20 +438,20 @@ public void github(Function<LibraryVersion, String> linkFactory) {
add("github", linkFactory);
}

public void javadoc(String linkTemplate) {
javadoc(asFactory(linkTemplate));
public void docs(String linkTemplate) {
docs(asFactory(linkTemplate));
}

public void javadoc(Function<LibraryVersion, String> linkFactory) {
add("javadoc", linkFactory);
public void docs(Function<LibraryVersion, String> linkFactory) {
add("docs", linkFactory);
}

public void reference(String linkTemplate) {
reference(asFactory(linkTemplate));
public void javadoc(String linkTemplate) {
javadoc(asFactory(linkTemplate));
}

public void reference(Function<LibraryVersion, String> linkFactory) {
add("reference", linkFactory);
public void javadoc(Function<LibraryVersion, String> linkFactory) {
add("javadoc", linkFactory);
}

public void releaseNotes(String linkTemplate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class Library {

private final VersionAlignment versionAlignment;

private final String linkRootName;

private final Map<String, Function<LibraryVersion, String>> links;

/**
Expand All @@ -75,11 +77,13 @@ public class Library {
* @param prohibitedVersions version of the library that are prohibited
* @param considerSnapshots whether to consider snapshots
* @param versionAlignment version alignment, if any, for the library
* @param linkRootName the root name to use when generating link variable or
* {@code null} to generate one based on the library {@code name}
* @param links a list of HTTP links relevant to the library
*/
public Library(String name, String calendarName, LibraryVersion version, List<Group> groups,
List<ProhibitedVersion> prohibitedVersions, boolean considerSnapshots, VersionAlignment versionAlignment,
Map<String, Function<LibraryVersion, String>> links) {
String linkRootName, Map<String, Function<LibraryVersion, String>> links) {
this.name = name;
this.calendarName = (calendarName != null) ? calendarName : name;
this.version = version;
Expand All @@ -89,6 +93,7 @@ public Library(String name, String calendarName, LibraryVersion version, List<Gr
this.prohibitedVersions = prohibitedVersions;
this.considerSnapshots = considerSnapshots;
this.versionAlignment = versionAlignment;
this.linkRootName = linkRootName;
this.links = Collections.unmodifiableMap(links);
}

Expand Down Expand Up @@ -124,6 +129,10 @@ public VersionAlignment getVersionAlignment() {
return this.versionAlignment;
}

public String getLinkRootName() {
return this.linkRootName;
}

public Map<String, String> getLinks() {
Map<String, String> links = new TreeMap<>();
this.links.forEach((name, linkFactory) -> links.put(name, linkFactory.apply(this.version)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated() throws IOExcepti
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
.apply(new Upgrade(new Library("ActiveMQ", null, new LibraryVersion(DependencyVersion.parse("5.15.11")),
null, null, false, null, Collections.emptyMap()), DependencyVersion.parse("5.16")));
null, null, false, null, null, Collections.emptyMap()), DependencyVersion.parse("5.16")));
String bomContents = Files.readString(bom.toPath());
assertThat(bomContents).hasSize(originalContents.length() - 3);
}
Expand All @@ -67,7 +67,7 @@ void whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdat
FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
new UpgradeApplicator(bom.toPath(), gradleProperties.toPath())
.apply(new Upgrade(new Library("Kotlin", null, new LibraryVersion(DependencyVersion.parse("1.3.70")), null,
null, false, null, Collections.emptyMap()), DependencyVersion.parse("1.4")));
null, false, null, null, Collections.emptyMap()), DependencyVersion.parse("1.4")));
Properties properties = new Properties();
try (InputStream in = new FileInputStream(gradleProperties)) {
properties.load(in);
Expand Down
Loading

0 comments on commit 8b4f411

Please sign in to comment.