From 90614db40234fe5d3f2ad5cc0ffb2095c6c5e44c Mon Sep 17 00:00:00 2001 From: wonwoo Date: Thu, 5 Oct 2023 17:47:37 +0900 Subject: [PATCH] Take R2DBC MySQL driver into account as of Spring Boot 3.1.x See gh-1314 --- .../R2dbcHelpDocumentCustomizer.java | 15 +++++++-- ...ingDataProjectGenerationConfiguration.java | 4 +-- .../R2dbcHelpDocumentCustomizerTests.java | 31 +++++++++++++------ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizer.java index e81eb4709cd..c5454d28e2c 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizer.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizer.java @@ -22,6 +22,9 @@ import io.spring.initializr.generator.buildsystem.Build; 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 a section when R2DBC is selected but no @@ -31,17 +34,23 @@ */ public class R2dbcHelpDocumentCustomizer implements HelpDocumentCustomizer { - private static final List DRIVERS = Arrays.asList("h2", "mariadb", "postgresql", "sqlserver", "oracle"); + private static final List DRIVERS = Arrays.asList("h2", "mysql", "mariadb", "postgresql", "sqlserver", + "oracle"); + + private static final VersionRange SPRING_BOOT_3_1_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.1.0"); + + private final boolean mysqlR2dbcIsAsyncerDependency; private final Build build; - public R2dbcHelpDocumentCustomizer(Build build) { + public R2dbcHelpDocumentCustomizer(Build build, Version platformVersion) { this.build = build; + this.mysqlR2dbcIsAsyncerDependency = SPRING_BOOT_3_1_0_OR_LATER.match(platformVersion); } @Override public void customize(HelpDocument document) { - if (this.build.dependencies().ids().noneMatch(DRIVERS::contains)) { + if (this.build.dependencies().ids().noneMatch(DRIVERS::contains) || !this.mysqlR2dbcIsAsyncerDependency) { document.addSection((writer) -> { writer.println("## Missing R2DBC Driver"); writer.println(); diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/SpringDataProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/SpringDataProjectGenerationConfiguration.java index 4ba833ac694..756e2bcd506 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/SpringDataProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springdata/SpringDataProjectGenerationConfiguration.java @@ -39,8 +39,8 @@ public R2dbcBuildCustomizer r2dbcBuildCustomizer(ProjectDescription description) @Bean @ConditionalOnRequestedDependency("data-r2dbc") - public R2dbcHelpDocumentCustomizer r2dbcHelpDocumentCustomizer(Build build) { - return new R2dbcHelpDocumentCustomizer(build); + public R2dbcHelpDocumentCustomizer r2dbcHelpDocumentCustomizer(Build build, ProjectDescription description) { + return new R2dbcHelpDocumentCustomizer(build, description.getPlatformVersion()); } } diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizerTests.java index 486c7808eef..3f8bf2218a3 100644 --- a/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizerTests.java +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/springdata/R2dbcHelpDocumentCustomizerTests.java @@ -21,6 +21,7 @@ import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.io.template.MustacheTemplateRenderer; import io.spring.initializr.generator.spring.documentation.HelpDocument; +import io.spring.initializr.generator.version.Version; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -35,53 +36,65 @@ class R2dbcHelpDocumentCustomizerTests { @Test void r2dbcWithNoMatchingDriver() { - HelpDocument helpDocument = createHelpDocument(); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0")); assertThat(helpDocument.getSections()).hasSize(1); } @Test void r2dbcWithH2() { - HelpDocument helpDocument = createHelpDocument("h2"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "h2"); assertThat(helpDocument.getSections()).isEmpty(); } @Test void r2dbcWithMariadb() { - HelpDocument helpDocument = createHelpDocument("mariadb"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "mariadb"); assertThat(helpDocument.getSections()).isEmpty(); } @Test void r2dbcWithPostgresql() { - HelpDocument helpDocument = createHelpDocument("postgresql"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "postgresql"); assertThat(helpDocument.getSections()).isEmpty(); } @Test void r2dbcWithSqlServer() { - HelpDocument helpDocument = createHelpDocument("sqlserver"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "sqlserver"); assertThat(helpDocument.getSections()).isEmpty(); } @Test void r2dbcWithOracle() { - HelpDocument helpDocument = createHelpDocument("oracle"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "oracle"); assertThat(helpDocument.getSections()).isEmpty(); } + @Test + void r2dbcWithMysql() { + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "mysql"); + assertThat(helpDocument.getSections()).isEmpty(); + } + + @Test + void r2dbcWithMysqlBeforeVersion() { + HelpDocument helpDocument = createHelpDocument(Version.parse("2.7.0.M1"), "mysql"); + assertThat(helpDocument.getSections()).hasSize(1); + } + @Test void r2dbcWithSeveralDrivers() { - HelpDocument helpDocument = createHelpDocument("mysql", "h2"); + HelpDocument helpDocument = createHelpDocument(Version.parse("3.1.0"), "mysql", "h2"); assertThat(helpDocument.getSections()).isEmpty(); } - private HelpDocument createHelpDocument(String... dependencyIds) { + private HelpDocument createHelpDocument(Version platformVersion, String... dependencyIds) { Build build = new GradleBuild(); for (String dependencyId : dependencyIds) { build.dependencies().add(dependencyId, Dependency.withCoordinates(dependencyId, dependencyId)); } HelpDocument document = new HelpDocument(mock(MustacheTemplateRenderer.class)); - new R2dbcHelpDocumentCustomizer(build).customize(document); + new R2dbcHelpDocumentCustomizer(build, platformVersion).customize(document); return document; }