From 3c71d57eae02e099b586a0ee38fc572e5a2f571c Mon Sep 17 00:00:00 2001 From: dashaun Date: Sat, 27 Apr 2024 22:28:25 -0500 Subject: [PATCH] Fixes #1454 --- ...endencyProjectGenerationConfiguration.java | 7 +++ .../SpringShellTestBuildCustomizer.java | 39 +++++++++++++ .../dependency/springshell/package-info.java | 20 +++++++ .../SpringShellTestBuildCustomizerTests.java | 57 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizer.java create mode 100644 start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/package-info.java create mode 100644 start-site/src/test/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizerTests.java diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java index b43a3c5e29..4a42b1a1b7 100644 --- a/start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java @@ -32,6 +32,7 @@ import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityRSocketBuildCustomizer; import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityTestBuildCustomizer; import io.spring.start.site.extension.dependency.springsession.SpringSessionBuildCustomizer; +import io.spring.start.site.extension.dependency.springshell.SpringShellTestBuildCustomizer; import io.spring.start.site.extension.dependency.thymeleaf.ThymeleafBuildCustomizer; import org.springframework.context.annotation.Bean; @@ -115,4 +116,10 @@ public MyBatisTestBuildCustomizer mybatisTestBuildCustomizer() { return new MyBatisTestBuildCustomizer(); } + @Bean + @ConditionalOnRequestedDependency("spring-shell") + public SpringShellTestBuildCustomizer springShellTestBuildCustomizer() { + return new SpringShellTestBuildCustomizer(); + } + } diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizer.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizer.java new file mode 100644 index 0000000000..cf3ad22582 --- /dev/null +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizer.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.springshell; + +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 {@code spring-shell-test} when Spring + * Shell is selected. + * + * @author DaShaun Carter + */ +public class SpringShellTestBuildCustomizer implements BuildCustomizer { + + @Override + public void customize(Build build) { + var springShell = Dependency.withCoordinates("org.springframework.shell", "spring-shell-starter-test") + .scope(DependencyScope.TEST_COMPILE); + build.dependencies().add("spring-shell-starter-test", springShell); + } + +} diff --git a/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/package-info.java b/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/package-info.java new file mode 100644 index 0000000000..cd7b0e6de9 --- /dev/null +++ b/start-site/src/main/java/io/spring/start/site/extension/dependency/springshell/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * Extensions for generation of projects that depend on Spring Security. + */ +package io.spring.start.site.extension.dependency.springshell; diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizerTests.java new file mode 100644 index 0000000000..3ea39d3268 --- /dev/null +++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/springshell/SpringShellTestBuildCustomizerTests.java @@ -0,0 +1,57 @@ +/* + * 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.springshell; + +import io.spring.initializr.metadata.BillOfMaterials; +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.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class SpringShellTestBuildCustomizerTests extends AbstractExtensionTests { + + @Test + void shellTestIsAddedWithSpringShell() { + ProjectRequest request = createProjectRequest("spring-shell"); + BillOfMaterials bom = getBom("spring-shell", request.getBootVersion()); + assertThat(mavenPom(request)).hasDependency(getDependency("spring-shell")) + .hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST)) + .hasDependency(springShellStarterTest()) + .hasDependenciesSize(3) + .hasBom("org.springframework.shell", "spring-shell-dependencies", "${spring-shell.version}") + .hasBomsSize(1) + .hasProperty("spring-shell.version", bom.getVersion()); + } + + @Test + void shellTestIsNotAddedWithoutSpringShell() { + ProjectRequest request = createProjectRequest("web"); + assertThat(mavenPom(request)).hasDependency(Dependency.createSpringBootStarter("web")) + .hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST)) + .hasDependenciesSize(2); + } + + private static Dependency springShellStarterTest() { + Dependency dependency = Dependency.withId("spring-shell-starter-test", "org.springframework.shell", + "spring-shell-starter-test"); + dependency.setScope(Dependency.SCOPE_TEST); + return dependency; + } + +}