Skip to content

Commit cb292a9

Browse files
committed
upgrade to flyway 7.3.0 (compile time only dependency)
1 parent 82cf183 commit cb292a9

File tree

4 files changed

+13
-39
lines changed

4 files changed

+13
-39
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ project(':embedded-database-spring-test') {
209209
compile 'mysql:mysql-connector-java:8.0.22', optional
210210
compile 'org.mariadb.jdbc:mariadb-java-client:2.7.0', optional
211211

212-
compile 'org.flywaydb:flyway-core:5.0.7', optional
213-
compile 'org.flywaydb.flyway-test-extensions:flyway-spring-test:5.0.0', optional
212+
compile 'org.flywaydb:flyway-core:7.3.0', optional
213+
compile 'org.flywaydb.flyway-test-extensions:flyway-spring-test:7.0.0', optional
214214
compile 'org.springframework.boot:spring-boot-starter-test:1.5.22.RELEASE', optional
215215
compile 'org.liquibase:liquibase-core:3.5.5', optional
216216

embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayClassUtils.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,15 @@
1818

1919
import org.apache.commons.io.IOUtils;
2020
import org.flywaydb.core.Flyway;
21-
import org.flywaydb.core.api.FlywayException;
2221
import org.slf4j.LoggerFactory;
2322
import org.springframework.core.io.ClassPathResource;
2423
import org.springframework.util.ClassUtils;
2524

26-
import static io.zonky.test.db.util.ReflectionUtils.getField;
27-
import static io.zonky.test.db.util.ReflectionUtils.invokeMethod;
28-
import static io.zonky.test.db.util.ReflectionUtils.invokeStaticMethod;
2925
import static java.nio.charset.StandardCharsets.UTF_8;
3026

3127
public class FlywayClassUtils {
3228

3329
private static final int flywayVersion = loadFlywayVersion();
34-
private static final boolean flywayPro = loadFlywayPro();
3530

3631
private FlywayClassUtils() {}
3732

@@ -53,31 +48,7 @@ private static int loadFlywayVersion() {
5348
}
5449
}
5550

56-
private static boolean loadFlywayPro() {
57-
if (flywayVersion < 50) {
58-
return false;
59-
}
60-
try {
61-
if (flywayVersion >= 60) {
62-
Object flywayConfig = invokeStaticMethod(Flyway.class, "configure");
63-
invokeMethod(flywayConfig, "undoSqlMigrationPrefix", "U");
64-
} else if (flywayVersion >= 51) {
65-
Object flywayConfig = getField(new Flyway(), "configuration");
66-
invokeMethod(flywayConfig, "setUndoSqlMigrationPrefix", "U");
67-
} else {
68-
new Flyway().setUndoSqlMigrationPrefix("U");
69-
}
70-
return true;
71-
} catch (FlywayException e) {
72-
return false;
73-
}
74-
}
75-
7651
public static int getFlywayVersion() {
7752
return flywayVersion;
7853
}
79-
80-
public static boolean isFlywayPro() {
81-
return flywayPro;
82-
}
8354
}

embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/FlywayWrapper.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.flywaydb.core.Flyway;
2222
import org.flywaydb.core.api.resolver.MigrationResolver;
2323
import org.flywaydb.core.api.resolver.ResolvedMigration;
24-
import org.flywaydb.core.internal.util.scanner.Scanner;
2524
import org.springframework.aop.framework.ProxyFactory;
2625
import org.springframework.util.ClassUtils;
2726

@@ -51,7 +50,7 @@ public static FlywayWrapper newInstance() {
5150
Object config = invokeStaticMethod(Flyway.class, "configure");
5251
return new FlywayWrapper(invokeMethod(config, "load"));
5352
} else {
54-
return new FlywayWrapper(new Flyway());
53+
return new FlywayWrapper(invokeConstructor(Flyway.class));
5554
}
5655
}
5756

@@ -100,7 +99,7 @@ public Collection<ResolvedMigration> getMigrations() {
10099
"getConfiguration".equals(invocation.getMethod().getName()) ? config : invocation.proceed());
101100
return invokeMethod(resolver, "resolveMigrations", contextInstance);
102101
} else {
103-
return resolver.resolveMigrations();
102+
return invokeMethod(resolver, "resolveMigrations");
104103
}
105104
} catch (ClassNotFoundException e) {
106105
throw new IllegalStateException("Class not found: " + e.getMessage());
@@ -129,7 +128,7 @@ private MigrationResolver createMigrationResolver(Flyway flyway) throws ClassNot
129128
Object placeholderReplacer = invokeMethod(flyway, "createPlaceholderReplacer");
130129
return invokeMethod(flyway, "createMigrationResolver", null, scanner, placeholderReplacer);
131130
} else if (flywayVersion >= 40) {
132-
Scanner scanner = new Scanner(flyway.getClassLoader());
131+
Object scanner = createScanner(flyway);
133132
return invokeMethod(flyway, "createMigrationResolver", null, scanner);
134133
} else {
135134
return invokeMethod(flyway, "createMigrationResolver", (Object) null);
@@ -191,7 +190,11 @@ private Object createScanner(Flyway flyway) throws ClassNotFoundException {
191190
invokeMethod(config, "getEncoding"));
192191
}
193192
if (flywayVersion >= 51) {
194-
return invokeConstructor(Scanner.class, config);
193+
return invokeConstructor("org.flywaydb.core.internal.util.scanner.Scanner", config);
194+
}
195+
if (flywayVersion >= 40) {
196+
return invokeConstructor("org.flywaydb.core.internal.util.scanner.Scanner",
197+
(Object) invokeMethod(config, "getClassLoader"));
195198
}
196199

197200
throw new IllegalStateException("Unsupported flyway version: " + flywayVersion);

embedded-database-spring-test/src/main/java/io/zonky/test/db/flyway/OptimizedFlywayTestExecutionListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import java.util.List;
4343
import java.util.function.Function;
4444

45-
import static org.springframework.asm.SpringAsmInfo.ASM_VERSION;
45+
import static org.springframework.asm.Opcodes.ASM6;
4646
import static org.springframework.util.ReflectionUtils.findMethod;
4747

4848
public class OptimizedFlywayTestExecutionListener implements TestExecutionListener, Ordered {
@@ -157,7 +157,7 @@ private static class ClassTransformer extends ClassVisitor {
157157
private final Function<MethodVisitor, MethodVisitor> methodReplacer;
158158

159159
private ClassTransformer(ClassWriter cw, Method method, Function<MethodVisitor, MethodVisitor> methodReplacer) {
160-
super(ASM_VERSION, cw);
160+
super(ASM6, cw);
161161
this.methodName = method.getName();
162162
this.methodDescriptor = Type.getMethodDescriptor(method);
163163
this.methodReplacer = methodReplacer;
@@ -181,7 +181,7 @@ private static class LocationsMigrationHandlingMethodReplacer extends MethodVisi
181181

182182
private LocationsMigrationHandlingMethodReplacer(MethodVisitor writer) {
183183
// now, we're not passing the writer to the superclass for our radical changes
184-
super(ASM_VERSION);
184+
super(ASM6);
185185
this.writer = writer;
186186
}
187187

0 commit comments

Comments
 (0)