Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path normalization breaks classpath-relative paths with a custom ResourceAccessor #5878

Open
2 tasks done
andrus opened this issue May 5, 2024 · 1 comment · May be fixed by #5894
Open
2 tasks done

Path normalization breaks classpath-relative paths with a custom ResourceAccessor #5878

andrus opened this issue May 5, 2024 · 1 comment · May be fixed by #5894

Comments

@andrus
Copy link

andrus commented May 5, 2024

Search first

  • I searched and no similar issues were found

Description

I am trying again to upgrade Bootique.io framework to Liquibase 4.x from 3.x. An earlier issue #3105 was fixed in LB 4.17, and helped us to move forward. However, there are still a few places where the base path of a resource is altered, so the relative resources can not be properly resolved inside a custom ResourceAccessor. The culprit is stripping the classpath: prefix during path normalization. So this change to DatabaseChangeLog.normalizePath(..) fixes everything for me:

--- a/liquibase-standard/src/main/java/liquibase/changelog/DatabaseChangeLog.java
+++ b/liquibase-standard/src/main/java/liquibase/changelog/DatabaseChangeLog.java
@@ -1028,10 +1028,6 @@ public class DatabaseChangeLog implements Comparable<DatabaseChangeLog>, Conditi
             return null;
         }

-        if (filePath.startsWith("classpath:")) {
-            filePath = filePath.substring("classpath:".length());
-        }
-
         if (filePath.contains("\\")) {
             filePath = filePath.replace("\\", "/");
         }

But I suspect such a change may break things elsewhere, so not sending a PR just yet 😀 Instead, let me point to some of the call spots for normalizePath(..) that resulted in broken relative resources, and maybe someone can suggest a proper solution, such as an alternative normalize method that preserves the "protocol" prefix in paths:

Steps To Reproduce

This test on branch 123 fails: https://github.com/bootique/bootique-jdbc/blob/123/bootique-jdbc-junit5-derby/src/test/java/io/bootique/jdbc/junit5/derby/DerbyTester_Liquibase_RelativeIT.java

git clone git@github.com:bootique/bootique-jdbc.git
cd bootique-jdbc
git checkout -b 123 origin/123
mvn clean verify
Caused by: liquibase.exception.LiquibaseException: Error parsing classpath:io/bootique/jdbc/junit5/derby/DerbyTester_Liquibase_RelativeIT-changelog.yml : java.io.FileNotFoundException: /Users/andrus/work/bootique/bootique-jdbc/bootique-jdbc-junit5-derby/io/bootique/jdbc/junit5/derby/changelogs/changelog.sql (No such file or directory)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:987)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:907)
at io.bootique.jdbc.liquibase.LiquibaseRunner.lambda$createDatabaseChangeLog$0(LiquibaseRunner.java:108)
... 17 more
Caused by: liquibase.exception.ChangeLogParseException: Error parsing classpath:io/bootique/jdbc/junit5/derby/DerbyTester_Liquibase_RelativeIT-changelog.yml : java.io.FileNotFoundException: /Users/andrus/work/bootique/bootique-jdbc/bootique-jdbc-junit5-derby/io/bootique/jdbc/junit5/derby/changelogs/changelog.sql (No such file or directory)
at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:96)
at liquibase.changelog.DatabaseChangeLog.lambda$include$4(DatabaseChangeLog.java:957)
at liquibase.Scope.child(Scope.java:199)
at liquibase.Scope.child(Scope.java:175)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:956)
... 19 more
Caused by: liquibase.exception.SetupException: java.io.FileNotFoundException: /Users/andrus/work/bootique/bootique-jdbc/bootique-jdbc-junit5-derby/io/bootique/jdbc/junit5/derby/changelogs/changelog.sql (No such file or directory)
at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:465)
at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:390)
at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:90)
... 23 more
Caused by: liquibase.exception.LiquibaseException: java.io.FileNotFoundException: /Users/andrus/work/bootique/bootique-jdbc/bootique-jdbc-junit5-derby/io/bootique/jdbc/junit5/derby/changelogs/changelog.sql (No such file or directory)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:987)
at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:455)
... 25 more
Caused by: liquibase.exception.ChangeLogParseException: java.io.FileNotFoundException: /Users/andrus/work/bootique/bootique-jdbc/bootique-jdbc-junit5-derby/io/bootique/jdbc/junit5/derby/changelogs/changelog.sql (No such file or directory)
at liquibase.parser.core.sql.SqlChangeLogParser.parse(SqlChangeLogParser.java:54)
at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:959)
... 26 more

Expected/Desired Behavior

The framework code setting DatabaseChangeLog.physicalFilePath (either via constructor or setter) should not strip an optional "protocol" (such as classpath:) from the path. This will allow to apply the same protocol to relative child resources.

Liquibase Version

4.27.0

Database Vendor & Version

No response

Liquibase Integration

Bootique.io

Liquibase Extensions

No response

OS and/or Infrastructure Type/Provider

No response

Additional Context

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR (Thank you!)
@tati-qalified
Copy link
Contributor

tati-qalified commented May 7, 2024

Hi @andrus, thank you for reporting this issue.
This is a complex topic, as some users need the classpath: to be stripped when normalizing the path, and others need it to not be stripped.

But I suspect such a change may break things elsewhere, so not sending a PR just yet 😀

I'd recommend the opposite, considering that you have a possible solution - if you submit a PR we can test it and see what/if it breaks. Our development team is always available to provide guidance or discuss changes if needed.

Please consider submitting a PR, and let me know if you have any questions.
Thank you!
Tatiana

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants