Skip to content

Commit

Permalink
Match Testcontainers version
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Feb 29, 2024
1 parent 68bc6d6 commit e6a04c3
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package io.spring.start.site.extension.dependency.postgresql;

import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectDescription;
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.versionresolver.MavenVersionResolver;
import io.spring.start.site.container.ComposeFileCustomizer;
import io.spring.start.site.container.DockerServiceResolver;
import io.spring.start.site.container.ServiceConnections.ServiceConnection;
Expand All @@ -26,6 +30,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
* Configuration for generation of projects that depend on PgVector.
*
Expand All @@ -37,13 +43,31 @@ class PgVectorProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.PostgreSQLContainer";

private static final VersionRange TESTCONTAINERS_1_9_7_OR_LATER = VersionParser.DEFAULT.parseRange("1.19.7");

private final MavenVersionResolver versionResolver;

private final ProjectDescription description;

public PgVectorProjectGenerationConfiguration(MavenVersionResolver versionResolver,
ProjectDescription description) {
this.versionResolver = versionResolver;
this.description = description;
}

@Bean
@ConditionalOnPlatformVersion("3.3.0-M3")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer pgvectorServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver
.doWith("pgvector", (service) -> serviceConnections.addServiceConnection(
Map<String, String> resolve = this.versionResolver.resolveDependencies("org.springframework.boot",
"spring-boot-dependencies", this.description.getPlatformVersion().toString());
String testcontainersVersion = resolve.get("org.testcontainers:testcontainers");

return (serviceConnections) -> {
if (TESTCONTAINERS_1_9_7_OR_LATER.match(Version.parse(testcontainersVersion))) {
serviceResolver.doWith("pgvector", (service) -> serviceConnections.addServiceConnection(
ServiceConnection.ofContainer("pgvector", service, TESTCONTAINERS_CLASS_NAME)));
}
};
}

@Bean
Expand Down

0 comments on commit e6a04c3

Please sign in to comment.