diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizer.java new file mode 100644 index 00000000000..349ba5b9213 --- /dev/null +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizer.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.start.site.extension.dependency.dgs; + +import io.spring.initializr.generator.buildsystem.Build; +import io.spring.initializr.generator.buildsystem.Dependency; +import io.spring.initializr.generator.buildsystem.DependencyScope; +import io.spring.initializr.generator.spring.build.BuildCustomizer; + +/** + * A {@link BuildCustomizer} that automatically adds + * "graphql-dgs-spring-graphql-starter-test" when the {@code dgs} dependency is present. + * + * @author Brian Clozel + */ +class DgsBuildCustomizer implements BuildCustomizer { + + @Override + public void customize(Build build) { + build.dependencies() + .add("graphql-dgs-spring-graphql-starter-test", + Dependency.withCoordinates("com.netflix.graphql.dgs", "graphql-dgs-spring-graphql-starter-test") + .scope(DependencyScope.TEST_COMPILE)); + } + +} diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsProjectGenerationConfiguration.java new file mode 100644 index 00000000000..be1387b6c1c --- /dev/null +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/dgs/DgsProjectGenerationConfiguration.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.start.site.extension.dependency.dgs; + +import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; +import io.spring.initializr.generator.project.ProjectGenerationConfiguration; + +import org.springframework.context.annotation.Bean; + +/** + * {@link ProjectGenerationConfiguration} for generation of projects that use the Netflix + * DGS. + * + * @author Brian Clozel + */ +@ProjectGenerationConfiguration +@ConditionalOnRequestedDependency("netflix-dgs") +class DgsProjectGenerationConfiguration { + + @Bean + DgsBuildCustomizer dgsBuildCustomizer() { + return new DgsBuildCustomizer(); + } + +} diff --git a/start-site/src/main/resources/META-INF/spring.factories b/start-site/src/main/resources/META-INF/spring.factories index f2a58132499..40924849fc3 100644 --- a/start-site/src/main/resources/META-INF/spring.factories +++ b/start-site/src/main/resources/META-INF/spring.factories @@ -7,6 +7,7 @@ io.spring.start.site.extension.dependency.activemq.ActiveMQProjectGenerationConf io.spring.start.site.extension.dependency.activemq.ArtemisProjectGenerationConfiguration,\ io.spring.start.site.extension.dependency.cassandra.CassandraProjectGenerationConfiguration,\ io.spring.start.site.extension.dependency.derby.DerbyProjectGenerationConfiguration,\ +io.spring.start.site.extension.dependency.dgs.DgsProjectGenerationConfiguration,\ io.spring.start.site.extension.dependency.dgs.DgsCodegenProjectGenerationConfiguration,\ io.spring.start.site.extension.dependency.dockercompose.DockerComposeProjectGenerationConfiguration,\ io.spring.start.site.extension.dependency.elasticsearch.ElasticsearchProjectGenerationConfiguration,\ diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizerTests.java new file mode 100644 index 00000000000..0dd86da5b96 --- /dev/null +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/dgs/DgsBuildCustomizerTests.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.start.site.extension.dependency.dgs; + +import io.spring.initializr.metadata.Dependency; +import io.spring.initializr.web.project.ProjectRequest; +import io.spring.start.site.extension.AbstractExtensionTests; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class DgsBuildCustomizerTests extends AbstractExtensionTests { + + private Dependency dgsTest; + + @BeforeEach + void setup() { + this.dgsTest = Dependency.withId("graphql-dgs-spring-graphql-starter-test", "com.netflix.graphql.dgs", + "graphql-dgs-spring-graphql-starter-test"); + this.dgsTest.setScope(Dependency.SCOPE_TEST); + } + + @Test + void shouldAddTestingDependency() { + ProjectRequest request = createProjectRequest("web", "netflix-dgs"); + assertThat(mavenPom(request)).hasDependency(Dependency.createSpringBootStarter("web")) + .hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST)) + .hasDependency(this.dgsTest) + .hasDependenciesSize(4); + } + +}