From 0508a9e1f008005ed837e80e38c857315751d3bc Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Sat, 27 Jul 2024 23:00:30 +0700 Subject: [PATCH 1/2] Update reference links in HELP.md See gh-1541 --- ...adleBuildSystemHelpDocumentCustomizer.java | 24 +++++++++++++++---- ...avenBuildSystemHelpDocumentCustomizer.java | 16 +++++++++++-- .../GraalVmHelpDocumentCustomizer.java | 20 ++++++++++++---- .../ObservabilityHelpDocumentCustomizer.java | 17 ++++++++++--- .../TestContainersHelpDocumentCustomizer.java | 20 ++++++++++++---- ...uildSystemHelpDocumentCustomizerTests.java | 4 ++-- ...uildSystemHelpDocumentCustomizerTests.java | 6 ++--- .../GraalVmHelpDocumentCustomizerTests.java | 11 +++++++++ 8 files changed, 95 insertions(+), 23 deletions(-) diff --git a/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java index 35052ee14b9..5134c12c687 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java @@ -20,6 +20,8 @@ import io.spring.initializr.generator.spring.documentation.HelpDocument; import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionParser; +import io.spring.initializr.generator.version.VersionRange; /** * A {@link HelpDocumentCustomizer} that adds reference links for Gradle. @@ -29,6 +31,10 @@ */ class GradleBuildSystemHelpDocumentCustomizer implements HelpDocumentCustomizer { + private static final String SPRING_BOOT_DOCS_URL = "https://docs.spring.io/spring-boot"; + + private static final VersionRange SPRING_BOOT_3_3_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0"); + private final Version springBootVersion; GradleBuildSystemHelpDocumentCustomizer(ProjectDescription description) { @@ -42,14 +48,22 @@ public void customize(HelpDocument document) { "Gradle Build Scans – insights for your project's build"); document.gettingStarted().addReferenceDocLink("https://docs.gradle.org", "Official Gradle documentation"); document.gettingStarted() - .addReferenceDocLink( - String.format("https://docs.spring.io/spring-boot/docs/%s/gradle-plugin/reference/html/", - this.springBootVersion), - "Spring Boot Gradle Plugin Reference Guide"); + .addReferenceDocLink(generateReferenceGuideUrl(), "Spring Boot Gradle Plugin Reference Guide"); document.gettingStarted() .addReferenceDocLink(String.format( - "https://docs.spring.io/spring-boot/docs/%s/gradle-plugin/reference/html/#build-image", + generateReferenceGuideUrl() + (shouldChangeUrl() ? "/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); + } + } diff --git a/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java index 3d8ef234871..1333d78b6f5 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java @@ -20,6 +20,8 @@ import io.spring.initializr.generator.spring.documentation.HelpDocument; import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionParser; +import io.spring.initializr.generator.version.VersionRange; /** * A {@link HelpDocumentCustomizer} that adds reference links for Apache Maven. @@ -29,6 +31,10 @@ */ class MavenBuildSystemHelpDocumentCustomizer implements HelpDocumentCustomizer { + private static final String SPRING_BOOT_DOCS_URL = "https://docs.spring.io/spring-boot"; + + private static final VersionRange SPRING_BOOT_3_3_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0"); + private final Version springBootVersion; MavenBuildSystemHelpDocumentCustomizer(ProjectDescription description) { @@ -41,13 +47,19 @@ 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 + "#build-image"; + String buildImageSection = referenceGuideUrl + (shouldChangeUrl() ? "/build-image.html" : "#build-image"); document.gettingStarted().addReferenceDocLink(buildImageSection, "Create an OCI image"); } private String generateReferenceGuideUrl() { - String baseUrlFormat = "https://docs.spring.io/spring-boot/docs/%s/maven-plugin/reference/html/"; + 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); + } + } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java index 685edb169b7..363f54b6478 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java @@ -28,6 +28,8 @@ import io.spring.initializr.generator.spring.documentation.HelpDocument; import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionParser; +import io.spring.initializr.generator.version.VersionRange; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; @@ -38,6 +40,8 @@ */ class GraalVmHelpDocumentCustomizer implements HelpDocumentCustomizer { + private static final VersionRange SPRING_BOOT_3_3_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0"); + private final InitializrMetadata metadata; private final ProjectDescription description; @@ -56,13 +60,16 @@ class GraalVmHelpDocumentCustomizer implements HelpDocumentCustomizer { @Override public void customize(HelpDocument document) { document.gettingStarted() - .addReferenceDocLink(String.format( - "https://docs.spring.io/spring-boot/docs/%s/reference/html/native-image.html#native-image", + .addReferenceDocLink(String.format(shouldChangeUrl() + ? "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 = String.format("https://docs.spring.io/spring-boot/docs/%s/%s/reference/htmlsingle/#aot", - this.platformVersion, (mavenBuild) ? "maven-plugin" : "gradle-plugin"); + String url = shouldChangeUrl() + ? 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"); document.gettingStarted().addAdditionalLink(url, "Configure AOT settings in Build Plugin"); Map model = new HashMap<>(); @@ -98,4 +105,9 @@ private Stream buildDependencies() { .filter(Objects::nonNull); } + private boolean shouldChangeUrl() { + + return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion); + } + } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java index a14175982aa..a5af92e7706 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java @@ -21,6 +21,8 @@ import io.spring.initializr.generator.spring.documentation.HelpDocument; import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; import io.spring.initializr.generator.version.Version; +import io.spring.initializr.generator.version.VersionParser; +import io.spring.initializr.generator.version.VersionRange; /** * {@link HelpDocumentCustomizer} implementation for Observability. @@ -29,6 +31,8 @@ */ public class ObservabilityHelpDocumentCustomizer implements HelpDocumentCustomizer { + private static final VersionRange SPRING_BOOT_3_3_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0"); + private final Version platformVersion; private final Build build; @@ -42,13 +46,20 @@ public ObservabilityHelpDocumentCustomizer(ProjectDescription description, Build public void customize(HelpDocument document) { if (this.build.dependencies().has("distributed-tracing")) { document.gettingStarted() - .addReferenceDocLink("https://micrometer.io/docs/tracing", "Distributed Tracing Reference Guide"); + .addReferenceDocLink("https://docs.micrometer.io/tracing/reference/index.html", + "Distributed Tracing Reference Guide"); document.gettingStarted() - .addReferenceDocLink(String.format( - "https://docs.spring.io/spring-boot/docs/%s/reference/html/actuator.html#actuator.micrometer-tracing.getting-started", + .addReferenceDocLink(String.format(shouldChangeUrl() + ? "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); + } + } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java index 91f34224247..41e3d689ce6 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java @@ -23,6 +23,8 @@ import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.spring.documentation.HelpDocument; import io.spring.initializr.generator.spring.documentation.HelpDocumentCustomizer; +import io.spring.initializr.generator.version.VersionParser; +import io.spring.initializr.generator.version.VersionRange; import io.spring.start.site.container.DockerService; import io.spring.start.site.container.ServiceConnections; import io.spring.start.site.container.ServiceConnections.ServiceConnection; @@ -35,6 +37,8 @@ */ class TestContainersHelpDocumentCustomizer implements HelpDocumentCustomizer { + private static final VersionRange SPRING_BOOT_3_3_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0"); + private final ProjectDescription description; private final ServiceConnections serviceConnections; @@ -46,7 +50,9 @@ class TestContainersHelpDocumentCustomizer implements HelpDocumentCustomizer { @Override public void customize(HelpDocument document) { - String referenceDocUrl = "https://docs.spring.io/spring-boot/docs/%s/reference/html/features.html#features.testing.testcontainers" + String referenceDocUrl = (shouldChangeUrl() + ? "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"); @@ -55,10 +61,16 @@ public void customize(HelpDocument document) { .map(ServiceConnection::dockerService) .toList(); model.put("services", dockerServices); - model.put("testcontainersAtDevelopmentTimeLink", - "https://docs.spring.io/spring-boot/docs/%s/reference/html/features.html#features.testing.testcontainers.at-development-time" - .formatted(this.description.getPlatformVersion())); + 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") + .formatted(this.description.getPlatformVersion())); document.addSection("testcontainers", model); } + private boolean shouldChangeUrl() { + + return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.description.getPlatformVersion()); + } + } diff --git a/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java index cefd3029969..74da64eb4d5 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java @@ -38,8 +38,8 @@ void linksAddedToHelpDocumentForGradleBuild() { assertHelpDocument("gradle-build", 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/)", - "* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.0/gradle-plugin/reference/html/#build-image)"); + "* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.0/gradle-plugin)", + "* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.0/gradle-plugin/packaging-oci-image.html)"); } @Test diff --git a/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java index 56a17532e5c..e4b43e87551 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java @@ -37,15 +37,15 @@ class MavenBuildSystemHelpDocumentCustomizerTests extends AbstractExtensionTests void linksAddedToHelpDocumentForMavenBuild() { assertHelpDocument("maven-build", 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/docs/3.3.0/maven-plugin/reference/html/)", - "* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.3.0/maven-plugin/reference/html/#build-image)"); + "* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.0/maven-plugin)", + "* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.0/maven-plugin/build-image.html)"); } @Test void linksNotAddedToHelpDocumentForGradleBuild() { assertHelpDocument("gradle-build", SPRING_BOOT_VERSION).doesNotContain( "* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)", - "* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.3.0/maven-plugin/)"); + "* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.0/maven-plugin/)"); } private ListAssert assertHelpDocument(String type, String version) { diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java index 78961c3b532..b6c4b94200f 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java @@ -45,6 +45,17 @@ class GraalVmHelpDocumentCustomizerTests extends AbstractExtensionTests { @Autowired private MustacheTemplateRenderer templateRenderer; + @Test + void mavenBuildAndGradleAddLinkToMavenAotPlugin() { + MutableProjectDescription description = new MutableProjectDescription(); + description.setPlatformVersion(Version.parse("3.3.0")); + HelpDocument document = customize(description, new MavenBuild()); + 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 mavenBuildAddLinkToMavenAotPlugin() { MutableProjectDescription description = new MutableProjectDescription(); From 880c59dfc0ceffebdef56dfbf7e4019e2b952cb8 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 29 Jul 2024 09:29:30 +0200 Subject: [PATCH 2/2] Polish "Update reference links in HELP.md" See gh-1541 --- ...adleBuildSystemHelpDocumentCustomizer.java | 19 +++--- ...avenBuildSystemHelpDocumentCustomizer.java | 14 ++-- .../GraalVmHelpDocumentCustomizer.java | 9 +-- .../ObservabilityHelpDocumentCustomizer.java | 7 +- .../TestContainersHelpDocumentCustomizer.java | 15 ++--- ...uildSystemHelpDocumentCustomizerTests.java | 15 ++++- ...uildSystemHelpDocumentCustomizerTests.java | 15 ++++- .../GraalVmHelpDocumentCustomizerTests.java | 25 ++++++-- ...ervabilityHelpDocumentCustomizerTests.java | 64 +++++++++++++++++++ ...rsProjectGenerationConfigurationTests.java | 14 +++- 10 files changed, 141 insertions(+), 56 deletions(-) create mode 100644 start-site/src/test/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizerTests.java diff --git a/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java index 5134c12c687..b645a5cb974 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizer.java @@ -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); } } diff --git a/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java index 1333d78b6f5..e4fe3d8d715 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizer.java @@ -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); } } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java index 363f54b6478..9a962a914f4 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizer.java @@ -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"); @@ -105,9 +105,4 @@ private Stream buildDependencies() { .filter(Objects::nonNull); } - private boolean shouldChangeUrl() { - - return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion); - } - } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java index a5af92e7706..0b82d7e30b0 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizer.java @@ -49,7 +49,7 @@ 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"); @@ -57,9 +57,4 @@ public void customize(HelpDocument document) { } } - private boolean shouldChangeUrl() { - - return this.SPRING_BOOT_3_3_0_OR_LATER.match(this.platformVersion); - } - } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java index 41e3d689ce6..cbe847d9f0e 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/testcontainers/TestContainersHelpDocumentCustomizer.java @@ -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 model = new HashMap<>(); List 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()); - } - } diff --git a/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java index 74da64eb4d5..fe8970a452d 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/build/gradle/GradleBuildSystemHelpDocumentCustomizerTests.java @@ -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 @@ -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 assertHelpDocument(String type, String version) { diff --git a/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java index e4b43e87551..c430cb05b63 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/build/maven/MavenBuildSystemHelpDocumentCustomizerTests.java @@ -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( @@ -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 assertHelpDocument(String type, String version) { diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java index b6c4b94200f..0ec9c9e0409 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/graalvm/GraalVmHelpDocumentCustomizerTests.java @@ -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"); @@ -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"); @@ -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"); diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizerTests.java new file mode 100644 index 00000000000..9b1dae50d95 --- /dev/null +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/observability/ObservabilityHelpDocumentCustomizerTests.java @@ -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 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(); + } + +} diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/testcontainers/TestcontainersProjectGenerationConfigurationTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/testcontainers/TestcontainersProjectGenerationConfigurationTests.java index 5773293b593..a18c5e3bbca 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/dependency/testcontainers/TestcontainersProjectGenerationConfigurationTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/testcontainers/TestcontainersProjectGenerationConfigurationTests.java @@ -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"); }