Skip to content

Commit

Permalink
Merge pull request #882 from tisonkun
Browse files Browse the repository at this point in the history
* pr/882:
  Polish "Update artifact coordinates for R2DBC Postgres driver"
  Update artifact coordinates for R2DBC Postgres driver

Closes gh-882
  • Loading branch information
snicoll committed Apr 1, 2022
2 parents 864221d + 96b858e commit 806c198
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 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.
Expand All @@ -24,6 +24,9 @@
import io.spring.initializr.generator.buildsystem.DependencyContainer;
import io.spring.initializr.generator.buildsystem.DependencyScope;
import io.spring.initializr.generator.spring.build.BuildCustomizer;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.generator.version.VersionParser;
import io.spring.initializr.generator.version.VersionRange;

/**
* A {@link BuildCustomizer} for R2DBC that adds the necessary extra dependencies based on
Expand All @@ -36,6 +39,14 @@ public class R2dbcBuildCustomizer implements BuildCustomizer<Build> {

private static final List<String> JDBC_DEPENDENCY_IDS = Arrays.asList("jdbc", "data-jdbc", "data-jpa");

private static final VersionRange SPRING_BOOT_3_0_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.0.0-M1");

private final Version platformVersion;

public R2dbcBuildCustomizer(Version platformVersion) {
this.platformVersion = platformVersion;
}

@Override
public void customize(Build build) {
if (build.dependencies().has("h2")) {
Expand All @@ -48,7 +59,8 @@ public void customize(Build build) {
addManagedDriver(build.dependencies(), "dev.miku", "r2dbc-mysql");
}
if (build.dependencies().has("postgresql")) {
addManagedDriver(build.dependencies(), "io.r2dbc", "r2dbc-postgresql");
String groupId = (SPRING_BOOT_3_0_0_OR_LATER.match(this.platformVersion)) ? "org.postgresql" : "io.r2dbc";
addManagedDriver(build.dependencies(), groupId, "r2dbc-postgresql");
}
if (build.dependencies().has("sqlserver")) {
addManagedDriver(build.dependencies(), "io.r2dbc", "r2dbc-mssql");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,6 +18,7 @@

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;

import org.springframework.context.annotation.Bean;
Expand All @@ -32,8 +33,8 @@ public class SpringDataProjectGenerationConfiguration {

@Bean
@ConditionalOnRequestedDependency("data-r2dbc")
public R2dbcBuildCustomizer r2dbcBuildCustomizer() {
return new R2dbcBuildCustomizer();
public R2dbcBuildCustomizer r2dbcBuildCustomizer(ProjectDescription description) {
return new R2dbcBuildCustomizer(description.getPlatformVersion());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 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.
Expand Down Expand Up @@ -69,6 +69,17 @@ void r2dbcWithPostgresql() {
build.dependencies().add("postgresql");
customize(build);
assertThat(build.dependencies().ids()).containsOnly("data-r2dbc", "postgresql", "r2dbc-postgresql");
assertThat(build.dependencies().get("r2dbc-postgresql").getGroupId()).isEqualTo("io.r2dbc");
}

@Test
void r2dbcWithPostgresqlAfterSpringBoot3() {
Build build = createBuild();
build.dependencies().add("data-r2dbc");
build.dependencies().add("postgresql");
customize(build, Version.parse("3.0.0-M2"));
assertThat(build.dependencies().ids()).containsOnly("data-r2dbc", "postgresql", "r2dbc-postgresql");
assertThat(build.dependencies().get("r2dbc-postgresql").getGroupId()).isEqualTo("org.postgresql");
}

@Test
Expand Down Expand Up @@ -122,12 +133,19 @@ void r2dbcWithLiquibaseAndJdbcStaterDoesNotAddSpringJdbc(String jdbcStarter) {

private Build createBuild() {
InitializrMetadata metadata = getMetadata();
return new MavenBuild(new MetadataBuildItemResolver(metadata,
Version.parse(metadata.getBootVersions().getDefault().getId())));
return new MavenBuild(new MetadataBuildItemResolver(metadata, getDefaultPlatformVersion(metadata)));
}

private void customize(Build build) {
new R2dbcBuildCustomizer().customize(build);
customize(build, getDefaultPlatformVersion(getMetadata()));
}

private void customize(Build build, Version platformVersion) {
new R2dbcBuildCustomizer(platformVersion).customize(build);
}

private Version getDefaultPlatformVersion(InitializrMetadata metadata) {
return Version.parse(metadata.getBootVersions().getDefault().getId());
}

}

0 comments on commit 806c198

Please sign in to comment.