Skip to content

Commit

Permalink
Polish "Update reference links in HELP.md"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Jul 29, 2024
1 parent 0508a9e commit 880c59d
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,17 @@ public void customize(HelpDocument document) {
document.gettingStarted()
.addReferenceDocLink(generateReferenceGuideUrl(), "Spring Boot Gradle Plugin Reference Guide");
document.gettingStarted()
.addReferenceDocLink(String.format(
generateReferenceGuideUrl() + (shouldChangeUrl() ? "/packaging-oci-image.html" : "#build-image"),
this.springBootVersion), "Create an OCI image");
.addReferenceDocLink(
String
.format(generateReferenceGuideUrl() + (SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion)
? "/packaging-oci-image.html" : "#build-image"), this.springBootVersion),
"Create an OCI image");
}

private String generateReferenceGuideUrl() {
String baseUrlFormat = SPRING_BOOT_DOCS_URL
+ (shouldChangeUrl() ? "/%s/gradle-plugin" : "/%s/gradle-plugin/reference/html/");
return String.format(baseUrlFormat, this.springBootVersion);
}

private boolean shouldChangeUrl() {

return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion);
String baseUrlFormat = SPRING_BOOT_DOCS_URL + (SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion)
? "/%s/gradle-plugin" : "/docs/%s/gradle-plugin/reference/html/");
return baseUrlFormat.formatted(this.springBootVersion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ public void customize(HelpDocument document) {
.addReferenceDocLink("https://maven.apache.org/guides/index.html", "Official Apache Maven documentation");
String referenceGuideUrl = generateReferenceGuideUrl();
document.gettingStarted().addReferenceDocLink(referenceGuideUrl, "Spring Boot Maven Plugin Reference Guide");
String buildImageSection = referenceGuideUrl + (shouldChangeUrl() ? "/build-image.html" : "#build-image");
String buildImageSection = referenceGuideUrl
+ (SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion) ? "/build-image.html" : "#build-image");
document.gettingStarted().addReferenceDocLink(buildImageSection, "Create an OCI image");
}

private String generateReferenceGuideUrl() {
String baseUrlFormat = SPRING_BOOT_DOCS_URL
+ (shouldChangeUrl() ? "/%s/maven-plugin" : "/docs/%s/maven-plugin/reference/html/");
return String.format(baseUrlFormat, this.springBootVersion);
}

