|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 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.springazure; |
| 18 | + |
| 19 | +import io.spring.initializr.generator.buildsystem.Build; |
| 20 | +import io.spring.initializr.generator.buildsystem.Dependency; |
| 21 | +import io.spring.initializr.generator.buildsystem.DependencyScope; |
| 22 | +import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem; |
| 23 | +import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem; |
| 24 | +import io.spring.initializr.generator.condition.ConditionalOnBuildSystem; |
| 25 | +import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; |
| 26 | +import io.spring.initializr.generator.project.ProjectGenerationConfiguration; |
| 27 | +import io.spring.initializr.generator.spring.build.BuildCustomizer; |
| 28 | +import io.spring.initializr.generator.spring.build.gradle.DevelopmentOnlyDependencyGradleBuildCustomizer; |
| 29 | +import io.spring.initializr.generator.spring.build.maven.OptionalDependencyMavenBuildCustomizer; |
| 30 | +import io.spring.start.site.container.ComposeFileCustomizer; |
| 31 | +import io.spring.start.site.container.DockerServiceResolver; |
| 32 | + |
| 33 | +import org.springframework.context.annotation.Bean; |
| 34 | + |
| 35 | +/** |
| 36 | + * Configuration for generation of projects that depend on Spring Azure Docker Compose. |
| 37 | + * |
| 38 | + * @author Eddú Meléndez |
| 39 | + * @author Moritz Halbritter |
| 40 | + */ |
| 41 | +@ProjectGenerationConfiguration |
| 42 | +@ConditionalOnRequestedDependency("azure-storage") |
| 43 | +class SpringAzureDockerComposeProjectGenerationConfiguration { |
| 44 | + |
| 45 | + private static final String DEPENDENCY_ID = "spring-azure-docker-compose"; |
| 46 | + |
| 47 | + @Bean |
| 48 | + @ConditionalOnRequestedDependency("docker-compose") |
| 49 | + BuildCustomizer<Build> springAzureDockerComposeBuildCustomizer() { |
| 50 | + return (build) -> build.dependencies() |
| 51 | + .add(DEPENDENCY_ID, Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-docker-compose") |
| 52 | + .scope(DependencyScope.RUNTIME)); |
| 53 | + } |
| 54 | + |
| 55 | + @Bean |
| 56 | + @ConditionalOnBuildSystem(MavenBuildSystem.ID) |
| 57 | + OptionalDependencyMavenBuildCustomizer springAzureDockerComposeMavenBuildCustomizer() { |
| 58 | + return new OptionalDependencyMavenBuildCustomizer(DEPENDENCY_ID); |
| 59 | + } |
| 60 | + |
| 61 | + @Bean |
| 62 | + @ConditionalOnBuildSystem(GradleBuildSystem.ID) |
| 63 | + DevelopmentOnlyDependencyGradleBuildCustomizer springAzureDockerComposeGradleBuildCustomizer() { |
| 64 | + return new DevelopmentOnlyDependencyGradleBuildCustomizer(DEPENDENCY_ID); |
| 65 | + } |
| 66 | + |
| 67 | + @Bean |
| 68 | + @ConditionalOnRequestedDependency("docker-compose") |
| 69 | + ComposeFileCustomizer azureStorageComposeFileCustomizer(DockerServiceResolver serviceResolver) { |
| 70 | + return (composeFile) -> serviceResolver.doWith("azurite", |
| 71 | + (service) -> composeFile.services().add("azurite", service)); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments