9
9
import java .util .Map ;
10
10
import java .util .Objects ;
11
11
12
+ import static org .springframework .test .util .ReflectionTestUtils .getField ;
12
13
import static org .springframework .test .util .ReflectionTestUtils .invokeMethod ;
13
14
14
15
/**
@@ -50,7 +51,6 @@ public class FlywayConfigSnapshot {
50
51
private final String repeatableSqlMigrationPrefix ;
51
52
private final String sqlMigrationSeparator ;
52
53
private final String sqlMigrationPrefix ;
53
- private final String sqlMigrationSuffix ;
54
54
private final String placeholderPrefix ;
55
55
private final String placeholderSuffix ;
56
56
private final Object encoding ;
@@ -79,47 +79,53 @@ public class FlywayConfigSnapshot {
79
79
private final int connectRetries ;
80
80
81
81
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" );
100
106
101
107
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" );
105
111
} else {
106
112
this .baselineVersion = null ;
107
113
this .baselineDescription = null ;
108
114
this .baselineOnMigrate = false ;
109
115
}
110
116
111
117
if (flywayVersion >= 32 ) {
112
- this .placeholderReplacement = flyway . isPlaceholderReplacement ( );
118
+ this .placeholderReplacement = invokeMethod ( config , "isPlaceholderReplacement" );
113
119
} else {
114
120
this .placeholderReplacement = true ;
115
121
}
116
122
117
123
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" );
123
129
} else {
124
130
this .skipDefaultResolvers = false ;
125
131
this .skipDefaultCallbacks = false ;
@@ -129,54 +135,55 @@ public FlywayConfigSnapshot(Flyway flyway) {
129
135
}
130
136
131
137
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" );
134
140
} else {
135
141
this .ignoreMissingMigrations = false ;
136
142
this .installedBy = null ;
137
143
}
138
144
139
145
if (flywayVersion >= 41 && flywayVersion < 50 ) {
140
- this .allowMixedMigrations = invokeMethod (flyway , "isAllowMixedMigrations" );
146
+ this .allowMixedMigrations = invokeMethod (config , "isAllowMixedMigrations" );
141
147
} else {
142
148
this .allowMixedMigrations = false ;
143
149
}
144
150
145
151
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" );
148
154
} else {
149
155
this .mixed = false ;
150
156
this .group = false ;
151
157
}
152
158
153
159
if (flywayVersion >= 50 ) {
154
- this .sqlMigrationSuffixes = flyway . getSqlMigrationSuffixes ( );
160
+ this .sqlMigrationSuffixes = invokeMethod ( config , "getSqlMigrationSuffixes" );
155
161
} else {
156
- this .sqlMigrationSuffixes = null ;
162
+ String sqlMigrationSuffix = invokeMethod (config , "getSqlMigrationSuffix" );
163
+ this .sqlMigrationSuffixes = new String [] {sqlMigrationSuffix };
157
164
}
158
165
159
166
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 ;
163
170
} else {
164
171
this .undoSqlMigrationPrefix = null ;
165
172
this .errorHandlers = null ;
166
173
this .dryRun = false ;
167
174
}
168
175
169
176
if (flywayVersion >= 51 ) {
170
- this .ignoreIgnoredMigrations = invokeMethod (flyway , "isIgnoreIgnoredMigrations" );
177
+ this .ignoreIgnoredMigrations = invokeMethod (config , "isIgnoreIgnoredMigrations" );
171
178
} else {
172
179
this .ignoreIgnoredMigrations = false ;
173
180
}
174
181
175
182
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" );
180
187
} else {
181
188
this .errorOverrides = null ;
182
189
this .stream = false ;
@@ -185,17 +192,17 @@ public FlywayConfigSnapshot(Flyway flyway) {
185
192
}
186
193
187
194
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" );
191
198
} else {
192
199
this .ignorePendingMigrations = false ;
193
200
this .connectRetries = 0 ;
194
201
this .initSql = null ;
195
202
}
196
203
197
204
if (flywayVersion >= 52 && isFlywayPro ) {
198
- this .licenseKey = invokeMethod (flyway , "getLicenseKey" );
205
+ this .licenseKey = invokeMethod (config , "getLicenseKey" );
199
206
} else {
200
207
this .licenseKey = null ;
201
208
}
@@ -233,10 +240,6 @@ public boolean isSkipDefaultCallbacks() {
233
240
return skipDefaultCallbacks ;
234
241
}
235
242
236
- public String getSqlMigrationSuffix () {
237
- return sqlMigrationSuffix ;
238
- }
239
-
240
243
public String [] getSqlMigrationSuffixes () {
241
244
return sqlMigrationSuffixes ;
242
245
}
@@ -421,7 +424,6 @@ public boolean equals(Object o) {
421
424
Objects .equals (repeatableSqlMigrationPrefix , that .repeatableSqlMigrationPrefix ) &&
422
425
Objects .equals (sqlMigrationSeparator , that .sqlMigrationSeparator ) &&
423
426
Objects .equals (sqlMigrationPrefix , that .sqlMigrationPrefix ) &&
424
- Objects .equals (sqlMigrationSuffix , that .sqlMigrationSuffix ) &&
425
427
Objects .equals (placeholderPrefix , that .placeholderPrefix ) &&
426
428
Objects .equals (placeholderSuffix , that .placeholderSuffix ) &&
427
429
Objects .equals (encoding , that .encoding ) &&
@@ -438,8 +440,8 @@ public int hashCode() {
438
440
Arrays .hashCode (sqlMigrationSuffixes ), Arrays .hashCode (errorOverrides ),
439
441
baselineVersion , target , placeholders , table , baselineDescription ,
440
442
undoSqlMigrationPrefix , repeatableSqlMigrationPrefix ,
441
- sqlMigrationSeparator , sqlMigrationPrefix , sqlMigrationSuffix ,
442
- placeholderPrefix , placeholderSuffix , encoding , initSql , licenseKey ,
443
+ sqlMigrationSeparator , sqlMigrationPrefix , placeholderPrefix ,
444
+ placeholderSuffix , encoding , initSql , licenseKey ,
443
445
skipDefaultResolvers , skipDefaultCallbacks , placeholderReplacement , baselineOnMigrate ,
444
446
outOfOrder , ignoreMissingMigrations , ignoreIgnoredMigrations , ignorePendingMigrations ,
445
447
ignoreFutureMigrations , validateOnMigrate , cleanOnValidationError , cleanDisabled ,
0 commit comments