private boolean shouldChangeUrl() {

return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion);
String baseUrlFormat = SPRING_BOOT_DOCS_URL + (SPRING_BOOT_3_3_0_OR_LATER.match(this.springBootVersion)
? "/%s/maven-plugin" : "/docs/%s/maven-plugin/reference/html/");
return baseUrlFormat.formatted(this.springBootVersion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class GraalVmHelpDocumentCustomizer implements HelpDocumentCustomizer {
@Override
public void customize(HelpDocument document) {
document.gettingStarted()
.addReferenceDocLink(String.format(shouldChangeUrl()
.addReferenceDocLink(String.format(SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion)
? "https://docs.spring.io/spring-boot/%s/reference/packaging/native-image/introducing-graalvm-native-images.html"
: "https://docs.spring.io/spring-boot/docs/%s/reference/html/native-image.html#native-image",
this.platformVersion), "GraalVM Native Image Support");
boolean mavenBuild = this.build instanceof MavenBuild;
boolean gradleBuild = this.build instanceof GradleBuild;
String url = shouldChangeUrl()
String url = SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion)
? String.format("https://docs.spring.io/spring-boot/%s/how-to/aot.html", this.platformVersion)
: String.format("https://docs.spring.io/spring-boot/docs/%s/%s/reference/htmlsingle/#aot",
this.platformVersion, (mavenBuild) ? "maven-plugin" : "gradle-plugin");
Expand Down Expand Up @@ -105,9 +105,4 @@ private Stream<Dependency> buildDependencies() {
.filter(Objects::nonNull);
}

private boolean shouldChangeUrl() {

return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,12 @@ public void customize(HelpDocument document) {
.addReferenceDocLink("https://docs.micrometer.io/tracing/reference/index.html",
"Distributed Tracing Reference Guide");
document.gettingStarted()
.addReferenceDocLink(String.format(shouldChangeUrl()
.addReferenceDocLink(String.format(SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion)
? "https://docs.spring.io/spring-boot/%s/reference/actuator/tracing.html"
: "https://docs.spring.io/spring-boot/docs/%s/reference/html/actuator.html#actuator.micrometer-tracing.getting-started",
this.platformVersion), "Getting Started with Distributed Tracing");

}
}

private boolean shouldChangeUrl() {

return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,22 @@ class TestContainersHelpDocumentCustomizer implements HelpDocumentCustomizer {

@Override
public void customize(HelpDocument document) {
String referenceDocUrl = (shouldChangeUrl()
String referenceDocUrl = (SPRING_BOOT_3_3_0_OR_LATER.match(this.description.getPlatformVersion())
? "https://docs.spring.io/spring-boot/%s/reference/testing/testcontainers.html#testing.testcontainers"
: "https://docs.spring.io/spring-boot/docs/%s/reference/html/features.html#features.testing.testcontainers")
.formatted(this.description.getPlatformVersion());
document.gettingStarted().addReferenceDocLink(referenceDocUrl, "Spring Boot Testcontainers support");

Map<String, Object> model = new HashMap<>();
List<DockerService> dockerServices = this.serviceConnections.values()
.map(ServiceConnection::dockerService)
.toList();
model.put("services", dockerServices);
model.put("testcontainersAtDevelopmentTimeLink", (shouldChangeUrl()
? "https://docs.spring.io/spring-boot/%s/reference/features/dev-services.html#features.dev-services.testcontainers"
: "https://docs.spring.io/spring-boot/docs/%s/reference/html/features.html#features.testcontainers")
model.put("testcontainersAtDevelopmentTimeLink", (SPRING_BOOT_3_3_0_OR_LATER
.match(this.description.getPlatformVersion())
? "https://docs.spring.io/spring-boot/%s/reference/features/dev-services.html#features.dev-services.testcontainers"
: "https://docs.spring.io/spring-boot/docs/%s/reference/html/features.html#features.testing.testcontainers.at-development-time")
.formatted(this.description.getPlatformVersion()));
document.addSection("testcontainers", model);
}

private boolean shouldChangeUrl() {

return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.description.getPlatformVersion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
*
* @author Jenn Strater
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class GradleBuildSystemHelpDocumentCustomizerTests extends AbstractExtensionTests {

private static final String OLD_SPRING_BOOT_VERSION = "3.2.0";

private static final String SPRING_BOOT_VERSION = "3.3.0";

@Test
Expand All @@ -43,11 +46,17 @@ void linksAddedToHelpDocumentForGradleBuild() {
}

@Test
void linksNotAddedToHelpDocumentForMavenBuild() {
assertHelpDocument("maven-build", SPRING_BOOT_VERSION).doesNotContain(
void linksAddedToHelpDocumentForGradleBuildWithOldSpringBootVersion() {
assertHelpDocument("gradle-build", OLD_SPRING_BOOT_VERSION).contains(
"* [Official Gradle documentation](https://docs.gradle.org)",
"* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)",
"* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.0/gradle-plugin/reference/html/)");
"* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.0/gradle-plugin/reference/html/)",
"* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.2.0/gradle-plugin/reference/html/#build-image)");
}

@Test
void linksNotAddedToHelpDocumentForMavenBuild() {
assertHelpDocument("maven-build", SPRING_BOOT_VERSION).noneMatch((line) -> line.contains("Gradle"));
}

private ListAssert<String> assertHelpDocument(String type, String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
*
* @author Jenn Strater
* @author Andy Wilkinson
* @author Moritz Halbritter
*/
class MavenBuildSystemHelpDocumentCustomizerTests extends AbstractExtensionTests {

private static final String SPRING_BOOT_VERSION = "3.3.0";

private static final String OLD_SPRING_BOOT_VERSION = "3.2.0";

@Test
void linksAddedToHelpDocumentForMavenBuild() {
assertHelpDocument("maven-build", SPRING_BOOT_VERSION).contains(
Expand All @@ -42,10 +45,16 @@ void linksAddedToHelpDocumentForMavenBuild() {
}

@Test
void linksNotAddedToHelpDocumentForGradleBuild() {
assertHelpDocument("gradle-build", SPRING_BOOT_VERSION).doesNotContain(
void linksAddedToHelpDocumentForMavenBuildWithOldSpringBootVersion() {
assertHelpDocument("maven-build", OLD_SPRING_BOOT_VERSION).contains(
"* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)",
"* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.0/maven-plugin/)");
"* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.0/maven-plugin/reference/html/)",
"* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.2.0/maven-plugin/reference/html/#build-image)");
}

@Test
void linksNotAddedToHelpDocumentForGradleBuild() {
assertHelpDocument("gradle-build", SPRING_BOOT_VERSION).noneMatch((line) -> line.contains("Maven"));
}

private ListAssert<String> assertHelpDocument(String type, String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
*/
class GraalVmHelpDocumentCustomizerTests extends AbstractExtensionTests {

private static final String SPRING_BOOT_VERSION = "3.3.0";

private static final String OLD_SPRING_BOOT_VERSION = "3.2.0";

@Autowired
private MustacheTemplateRenderer templateRenderer;

@Test
void mavenBuildAndGradleAddLinkToMavenAotPlugin() {
void mavenBuildAddLinkToMavenAotPlugin() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.3.0"));
description.setPlatformVersion(Version.parse(SPRING_BOOT_VERSION));
HelpDocument document = customize(description, new MavenBuild());
assertThat(document.gettingStarted().additionalLinks().getItems()).singleElement().satisfies((link) -> {
assertThat(link.getDescription()).isEqualTo("Configure AOT settings in Build Plugin");
Expand All @@ -57,9 +61,9 @@ void mavenBuildAndGradleAddLinkToMavenAotPlugin() {
}

@Test
void mavenBuildAddLinkToMavenAotPlugin() {
void mavenBuildAddLinkToMavenAotPluginWithOldSpringBootVersion() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.0"));
description.setPlatformVersion(Version.parse(OLD_SPRING_BOOT_VERSION));
HelpDocument document = customize(description, new MavenBuild());
assertThat(document.gettingStarted().additionalLinks().getItems()).singleElement().satisfies((link) -> {
assertThat(link.getDescription()).isEqualTo("Configure AOT settings in Build Plugin");
Expand All @@ -71,7 +75,18 @@ void mavenBuildAddLinkToMavenAotPlugin() {
@Test
void gradleBuildAddLinkToGradleAotPlugin() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.0"));
description.setPlatformVersion(Version.parse(SPRING_BOOT_VERSION));
HelpDocument document = customize(description, new GradleBuild());
assertThat(document.gettingStarted().additionalLinks().getItems()).singleElement().satisfies((link) -> {
assertThat(link.getDescription()).isEqualTo("Configure AOT settings in Build Plugin");
assertThat(link.getHref()).isEqualTo("https://docs.spring.io/spring-boot/3.3.0/how-to/aot.html");
});
}

@Test
void gradleBuildAddLinkToGradleAotPluginWithOldSpringBootVersion() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse(OLD_SPRING_BOOT_VERSION));
HelpDocument document = customize(description, new GradleBuild());
assertThat(document.gettingStarted().additionalLinks().getItems()).singleElement().satisfies((link) -> {
assertThat(link.getDescription()).isEqualTo("Configure AOT settings in Build Plugin");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2012-2024 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 io.spring.start.site.extension.dependency.observability;

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.assertj.core.api.ListAssert;
import org.junit.jupiter.api.Test;

/**
* Tests for {@link ObservabilityHelpDocumentCustomizer}.
*
* @author Moritz Halbritter
*/
class ObservabilityHelpDocumentCustomizerTests extends AbstractExtensionTests {

private static final String OLD_SPRING_BOOT_VERSION = "3.2.0";

private static final String SPRING_BOOT_VERSION = "3.3.0";

@Test
void linksAddedToHelpDocumentForGradleBuild() {
assertHelpDocument(SPRING_BOOT_VERSION, "distributed-tracing").contains(
"* [Distributed Tracing Reference Guide](https://docs.micrometer.io/tracing/reference/index.html)",
"* [Getting Started with Distributed Tracing](https://docs.spring.io/spring-boot/3.3.0/reference/actuator/tracing.html)");
}

@Test
void linksAddedToHelpDocumentForGradleBuildWithOldSpringBootVersion() {
assertHelpDocument(OLD_SPRING_BOOT_VERSION, "distributed-tracing").contains(
"* [Distributed Tracing Reference Guide](https://docs.micrometer.io/tracing/reference/index.html)",
"* [Getting Started with Distributed Tracing](https://docs.spring.io/spring-boot/docs/3.2.0/reference/html/actuator.html#actuator.micrometer-tracing.getting-started)");
}

@Test
void linksNotAddedToHelpDocumentForBuildWithoutTracing() {
assertHelpDocument(SPRING_BOOT_VERSION).noneMatch((line) -> line.contains("Tracing"));
}

private ListAssert<String> assertHelpDocument(String version, String... dependencies) {
ProjectRequest request = createProjectRequest(dependencies);
request.setType("gradle-build");
request.setBootVersion(version);
ProjectStructure project = generateProject(request);
return new TextAssert(project.getProjectDirectory().resolve("HELP.md")).lines();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,19 @@ fun contextLoads() {
@Test
void shouldAddHelpSection() {
assertHelpDocument(SPRING_BOOT_VERSION_3_3, "testcontainers", "data-mongodb", "postgresql").contains(
"https://docs.spring.io/spring-boot/docs/3.3.0/reference/html/features.html#features.testing.testcontainers")
"https://docs.spring.io/spring-boot/3.3.0/reference/testing/testcontainers.html#testing.testcontainers")
.contains(
"https://docs.spring.io/spring-boot/docs/3.3.0/reference/html/features.html#features.testing.testcontainers.at-development-time")
"https://docs.spring.io/spring-boot/3.3.0/reference/features/dev-services.html#features.dev-services.testcontainers")
.contains("mongo:latest")
.contains("postgres:latest");
}

@Test
void shouldAddHelpSectionWithOldSpringBoot() {
assertHelpDocument(SPRING_BOOT_VERSION_3_2, "testcontainers", "data-mongodb", "postgresql").contains(
"https://docs.spring.io/spring-boot/docs/3.2.0/reference/html/features.html#features.testing.testcontainers")
.contains(
"https://docs.spring.io/spring-boot/docs/3.2.0/reference/html/features.html#features.testing.testcontainers.at-development-time")
.contains("mongo:latest")
.contains("postgres:latest");
}
Expand Down

0 comments on commit 880c59d

Please sign in to comment.