Skip to content

Commit

Permalink
Merge pull request #1541 from ngocnhan-tran1996
Browse files Browse the repository at this point in the history
* pr/1541:
  Polish "Update reference links in HELP.md"
  Update reference links in HELP.md

Closes gh-1541
  • Loading branch information
mhalbritter committed Jul 29, 2024
2 parents a0944bf + 880c59d commit 722e50d
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -42,14 +48,19 @@ 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",
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 + (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 @@ -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.
Expand All @@ -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) {
Expand All @@ -41,13 +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 + "#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 = "https://docs.spring.io/spring-boot/docs/%s/maven-plugin/reference/html/";
return String.format(baseUrlFormat, 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 @@ -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;

Expand All @@ -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;
Expand All @@ -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(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 = String.format("https://docs.spring.io/spring-boot/docs/%s/%s/reference/htmlsingle/#aot",
this.platformVersion, (mavenBuild) ? "maven-plugin" : "gradle-plugin");
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");
document.gettingStarted().addAdditionalLink(url, "Configure AOT settings in Build Plugin");

Map<String, Object> model = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -42,10 +46,12 @@ 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(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");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -46,18 +50,21 @@ 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 = (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",
"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", (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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,35 @@
*
* @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
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
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,24 +28,33 @@
*
* @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(
"* [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(
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/docs/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,28 @@
*/
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 mavenBuildAddLinkToMavenAotPlugin() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.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");
assertThat(link.getHref()).isEqualTo("https://docs.spring.io/spring-boot/3.3.0/how-to/aot.html");
});
}

@Test
void mavenBuildAddLinkToMavenAotPluginWithOldSpringBootVersion() {
MutableProjectDescription description = new MutableProjectDescription();
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 @@ -60,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();
}

}
Loading

0 comments on commit 722e50d

Please sign in to comment.