Skip to content

Commit e65732e

Browse files
committed
Fix Flyway sub-folders support in Native image
Prior to this commit, the native image support for scanning Flyway migration scripts would not scan sub-folders at runtime when running a Native image. This commit ensures that the resource scanning at runtime also considers sub-directories for native images. Fixes gh-49661
1 parent 10df287 commit e65732e

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void initialize() {
145145

146146
private Resource[] getResources(PathMatchingResourcePatternResolver resolver, Location location, Resource root) {
147147
try {
148-
return resolver.getResources(root.getURI() + "/*");
148+
return resolver.getResources(root.getURI() + "/**/*");
149149
}
150150
catch (IOException ex) {
151151
throw new UncheckedIOException("Failed to list resources for " + location.getDescriptor(), ex);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ void shouldRegisterResourceHints() {
968968
new FlywayAutoConfigurationRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
969969
assertThat(RuntimeHintsPredicates.resource().forResource("db/migration/")).accepts(runtimeHints);
970970
assertThat(RuntimeHintsPredicates.resource().forResource("db/migration/V1__init.sql")).accepts(runtimeHints);
971+
assertThat(RuntimeHintsPredicates.resource().forResource("db/migration/nested/V2__users.sql"))
972+
.accepts(runtimeHints);
971973
}
972974

973975
@Test

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProviderCustomizerTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.boot.testsupport.classpath.resources.WithResource;
28+
import org.springframework.boot.testsupport.classpath.resources.WithResources;
2829

2930
import static org.assertj.core.api.Assertions.assertThat;
3031

@@ -56,6 +57,19 @@ void nativeImageResourceProviderShouldFindMigrations() {
5657
assertThat(migrations).containsExactly(migration);
5758
}
5859

60+
@Test
61+
@WithResources({ @WithResource(name = "db/migration/V1__init.sql"),
62+
@WithResource(name = "db/migration/nested/V2__users.sql") })
63+
void nativeImageResourceProviderShouldFindNestedMigrations() {
64+
FluentConfiguration configuration = new FluentConfiguration();
65+
this.customizer.customize(configuration);
66+
ResourceProvider resourceProvider = configuration.getResourceProvider();
67+
Collection<LoadableResource> migrations = resourceProvider.getResources("V", new String[] { ".sql" });
68+
LoadableResource v1 = resourceProvider.getResource("V1__init.sql");
69+
LoadableResource v2 = resourceProvider.getResource("nested/V2__users.sql");
70+
assertThat(migrations).containsExactly(v1, v2);
71+
}
72+
5973
@Test
6074
void shouldBackOffOnCustomResourceProvider() {
6175
FluentConfiguration configuration = new FluentConfiguration();

0 commit comments

Comments
 (0)