Skip to content

Commit

Permalink
Add more lenient Liquibase ZipPathHandler to work around includeAll n…
Browse files Browse the repository at this point in the history
…ot working in prod mode

Workaround until liquibase/liquibase#3524 is fixed
  • Loading branch information
famod committed Mar 16, 2023
1 parent 012085e commit c33b9b7
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.liquibase;

import java.io.FileNotFoundException;

import liquibase.resource.ResourceAccessor;
import liquibase.resource.ZipPathHandler;

// https://github.com/liquibase/liquibase/issues/3524#issuecomment-1465282155
public class LiquibaseLenientZipPathHandler extends ZipPathHandler {

@Override
public int getPriority(String root) {
if (root != null && root.startsWith("jar:") && root.contains("!/")) {
return PRIORITY_SPECIALIZED;
}
return PRIORITY_NOT_APPLICABLE;
}

@Override
public ResourceAccessor getResourceAccessor(String root) throws FileNotFoundException {
int idx = root.indexOf("!/");
return super.getResourceAccessor(idx > 0 ? root.substring(0, idx) : root);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.liquibase.LiquibaseLenientZipPathHandler
32 changes: 32 additions & 0 deletions integration-tests/liquibase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<artifactId>quarkus-integration-test-liquibase</artifactId>
<name>Quarkus - Integration Tests - Liquibase</name>
<description>Module that contains Liquibase related tests</description>

<properties>
<skipTests>false</skipTests>
<skipPMTests>${skipTests}</skipPMTests>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -35,6 +41,11 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-h2</artifactId>
Expand Down Expand Up @@ -126,6 +137,27 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<!--
The prod mode tests need to be part of a different execution to ensure that they don't mess with the standard tests.
By adding this configuration we ensure that the maven surefire plugin will execute twice, one for the regular **/*Test.java
tests (using the 'default-test' execution), and one for the prod mode tests (this 'prod-mode' execution)
-->
<execution>
<id>prod-mode</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>**/*PMT.java</includes>
<skip>${skipPMTests}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.it.liquibase;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.LogFile;
import io.quarkus.test.QuarkusProdModeTest;

public class LiquibaseFunctionalityPMT {

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot(jar -> jar
.addClasses(LiquibaseApp.class, LiquibaseFunctionalityResource.class)
.addAsResource("db")
.addAsResource("application.properties"))
.setApplicationName("liquibase-prodmode-test")
.setLogFileName("liquibase-prodmode-test.log")
.setRun(true);

@LogFile
private Path logfile;

@Test
public void test() {
LiquibaseFunctionalityTest.doTestLiquibaseQuarkusFunctionality(true);
}

@AfterEach
void dumpLog() throws IOException {
System.out.println(Files.readString(logfile));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ public class LiquibaseFunctionalityTest {
@Test
@DisplayName("Migrates a schema correctly using integrated instance")
public void testLiquibaseQuarkusFunctionality() {
doTestLiquibaseQuarkusFunctionality(isIncludeAllExpectedToWork());
}

static void doTestLiquibaseQuarkusFunctionality(boolean isIncludeAllExpectedToWork) {
when()
.get("/liquibase/update")
.then()
.body(is(
"create-tables-1,test-1,create-view-inline,create-view-file-abs,create-view-file-rel,"
+ (isIncludeAllExpectedToWork() ? "includeAll-1,includeAll-2," : "")
+ (isIncludeAllExpectedToWork ? "includeAll-1,includeAll-2," : "")
+ "json-create-tables-1,json-test-1,"
+ "sql-create-tables-1,sql-test-1,"
+ "yaml-create-tables-1,yaml-test-1,"
Expand Down

0 comments on commit c33b9b7

Please sign in to comment.