|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2022 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.flyway;
|
18 | 18 |
|
| 19 | +import java.lang.reflect.Constructor; |
19 | 20 | import java.util.Arrays;
|
20 | 21 |
|
| 22 | +import org.flywaydb.core.api.configuration.Configuration; |
21 | 23 | import org.flywaydb.core.api.configuration.FluentConfiguration;
|
22 | 24 | import org.flywaydb.core.api.migration.JavaMigration;
|
23 | 25 | import org.flywaydb.core.internal.scanner.LocationScannerCache;
|
|
29 | 31 | * {@link org.flywaydb.core.api.ResourceProvider}.
|
30 | 32 | *
|
31 | 33 | * @author Moritz Halbritter
|
| 34 | + * @author Maziz Esa |
32 | 35 | */
|
33 | 36 | class NativeImageResourceProviderCustomizer extends ResourceProviderCustomizer {
|
34 | 37 |
|
35 | 38 | @Override
|
36 | 39 | public void customize(FluentConfiguration configuration) {
|
37 | 40 | if (configuration.getResourceProvider() == null) {
|
38 |
| - Scanner<JavaMigration> scanner = new Scanner<>(JavaMigration.class, |
39 |
| - Arrays.asList(configuration.getLocations()), configuration.getClassLoader(), |
40 |
| - configuration.getEncoding(), configuration.isDetectEncoding(), false, new ResourceNameCache(), |
41 |
| - new LocationScannerCache(), configuration.isFailOnMissingLocations()); |
| 41 | + Scanner<?> scanner = createScanner(configuration); |
42 | 42 | NativeImageResourceProvider resourceProvider = new NativeImageResourceProvider(scanner,
|
43 | 43 | configuration.getClassLoader(), Arrays.asList(configuration.getLocations()),
|
44 | 44 | configuration.getEncoding(), configuration.isFailOnMissingLocations());
|
45 | 45 | configuration.resourceProvider(resourceProvider);
|
46 | 46 | }
|
47 | 47 | }
|
48 | 48 |
|
| 49 | + private static Scanner<?> createScanner(FluentConfiguration configuration) { |
| 50 | + try { |
| 51 | + return new Scanner<>(JavaMigration.class, Arrays.asList(configuration.getLocations()), |
| 52 | + configuration.getClassLoader(), configuration.getEncoding(), configuration.isDetectEncoding(), |
| 53 | + false, new ResourceNameCache(), new LocationScannerCache(), |
| 54 | + configuration.isFailOnMissingLocations()); |
| 55 | + } |
| 56 | + catch (NoSuchMethodError ex) { |
| 57 | + // Flyway 10 |
| 58 | + return createFlyway10Scanner(configuration); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + private static Scanner<?> createFlyway10Scanner(FluentConfiguration configuration) throws LinkageError { |
| 63 | + try { |
| 64 | + Constructor<?> scannerConstructor = Scanner.class.getDeclaredConstructor(Class.class, boolean.class, |
| 65 | + ResourceNameCache.class, LocationScannerCache.class, Configuration.class); |
| 66 | + return (Scanner<?>) scannerConstructor.newInstance(JavaMigration.class, false, new ResourceNameCache(), |
| 67 | + new LocationScannerCache(), configuration); |
| 68 | + } |
| 69 | + catch (Exception ex) { |
| 70 | + throw new RuntimeException(ex); |
| 71 | + } |
| 72 | + } |
| 73 | + |
49 | 74 | }
|
0 commit comments