diff --git a/components/sbm-support-boot/src/main/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinder.java b/components/sbm-support-boot/src/main/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinder.java new file mode 100644 index 000000000..ff8a8f219 --- /dev/null +++ b/components/sbm-support-boot/src/main/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinder.java @@ -0,0 +1,20 @@ +package org.springframework.sbm.boot.properties.finder; + +import org.openrewrite.properties.tree.Properties; +import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties; +import org.springframework.sbm.project.resource.ProjectResourceSet; +import org.springframework.sbm.project.resource.filter.ProjectResourceFinder; + +import java.util.Optional; + +public class SpringBootDefaultPropertiesFinder implements ProjectResourceFinder> { + + @Override + public Optional apply(ProjectResourceSet projectResourceSet) { + return projectResourceSet.stream() + .filter(r -> r.getSourceFile() instanceof Properties.File) + .map(r -> new SpringBootApplicationProperties(r.getAbsoluteProjectDir(), (Properties.File) r.getSourceFile())) + .filter(SpringBootApplicationProperties::isDefaultProperties) + .findFirst(); + } +} diff --git a/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinderTest.java b/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinderTest.java new file mode 100644 index 000000000..829910861 --- /dev/null +++ b/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/properties/finder/SpringBootDefaultPropertiesFinderTest.java @@ -0,0 +1,31 @@ +package org.springframework.sbm.boot.properties.finder; + +import org.junit.jupiter.api.Test; +import org.springframework.sbm.engine.context.ProjectContext; +import org.springframework.sbm.project.resource.TestProjectContext; + +import java.nio.file.Path; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SpringBootDefaultPropertiesFinderTest { + + @Test + public void givenAProjectWithDefaultSpringBootProperties_applyFinder_expectPropertyFile(){ + ProjectContext projectContext = TestProjectContext.buildProjectContext() + .addProjectResource(Path.of("src","main", "resources", "application.properties"), "foo=bar") + .build(); + + SpringBootDefaultPropertiesFinder springBootDefaultPropertiesFinder = new SpringBootDefaultPropertiesFinder(); + assertThat(springBootDefaultPropertiesFinder.apply(projectContext.getProjectResources()).isPresent()).isTrue(); + } + + @Test + public void givenAProjectWithoutDefaultSpringBootProperties_applyFinder_expectPropertyFile(){ + ProjectContext projectContext = TestProjectContext.buildProjectContext() + .build(); + + SpringBootDefaultPropertiesFinder springBootDefaultPropertiesFinder = new SpringBootDefaultPropertiesFinder(); + assertThat(springBootDefaultPropertiesFinder.apply(projectContext.getProjectResources()).isEmpty()).isTrue(); + } +}