|
1 | 1 | /* |
2 | | - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package io.spring.start.site.extension.dependency.springamqp; |
18 | 18 |
|
| 19 | +import io.spring.initializr.generator.buildsystem.Build; |
19 | 20 | import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; |
20 | 21 | import io.spring.initializr.generator.project.ProjectGenerationConfiguration; |
21 | 22 | import io.spring.start.site.container.ComposeFileCustomizer; |
|
29 | 30 | * Configuration for generation of projects that depend on Spring AMQP. |
30 | 31 | * |
31 | 32 | * @author Stephane Nicoll |
32 | | - * @author Stephane Nicoll |
| 33 | + * @author Eddú Meléndez |
33 | 34 | */ |
34 | 35 | @ProjectGenerationConfiguration |
35 | | -@ConditionalOnRequestedDependency("amqp") |
36 | 36 | class SpringAmqpProjectGenerationConfiguration { |
37 | 37 |
|
38 | 38 | private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.RabbitMQContainer"; |
39 | 39 |
|
40 | 40 | @Bean |
| 41 | + @ConditionalOnRequestedDependency("amqp") |
41 | 42 | SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() { |
42 | 43 | return new SpringRabbitTestBuildCustomizer(); |
43 | 44 | } |
44 | 45 |
|
45 | 46 | @Bean |
46 | 47 | @ConditionalOnRequestedDependency("testcontainers") |
47 | | - ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { |
48 | | - return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> serviceConnections |
49 | | - .addServiceConnection(ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false))); |
| 48 | + ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(Build build, |
| 49 | + DockerServiceResolver serviceResolver) { |
| 50 | + return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> { |
| 51 | + if (isAmqpEnabled(build)) { |
| 52 | + serviceConnections.addServiceConnection( |
| 53 | + ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false)); |
| 54 | + } |
| 55 | + }); |
50 | 56 | } |
51 | 57 |
|
52 | 58 | @Bean |
53 | 59 | @ConditionalOnRequestedDependency("docker-compose") |
54 | | - ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) { |
55 | | - return (composeFile) -> serviceResolver.doWith("rabbit", |
56 | | - (service) -> composeFile.services() |
| 60 | + ComposeFileCustomizer rabbitComposeFileCustomizer(Build build, DockerServiceResolver serviceResolver) { |
| 61 | + return (composeFile) -> serviceResolver.doWith("rabbit", (service) -> { |
| 62 | + if (isAmqpEnabled(build)) { |
| 63 | + composeFile.services() |
57 | 64 | .add("rabbitmq", |
58 | 65 | service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser") |
59 | 66 | .environment("RABBITMQ_DEFAULT_PASS", "secret") |
60 | | - .ports(5672)))); |
| 67 | + .ports(5672))); |
| 68 | + } |
| 69 | + }); |
| 70 | + } |
| 71 | + |
| 72 | + private boolean isAmqpEnabled(Build build) { |
| 73 | + return build.dependencies().has("amqp") || build.dependencies().has("amqp-streams"); |
61 | 74 | } |
62 | 75 |
|
63 | 76 | } |
0 commit comments