From 87ce541518cafb798b4e9d3ee9090db9d6a9d69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 6 Sep 2023 13:55:21 -0600 Subject: [PATCH 1/3] Add support for Pulsar container Recently, spring pulsar was integrated in spring boot with `ConnectionDetails` and `ServiceConnection`. --- .../SimpleDockerServiceResolver.java | 6 +++++ ...gPulsarProjectGenerationConfiguration.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/start-site/src/main/java/io/spring/start/site/container/SimpleDockerServiceResolver.java b/start-site/src/main/java/io/spring/start/site/container/SimpleDockerServiceResolver.java index f81853f084b..f67fe0344ee 100644 --- a/start-site/src/main/java/io/spring/start/site/container/SimpleDockerServiceResolver.java +++ b/start-site/src/main/java/io/spring/start/site/container/SimpleDockerServiceResolver.java @@ -41,6 +41,7 @@ public SimpleDockerServiceResolver() { this.dockerServices.put("mysql", mysql()); this.dockerServices.put("oracle", oracle()); this.dockerServices.put("postgres", postgres()); + this.dockerServices.put("pulsar", pulsar()); this.dockerServices.put("rabbit", rabbit()); this.dockerServices.put("redis", redis()); this.dockerServices.put("sqlServer", sqlServer()); @@ -86,6 +87,11 @@ private static DockerService postgres() { return new DockerService("postgres", "latest", "https://hub.docker.com/_/postgres", 5432); } + private static DockerService pulsar() { + return new DockerService("apachepulsar/pulsar", "latest", "https://hub.docker.com/r/apachepulsar/pulsar", 6650, + 8080); + } + private static DockerService rabbit() { return new DockerService("rabbitmq", "latest", "https://hub.docker.com/_/rabbitmq", 5672); } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java index 38fc039d8b5..c3a91f7b29d 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java @@ -16,17 +16,23 @@ package io.spring.start.site.extension.dependency.springpulsar; +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.project.ProjectGenerationConfiguration; import io.spring.initializr.metadata.InitializrMetadata; +import io.spring.start.site.container.ComposeFileCustomizer; +import io.spring.start.site.container.DockerServiceResolver; +import io.spring.start.site.container.ServiceConnections; +import io.spring.start.site.container.ServiceConnectionsCustomizer; import org.springframework.context.annotation.Bean; /** * Configuration for generation of projects that depend on Pulsar. * * @author Chris Bono + * @author EddĂș MelĂ©ndez */ @ProjectGenerationConfiguration @ConditionalOnRequestedDependency("pulsar") @@ -39,4 +45,20 @@ SpringPulsarBinderBuildCustomizer pulsarBinderBuildCustomizer(InitializrMetadata return new SpringPulsarBinderBuildCustomizer(metadata, description); } + @Bean + @ConditionalOnRequestedDependency("testcontainers") + @ConditionalOnPlatformVersion("3.2.0-SNAPSHOT") + ServiceConnectionsCustomizer pulsarServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { + return (serviceConnections) -> serviceResolver.doWith("pulsar", + (service) -> serviceConnections.addServiceConnection(ServiceConnections.ServiceConnection + .ofContainer("pulsar", service, "org.testcontainers.containers.PulsarContainer", false))); + } + + @Bean + @ConditionalOnRequestedDependency("docker-compose") + ComposeFileCustomizer pulsarComposeFileCustomizer(DockerServiceResolver serviceResolver) { + return (composeFile) -> serviceResolver.doWith("pulsar", + (service) -> composeFile.services().add("pulsar", service)); + } + } From d5b6e5c7b8105daea38c4820a8bc145d64a91df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 6 Sep 2023 14:02:23 -0600 Subject: [PATCH 2/3] Fix checkstyle --- .../SpringPulsarProjectGenerationConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java index c3a91f7b29d..03c4d148d00 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java @@ -21,11 +21,11 @@ import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.project.ProjectGenerationConfiguration; import io.spring.initializr.metadata.InitializrMetadata; - import io.spring.start.site.container.ComposeFileCustomizer; import io.spring.start.site.container.DockerServiceResolver; import io.spring.start.site.container.ServiceConnections; import io.spring.start.site.container.ServiceConnectionsCustomizer; + import org.springframework.context.annotation.Bean; /** From 935db45a4139de5f65bccdb0185839751cf9ef9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 6 Sep 2023 14:13:07 -0600 Subject: [PATCH 3/3] Add missing conditional on platform --- .../springpulsar/SpringPulsarProjectGenerationConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java index 03c4d148d00..3571e39ac4d 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springpulsar/SpringPulsarProjectGenerationConfiguration.java @@ -56,6 +56,7 @@ ServiceConnectionsCustomizer pulsarServiceConnectionsCustomizer(DockerServiceRes @Bean @ConditionalOnRequestedDependency("docker-compose") + @ConditionalOnPlatformVersion("3.2.0-SNAPSHOT") ComposeFileCustomizer pulsarComposeFileCustomizer(DockerServiceResolver serviceResolver) { return (composeFile) -> serviceResolver.doWith("pulsar", (service) -> composeFile.services().add("pulsar", service));