99import java .util .Map ;
1010import java .util .Objects ;
1111
12+ import static org .springframework .test .util .ReflectionTestUtils .getField ;
1213import static org .springframework .test .util .ReflectionTestUtils .invokeMethod ;
1314
1415/**
@@ -50,7 +51,6 @@ public class FlywayConfigSnapshot {
5051 private final String repeatableSqlMigrationPrefix ;
5152 private final String sqlMigrationSeparator ;
5253 private final String sqlMigrationPrefix ;
53- private final String sqlMigrationSuffix ;
5454 private final String placeholderPrefix ;
5555 private final String placeholderSuffix ;
5656 private final Object encoding ;
@@ -79,47 +79,53 @@ public class FlywayConfigSnapshot {
7979 private final int connectRetries ;
8080
8181 public FlywayConfigSnapshot (Flyway flyway ) {
82- this .classLoader = flyway .getClassLoader ();
83- this .dataSource = flyway .getDataSource ();
84- this .resolvers = flyway .getResolvers ();
85- this .callbacks = invokeMethod (flyway , "getCallbacks" );
86- this .sqlMigrationSuffix = flyway .getSqlMigrationSuffix ();
87- this .sqlMigrationSeparator = flyway .getSqlMigrationSeparator ();
88- this .sqlMigrationPrefix = flyway .getSqlMigrationPrefix ();
89- this .placeholderSuffix = flyway .getPlaceholderSuffix ();
90- this .placeholderPrefix = flyway .getPlaceholderPrefix ();
91- this .placeholders = flyway .getPlaceholders ();
92- this .target = flyway .getTarget ();
93- this .table = flyway .getTable ();
94- this .schemas = flyway .getSchemas ();
95- this .encoding = invokeMethod (flyway , "getEncoding" );
96- this .locations = invokeMethod (flyway , "getLocations" );
97- this .outOfOrder = flyway .isOutOfOrder ();
98- this .validateOnMigrate = flyway .isValidateOnMigrate ();
99- this .cleanOnValidationError = flyway .isCleanOnValidationError ();
82+ final Object config ;
83+ if (flywayVersion >= 51 ) {
84+ config = getField (flyway , "configuration" );
85+ } else {
86+ config = flyway ;
87+ }
88+
89+ this .classLoader = invokeMethod (config , "getClassLoader" );
90+ this .dataSource = invokeMethod (config , "getDataSource" );
91+ this .resolvers = invokeMethod (config , "getResolvers" );
92+ this .callbacks = invokeMethod (config , "getCallbacks" );
93+ this .sqlMigrationSeparator = invokeMethod (config , "getSqlMigrationSeparator" );
94+ this .sqlMigrationPrefix = invokeMethod (config , "getSqlMigrationPrefix" );
95+ this .placeholderSuffix = invokeMethod (config , "getPlaceholderSuffix" );
96+ this .placeholderPrefix = invokeMethod (config , "getPlaceholderPrefix" );
97+ this .placeholders = invokeMethod (config , "getPlaceholders" );
98+ this .target = invokeMethod (config , "getTarget" );
99+ this .table = invokeMethod (config , "getTable" );
100+ this .schemas = invokeMethod (config , "getSchemas" );
101+ this .encoding = invokeMethod (config , "getEncoding" );
102+ this .locations = invokeMethod (config , "getLocations" );
103+ this .outOfOrder = invokeMethod (config , "isOutOfOrder" );
104+ this .validateOnMigrate = invokeMethod (config , "isValidateOnMigrate" );
105+ this .cleanOnValidationError = invokeMethod (config , "isCleanOnValidationError" );
100106
101107 if (flywayVersion >= 31 ) {
102- this .baselineVersion = flyway . getBaselineVersion ( );
103- this .baselineDescription = flyway . getBaselineDescription ( );
104- this .baselineOnMigrate = flyway . isBaselineOnMigrate ( );
108+ this .baselineVersion = invokeMethod ( config , "getBaselineVersion" );
109+ this .baselineDescription = invokeMethod ( config , "getBaselineDescription" );
110+ this .baselineOnMigrate = invokeMethod ( config , "isBaselineOnMigrate" );
105111 } else {
106112 this .baselineVersion = null ;
107113 this .baselineDescription = null ;
108114 this .baselineOnMigrate = false ;
109115 }
110116
111117 if (flywayVersion >= 32 ) {
112- this .placeholderReplacement = flyway . isPlaceholderReplacement ( );
118+ this .placeholderReplacement = invokeMethod ( config , "isPlaceholderReplacement" );
113119 } else {
114120 this .placeholderReplacement = true ;
115121 }
116122
117123 if (flywayVersion >= 40 ) {
118- this .skipDefaultResolvers = flyway . isSkipDefaultResolvers ( );
119- this .skipDefaultCallbacks = flyway . isSkipDefaultCallbacks ( );
120- this .repeatableSqlMigrationPrefix = flyway . getRepeatableSqlMigrationPrefix ( );
121- this .ignoreFutureMigrations = flyway . isIgnoreFutureMigrations ( );
122- this .cleanDisabled = flyway . isCleanDisabled ( );
124+ this .skipDefaultResolvers = invokeMethod ( config , "isSkipDefaultResolvers" );
125+ this .skipDefaultCallbacks = invokeMethod ( config , "isSkipDefaultCallbacks" );
126+ this .repeatableSqlMigrationPrefix = invokeMethod ( config , "getRepeatableSqlMigrationPrefix" );
127+ this .ignoreFutureMigrations = invokeMethod ( config , "isIgnoreFutureMigrations" );
128+ this .cleanDisabled = invokeMethod ( config , "isCleanDisabled" );
123129 } else {
124130 this .skipDefaultResolvers = false ;
125131 this .skipDefaultCallbacks = false ;
@@ -129,54 +135,55 @@ public FlywayConfigSnapshot(Flyway flyway) {
129135 }
130136
131137 if (flywayVersion >= 41 ) {
132- this .ignoreMissingMigrations = flyway . isIgnoreMissingMigrations ( );
133- this .installedBy = flyway . getInstalledBy ( );
138+ this .ignoreMissingMigrations = invokeMethod ( config , "isIgnoreMissingMigrations" );
139+ this .installedBy = invokeMethod ( config , "getInstalledBy" );
134140 } else {
135141 this .ignoreMissingMigrations = false ;
136142 this .installedBy = null ;
137143 }
138144
139145 if (flywayVersion >= 41 && flywayVersion < 50 ) {
140- this .allowMixedMigrations = invokeMethod (flyway , "isAllowMixedMigrations" );
146+ this .allowMixedMigrations = invokeMethod (config , "isAllowMixedMigrations" );
141147 } else {
142148 this .allowMixedMigrations = false ;
143149 }
144150
145151 if (flywayVersion >= 42 ) {
146- this .mixed = flyway . isMixed ( );
147- this .group = flyway . isGroup ( );
152+ this .mixed = invokeMethod ( config , "isMixed" );
153+ this .group = invokeMethod ( config , "isGroup" );
148154 } else {
149155 this .mixed = false ;
150156 this .group = false ;
151157 }
152158
153159 if (flywayVersion >= 50 ) {
154- this .sqlMigrationSuffixes = flyway . getSqlMigrationSuffixes ( );
160+ this .sqlMigrationSuffixes = invokeMethod ( config , "getSqlMigrationSuffixes" );
155161 } else {
156- this .sqlMigrationSuffixes = null ;
162+ String sqlMigrationSuffix = invokeMethod (config , "getSqlMigrationSuffix" );
163+ this .sqlMigrationSuffixes = new String [] {sqlMigrationSuffix };
157164 }
158165
159166 if (flywayVersion >= 50 && isFlywayPro ) {
160- this .undoSqlMigrationPrefix = flyway . getUndoSqlMigrationPrefix ( );
161- this .errorHandlers = flyway . getErrorHandlers ( );
162- this .dryRun = flyway . getDryRunOutput ( ) != null ;
167+ this .undoSqlMigrationPrefix = invokeMethod ( config , "getUndoSqlMigrationPrefix" );
168+ this .errorHandlers = invokeMethod ( config , "getErrorHandlers" );
169+ this .dryRun = invokeMethod ( config , "getDryRunOutput" ) != null ;
163170 } else {
164171 this .undoSqlMigrationPrefix = null ;
165172 this .errorHandlers = null ;
166173 this .dryRun = false ;
167174 }
168175
169176 if (flywayVersion >= 51 ) {
170- this .ignoreIgnoredMigrations = invokeMethod (flyway , "isIgnoreIgnoredMigrations" );
177+ this .ignoreIgnoredMigrations = invokeMethod (config , "isIgnoreIgnoredMigrations" );
171178 } else {
172179 this .ignoreIgnoredMigrations = false ;
173180 }
174181
175182 if (flywayVersion >= 51 && isFlywayPro ) {
176- this .errorOverrides = invokeMethod (flyway , "getErrorOverrides" );
177- this .stream = invokeMethod (flyway , "isStream" );
178- this .batch = invokeMethod (flyway , "isBatch" );
179- this .oracleSqlPlus = invokeMethod (flyway , "isOracleSqlplus" );
183+ this .errorOverrides = invokeMethod (config , "getErrorOverrides" );
184+ this .stream = invokeMethod (config , "isStream" );
185+ this .batch = invokeMethod (config , "isBatch" );
186+ this .oracleSqlPlus = invokeMethod (config , "isOracleSqlplus" );
180187 } else {
181188 this .errorOverrides = null ;
182189 this .stream = false ;
@@ -185,17 +192,17 @@ public FlywayConfigSnapshot(Flyway flyway) {
185192 }
186193
187194 if (flywayVersion >= 52 ) {
188- this .ignorePendingMigrations = invokeMethod (flyway , "isIgnorePendingMigrations" );
189- this .connectRetries = invokeMethod (flyway , "getConnectRetries" );
190- this .initSql = invokeMethod (flyway , "getInitSql" );
195+ this .ignorePendingMigrations = invokeMethod (config , "isIgnorePendingMigrations" );
196+ this .connectRetries = invokeMethod (config , "getConnectRetries" );
197+ this .initSql = invokeMethod (config , "getInitSql" );
191198 } else {
192199 this .ignorePendingMigrations = false ;
193200 this .connectRetries = 0 ;
194201 this .initSql = null ;
195202 }
196203
197204 if (flywayVersion >= 52 && isFlywayPro ) {
198- this .licenseKey = invokeMethod (flyway , "getLicenseKey" );
205+ this .licenseKey = invokeMethod (config , "getLicenseKey" );
199206 } else {
200207 this .licenseKey = null ;
201208 }
@@ -233,10 +240,6 @@ public boolean isSkipDefaultCallbacks() {
233240 return skipDefaultCallbacks ;
234241 }
235242
236- public String getSqlMigrationSuffix () {
237- return sqlMigrationSuffix ;
238- }
239-
240243 public String [] getSqlMigrationSuffixes () {
241244 return sqlMigrationSuffixes ;
242245 }
@@ -421,7 +424,6 @@ public boolean equals(Object o) {
421424 Objects .equals (repeatableSqlMigrationPrefix , that .repeatableSqlMigrationPrefix ) &&
422425 Objects .equals (sqlMigrationSeparator , that .sqlMigrationSeparator ) &&
423426 Objects .equals (sqlMigrationPrefix , that .sqlMigrationPrefix ) &&
424- Objects .equals (sqlMigrationSuffix , that .sqlMigrationSuffix ) &&
425427 Objects .equals (placeholderPrefix , that .placeholderPrefix ) &&
426428 Objects .equals (placeholderSuffix , that .placeholderSuffix ) &&
427429 Objects .equals (encoding , that .encoding ) &&
@@ -438,8 +440,8 @@ public int hashCode() {
438440 Arrays .hashCode (sqlMigrationSuffixes ), Arrays .hashCode (errorOverrides ),
439441 baselineVersion , target , placeholders , table , baselineDescription ,
440442 undoSqlMigrationPrefix , repeatableSqlMigrationPrefix ,
441- sqlMigrationSeparator , sqlMigrationPrefix , sqlMigrationSuffix ,
442- placeholderPrefix , placeholderSuffix , encoding , initSql , licenseKey ,
443+ sqlMigrationSeparator , sqlMigrationPrefix , placeholderPrefix ,
444+ placeholderSuffix , encoding , initSql , licenseKey ,
443445 skipDefaultResolvers , skipDefaultCallbacks , placeholderReplacement , baselineOnMigrate ,
444446 outOfOrder , ignoreMissingMigrations , ignoreIgnoredMigrations , ignorePendingMigrations ,
445447 ignoreFutureMigrations , validateOnMigrate , cleanOnValidationError , cleanDisabled ,
0 commit comments