2323import org .flywaydb .core .api .resolver .ResolvedMigration ;
2424import org .springframework .aop .framework .ProxyFactory ;
2525import org .springframework .util .ClassUtils ;
26+ import org .springframework .util .ObjectUtils ;
2627
2728import javax .sql .DataSource ;
2829import java .util .Arrays ;
@@ -93,7 +94,10 @@ public Collection<ResolvedMigration> getMigrations() {
9394 Flyway flyway = getUltimateTargetObject (this .flyway );
9495 MigrationResolver resolver = createMigrationResolver (flyway );
9596
96- if (flywayVersion >= 52 ) {
97+ if (flywayVersion >= 90 ) {
98+ Object contextInstance = invokeConstructor ("org.flywaydb.core.api.resolver.MigrationResolver.Context" , config , null , null , null , null );
99+ return invokeMethod (resolver , "resolveMigrations" , contextInstance );
100+ } else if (flywayVersion >= 52 ) {
97101 Class <?> contextType = ClassUtils .forName ("org.flywaydb.core.api.resolver.Context" , classLoader );
98102 Object contextInstance = ProxyFactory .getProxy (contextType , (MethodInterceptor ) invocation ->
99103 "getConfiguration" .equals (invocation .getMethod ().getName ()) ? config : invocation .proceed ());
@@ -107,7 +111,21 @@ public Collection<ResolvedMigration> getMigrations() {
107111 }
108112
109113 private MigrationResolver createMigrationResolver (Flyway flyway ) throws ClassNotFoundException {
110- if (flywayVersion >= 63 ) {
114+ if (flywayVersion >= 90 ) {
115+ Object executor = getField (flyway , "flywayExecutor" );
116+ Object scanner = createScanner (flyway );
117+ Object sqlScriptFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptFactory" );
118+ Object sqlScriptExecutorFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory" );
119+ Object parsingContext = invokeConstructor ("org.flywaydb.core.internal.parser.ParsingContext" );
120+ return invokeMethod (executor , "createMigrationResolver" , scanner , scanner , sqlScriptExecutorFactory , sqlScriptFactory , parsingContext , null );
121+ } else if (flywayVersion >= 80 ) {
122+ Object executor = getField (flyway , "flywayExecutor" );
123+ Object scanner = createScanner (flyway );
124+ Object sqlScriptFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptFactory" );
125+ Object sqlScriptExecutorFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory" );
126+ Object parsingContext = invokeConstructor ("org.flywaydb.core.internal.parser.ParsingContext" );
127+ return invokeMethod (executor , "createMigrationResolver" , scanner , scanner , sqlScriptExecutorFactory , sqlScriptFactory , parsingContext );
128+ } else if (flywayVersion >= 63 ) {
111129 Object scanner = createScanner (flyway );
112130 Object sqlScriptFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptFactory" );
113131 Object sqlScriptExecutorFactory = createMock ("org.flywaydb.core.internal.sqlscript.SqlScriptExecutorFactory" );
@@ -136,6 +154,19 @@ private MigrationResolver createMigrationResolver(Flyway flyway) throws ClassNot
136154 }
137155
138156 private Object createScanner (Flyway flyway ) throws ClassNotFoundException {
157+ if (flywayVersion >= 80 ) {
158+ Object executor = getField (flyway , "flywayExecutor" );
159+ return invokeConstructor ("org.flywaydb.core.internal.scanner.Scanner" ,
160+ ClassUtils .forName ("org.flywaydb.core.api.migration.JavaMigration" , classLoader ),
161+ Arrays .asList ((Object []) invokeMethod (config , "getLocations" )),
162+ invokeMethod (config , "getClassLoader" ),
163+ invokeMethod (config , "getEncoding" ),
164+ invokeMethod (config , "isDetectEncoding" ),
165+ false ,
166+ getField (executor , "resourceNameCache" ),
167+ getField (executor , "locationScannerCache" ),
168+ invokeMethod (config , "isFailOnMissingLocations" ));
169+ }
139170 if (flywayVersion >= 79 ) {
140171 return invokeConstructor ("org.flywaydb.core.internal.scanner.Scanner" ,
141172 ClassUtils .forName ("org.flywaydb.core.api.migration.JavaMigration" , classLoader ),
@@ -305,31 +336,46 @@ public void setSqlMigrationSuffixes(List<String> sqlMigrationSuffixes) {
305336 }
306337
307338 public boolean isIgnoreMissingMigrations () {
308- if (flywayVersion >= 41 ) {
339+ if (flywayVersion >= 90 ) {
340+ Object [] patterns = getArray (config , "getIgnoreMigrationPatterns" );
341+ return patterns .length > 0 && "*" .equals (getField (patterns [patterns .length - 1 ], "migrationType" )) && "missing" .equalsIgnoreCase (getField (patterns [patterns .length - 1 ], "migrationState" ));
342+ } else if (flywayVersion >= 41 ) {
309343 return getValue (config , "isIgnoreMissingMigrations" );
310344 } else {
311345 return false ;
312346 }
313347 }
314348
315349 public void setIgnoreMissingMigrations (boolean ignoreMissingMigrations ) {
316- if (flywayVersion >= 41 ) {
350+ if (flywayVersion >= 90 ) {
351+ Object [] patterns = getArray (config , "getIgnoreMigrationPatterns" );
352+ if (isIgnoreMissingMigrations () && !ignoreMissingMigrations ) {
353+ setValue (config , "setIgnoreMigrationPatterns" , Arrays .copyOf (patterns , patterns .length - 1 ));
354+ } else if (!isIgnoreMissingMigrations () && ignoreMissingMigrations ) {
355+ try {
356+ Object ignorePattern = invokeStaticMethod ("org.flywaydb.core.api.pattern.ValidatePattern" , "fromPattern" , "*:missing" );
357+ setValue (config , "setIgnoreMigrationPatterns" , ObjectUtils .addObjectToArray (patterns , ignorePattern ));
358+ } catch (ClassNotFoundException e ) {
359+ throw new IllegalStateException ("Class not found: " + e .getMessage ());
360+ }
361+ }
362+ } else if (flywayVersion >= 41 ) {
317363 setValue (config , "setIgnoreMissingMigrations" , ignoreMissingMigrations );
318364 } else if (!Objects .equals (ignoreMissingMigrations , isIgnoreMissingMigrations ())) {
319365 throw new UnsupportedOperationException ("This method is not supported in current Flyway version" );
320366 }
321367 }
322368
323369 public boolean isIgnoreFutureMigrations () {
324- if (flywayVersion >= 40 ) {
370+ if (flywayVersion >= 40 && flywayVersion < 90 ) {
325371 return getValue (config , "isIgnoreFutureMigrations" );
326372 } else {
327373 return true ;
328374 }
329375 }
330376
331377 public void setIgnoreFutureMigrations (boolean ignoreFutureMigrations ) {
332- if (flywayVersion >= 40 ) {
378+ if (flywayVersion >= 40 && flywayVersion < 90 ) {
333379 setValue (config , "setIgnoreFutureMigrations" , ignoreFutureMigrations );
334380 } else if (!Objects .equals (ignoreFutureMigrations , isIgnoreFutureMigrations ())) {
335381 throw new UnsupportedOperationException ("This method is not supported in current Flyway version" );
@@ -344,6 +390,14 @@ public void setValidateOnMigrate(boolean validateOnMigrate) {
344390 setValue (config , "setValidateOnMigrate" , validateOnMigrate );
345391 }
346392
393+ public boolean isCleanDisabled () {
394+ return getValue (config , "isCleanDisabled" );
395+ }
396+
397+ public void setCleanDisabled (boolean cleanDisabled ) {
398+ setValue (config , "setCleanDisabled" , cleanDisabled );
399+ }
400+
347401 private static <T > T getValue (Object target , String method ) {
348402 return invokeMethod (target , method );
349403 }
0 commit comments