mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-19 19:47:08 +08:00
Fix generation of links with {bootVersion}
This commit makes sure to use the currently selected Spring Boot version, rather than the default one. Closes gh-1306
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -42,12 +42,13 @@ public class RequestedDependenciesHelpDocumentCustomizer implements HelpDocument
|
||||
|
||||
private final InitializrMetadata metadata;
|
||||
|
||||
private final String defaultPlatformVersion;
|
||||
private final String platformVersion;
|
||||
|
||||
public RequestedDependenciesHelpDocumentCustomizer(ProjectDescription description, InitializrMetadata metadata) {
|
||||
this.description = description;
|
||||
this.metadata = metadata;
|
||||
this.defaultPlatformVersion = metadata.getBootVersions().getDefault().getId();
|
||||
this.platformVersion = (description.getPlatformVersion() != null) ? description.getPlatformVersion().toString()
|
||||
: metadata.getBootVersions().getDefault().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +86,7 @@ public class RequestedDependenciesHelpDocumentCustomizer implements HelpDocument
|
||||
String description = (link.getDescription() != null) ? link.getDescription()
|
||||
: defaultDescription.apply(links);
|
||||
if (description != null) {
|
||||
String url = link.getHref().replace("{bootVersion}", this.defaultPlatformVersion);
|
||||
String url = link.getHref().replace("{bootVersion}", this.platformVersion);
|
||||
section.get().addItem(new GettingStartedSection.Link(url, description));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -22,6 +22,7 @@ import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
|
||||
import io.spring.initializr.generator.io.text.BulletedSection;
|
||||
import io.spring.initializr.generator.project.MutableProjectDescription;
|
||||
import io.spring.initializr.generator.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.Link;
|
||||
@@ -40,7 +41,7 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
private final InitializrMetadataTestBuilder metadataBuilder = InitializrMetadataTestBuilder.withDefaults();
|
||||
|
||||
@Test
|
||||
void dependencyWithReferenceDocLink() {
|
||||
void dependencyWithReferenceDocLinkUseDefaultPlatformVersionIfNoneIsSet() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("reference", "https://example.com/{bootVersion}/doc", "Reference doc example"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
@@ -50,6 +51,17 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
"Reference doc example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithReferenceDocLinkUsePlatformVersion() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("reference", "https://example.com/{bootVersion}/doc", "Reference doc example"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
HelpDocument document = customizeHelp(Version.parse("2.4.10"), "example");
|
||||
assertThat(document.gettingStarted().isEmpty()).isFalse();
|
||||
assertSingleLink(document.gettingStarted().referenceDocs(), "https://example.com/2.4.10/doc",
|
||||
"Reference doc example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithReferenceDocLinkGetDependencyNameByDefault() {
|
||||
Dependency dependency = createDependency("example", Link.create("reference", "https://example.com/doc"));
|
||||
@@ -71,7 +83,7 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithGuideLink() {
|
||||
void dependencyWithGuideLinkUseDefaultPlatformVersionIfNoneIsSet() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("guide", "https://example.com/{bootVersion}/how-to", "How-to example"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
@@ -80,6 +92,16 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
assertSingleLink(document.gettingStarted().guides(), "https://example.com/2.4.1/how-to", "How-to example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithGuideLinkUsePlatformVersion() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("guide", "https://example.com/{bootVersion}/how-to", "How-to example"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
HelpDocument document = customizeHelp(Version.parse("2.4.9"), "example");
|
||||
assertThat(document.gettingStarted().isEmpty()).isFalse();
|
||||
assertSingleLink(document.gettingStarted().guides(), "https://example.com/2.4.9/how-to", "How-to example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithGuideLinkGetDependencyNameByDefault() {
|
||||
Dependency dependency = createDependency("example", Link.create("guide", "https://example.com/how-to"));
|
||||
@@ -101,7 +123,7 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithAdditionalLink() {
|
||||
void dependencyWithAdditionalLinkUseDefaultPlatformVersionIfNoneIsSet() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("something", "https://example.com/{bootVersion}/test", "Test App"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
@@ -110,6 +132,16 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
assertSingleLink(document.gettingStarted().additionalLinks(), "https://example.com/2.4.1/test", "Test App");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithAdditionalLinkUsePlatformVersion() {
|
||||
Dependency dependency = createDependency("example",
|
||||
Link.create("something", "https://example.com/{bootVersion}/test", "Test App"));
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
HelpDocument document = customizeHelp(Version.parse("2.4.9"), "example");
|
||||
assertThat(document.gettingStarted().isEmpty()).isFalse();
|
||||
assertSingleLink(document.gettingStarted().additionalLinks(), "https://example.com/2.4.9/test", "Test App");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyWithAdditionalLinkDoNotDependencyNameByDefault() {
|
||||
Dependency dependency = createDependency("example", Link.create("something", "https://example.com/test"));
|
||||
@@ -136,7 +168,14 @@ class RequestedDependenciesHelpDocumentCustomizerTests {
|
||||
}
|
||||
|
||||
private HelpDocument customizeHelp(String... requestedDependencies) {
|
||||
return customizeHelp(null, requestedDependencies);
|
||||
}
|
||||
|
||||
private HelpDocument customizeHelp(Version platformVersion, String... requestedDependencies) {
|
||||
MutableProjectDescription description = new MutableProjectDescription();
|
||||
if (platformVersion != null) {
|
||||
description.setPlatformVersion(platformVersion);
|
||||
}
|
||||
for (String requestedDependency : requestedDependencies) {
|
||||
description.addDependency(requestedDependency,
|
||||
mock(io.spring.initializr.generator.buildsystem.Dependency.class));
|
||||
|
||||
Reference in New Issue
Block a user