Skip to content

Commit c34e3fa

Browse files
committed
Add amqp dependency if amqp-streams is selected
Closes gh-1862
1 parent 985a578 commit c34e3fa

File tree

3 files changed

+118
-21
lines changed

3 files changed

+118
-21
lines changed

start-site/src/main/java/io/spring/start/site/extension/dependency/springamqp/SpringAmqpProjectGenerationConfiguration.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,57 @@
2424
import io.spring.start.site.container.ServiceConnectionsCustomizer;
2525

2626
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
2728

2829
/**
2930
* Configuration for generation of projects that depend on Spring AMQP.
3031
*
3132
* @author Stephane Nicoll
32-
* @author Stephane Nicoll
3333
*/
3434
@ProjectGenerationConfiguration
35-
@ConditionalOnRequestedDependency("amqp")
3635
class SpringAmqpProjectGenerationConfiguration {
3736

38-
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.RabbitMQContainer";
37+
@Configuration(proxyBeanMethods = false)
38+
@ConditionalOnRequestedDependency("amqp")
39+
static class AmqpConfiguration {
3940

40-
@Bean
41-
SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() {
42-
return new SpringRabbitTestBuildCustomizer();
43-
}
41+
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.RabbitMQContainer";
42+
43+
@Bean
44+
SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() {
45+
return new SpringRabbitTestBuildCustomizer();
46+
}
47+
48+
@Bean
49+
@ConditionalOnRequestedDependency("testcontainers")
50+
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
51+
return (serviceConnections) -> serviceResolver.doWith("rabbit",
52+
(service) -> serviceConnections.addServiceConnection(
53+
ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false)));
54+
}
55+
56+
@Bean
57+
@ConditionalOnRequestedDependency("docker-compose")
58+
ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) {
59+
return (composeFile) -> serviceResolver.doWith("rabbit",
60+
(service) -> composeFile.services()
61+
.add("rabbitmq",
62+
service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser")
63+
.environment("RABBITMQ_DEFAULT_PASS", "secret")
64+
.ports(5672))));
65+
}
4466

45-
@Bean
46-
@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)));
5067
}
5168

52-
@Bean
53-
@ConditionalOnRequestedDependency("docker-compose")
54-
ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) {
55-
return (composeFile) -> serviceResolver.doWith("rabbit",
56-
(service) -> composeFile.services()
57-
.add("rabbitmq",
58-
service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser")
59-
.environment("RABBITMQ_DEFAULT_PASS", "secret")
60-
.ports(5672))));
69+
@ConditionalOnRequestedDependency("amqp-streams")
70+
@Configuration(proxyBeanMethods = false)
71+
static class AmqpStreamsConfiguration {
72+
73+
@Bean
74+
SpringRabbitStreamsBuildCustomizer springRabbitStreamsBuildCustomizer() {
75+
return new SpringRabbitStreamsBuildCustomizer();
76+
}
77+
6178
}
6279

6380
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springamqp;
18+
19+
import io.spring.initializr.generator.buildsystem.Build;
20+
import io.spring.initializr.generator.spring.build.BuildCustomizer;
21+
22+
/**
23+
* Adds AMQP if RabbitMQ Streams is selected.
24+
*
25+
* @author Moritz Halbritter
26+
*/
27+
class SpringRabbitStreamsBuildCustomizer implements BuildCustomizer<Build> {
28+
29+
@Override
30+
public void customize(Build build) {
31+
build.dependencies().add("amqp");
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springamqp;
18+
19+
import io.spring.initializr.metadata.Dependency;
20+
import io.spring.initializr.web.project.ProjectRequest;
21+
import io.spring.start.site.extension.AbstractExtensionTests;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
/**
27+
* Tests for {@link SpringRabbitStreamsBuildCustomizer}.
28+
*
29+
* @author Moritz Halbritter
30+
*/
31+
class SpringRabbitStreamsBuildCustomizerTests extends AbstractExtensionTests {
32+
33+
@Test
34+
void shouldDoNothingIfAmqpStreamsIsNotSelected() {
35+
ProjectRequest project = createProjectRequest("web");
36+
Dependency amqp = getDependency("amqp");
37+
assertThat(mavenPom(project)).doesNotHaveDependency(amqp.getGroupId(), amqp.getArtifactId());
38+
}
39+
40+
@Test
41+
void shouldAddAmqpIfAmqpStreamsIsSelected() {
42+
ProjectRequest project = createProjectRequest("amqp-streams");
43+
assertThat(mavenPom(project)).hasDependency(getDependency("amqp"));
44+
}
45+
46+
}

0 commit comments

Comments
 (0)