|
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.elasticsearch;
|
18 | 18 |
|
| 19 | +import io.spring.initializr.generator.buildsystem.Build; |
19 | 20 | import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
|
20 | 21 | import io.spring.start.site.container.ComposeFileCustomizer;
|
21 | 22 | import io.spring.start.site.container.DockerServiceResolver;
|
|
30 | 31 | *
|
31 | 32 | * @author Moritz Halbritter
|
32 | 33 | * @author Stephane Nicoll
|
| 34 | + * @author Eddú Meléndez |
33 | 35 | */
|
34 | 36 | @Configuration(proxyBeanMethods = false)
|
35 |
| -@ConditionalOnRequestedDependency("data-elasticsearch") |
36 | 37 | class ElasticsearchProjectGenerationConfiguration {
|
37 | 38 |
|
38 | 39 | private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.elasticsearch.ElasticsearchContainer";
|
39 | 40 |
|
40 | 41 | @Bean
|
41 | 42 | @ConditionalOnRequestedDependency("testcontainers")
|
42 |
| - ServiceConnectionsCustomizer elasticsearchServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { |
43 |
| - return (serviceConnections) -> serviceResolver.doWith("elasticsearch", |
44 |
| - (service) -> serviceConnections.addServiceConnection( |
| 43 | + ServiceConnectionsCustomizer elasticsearchServiceConnectionsCustomizer(Build build, |
| 44 | + DockerServiceResolver serviceResolver) { |
| 45 | + return (serviceConnections) -> { |
| 46 | + if (isElasticsearchEnabled(build)) { |
| 47 | + serviceResolver.doWith("elasticsearch", (service) -> serviceConnections.addServiceConnection( |
45 | 48 | ServiceConnection.ofContainer("elasticsearch", service, TESTCONTAINERS_CLASS_NAME, false)));
|
| 49 | + } |
| 50 | + }; |
46 | 51 | }
|
47 | 52 |
|
48 | 53 | @Bean
|
49 | 54 | @ConditionalOnRequestedDependency("docker-compose")
|
50 |
| - ComposeFileCustomizer elasticsearchComposeFileCustomizer(DockerServiceResolver serviceResolver) { |
51 |
| - return (composeFile) -> serviceResolver.doWith("elasticsearch", |
52 |
| - (service) -> composeFile.services() |
53 |
| - .add("elasticsearch", |
54 |
| - service.andThen((builder) -> builder.environment("ELASTIC_PASSWORD", "secret") |
55 |
| - .environment("xpack.security.enabled", "false") |
56 |
| - .environment("discovery.type", "single-node")))); |
| 55 | + ComposeFileCustomizer elasticsearchComposeFileCustomizer(Build build, DockerServiceResolver serviceResolver) { |
| 56 | + return (composeFile) -> { |
| 57 | + if (isElasticsearchEnabled(build)) { |
| 58 | + serviceResolver.doWith("elasticsearch", |
| 59 | + (service) -> composeFile.services() |
| 60 | + .add("elasticsearch", |
| 61 | + service.andThen((builder) -> builder.environment("ELASTIC_PASSWORD", "secret") |
| 62 | + .environment("xpack.security.enabled", "false") |
| 63 | + .environment("discovery.type", "single-node")))); |
| 64 | + } |
| 65 | + }; |
| 66 | + } |
| 67 | + |
| 68 | + private boolean isElasticsearchEnabled(Build build) { |
| 69 | + return build.dependencies().has("data-elasticsearch") |
| 70 | + || build.dependencies().has("spring-ai-vectordb-elasticsearch"); |
57 | 71 | }
|
58 | 72 |
|
59 | 73 | }
|
0 commit comments