From 3cef4285ed24d8bec41af2400dec488903981e4a Mon Sep 17 00:00:00 2001
From: Juan Jose Garcia <juangarciavxx@gmail.com>
Date: Mon, 1 Apr 2024 12:38:31 -0500
Subject: [PATCH 1/2] Improvement in liquibase search-path handling in
 ResourceAccessor

---
 .../quarkus/liquibase/LiquibaseFactory.java   | 28 +++++++++++--------
 .../liquibase/runtime/LiquibaseConfig.java    |  3 +-
 .../LiquibaseDataSourceBuildTimeConfig.java   |  8 +++---
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/LiquibaseFactory.java b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/LiquibaseFactory.java
index dd865652bb7e3..d26d6d25c480a 100644
--- a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/LiquibaseFactory.java
+++ b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/LiquibaseFactory.java
@@ -35,21 +35,22 @@ public LiquibaseFactory(LiquibaseConfig config, DataSource datasource, String da
 
     private ResourceAccessor resolveResourceAccessor() throws FileNotFoundException {
 
-        if (config.changeLog.startsWith("classpath:")) {
-            return new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader());
-        }
-
-        if (!config.changeLog.startsWith("filesystem:") &&
-                config.searchPath.size() == 1 &&
-                config.searchPath.get(0).equals("/")) {
-            return new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader());
-        }
-
         CompositeResourceAccessor compositeResourceAccessor = new CompositeResourceAccessor();
         compositeResourceAccessor
                 .addResourceAccessor(new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader()));
 
-        for (String searchPath : config.searchPath) {
+        if (!config.changeLog.startsWith("filesystem:") && config.searchPath.isEmpty()) {
+            return compositeResourceAccessor;
+        }
+
+        if (config.searchPath.isEmpty()) {
+            compositeResourceAccessor.addResourceAccessor(
+                    new DirectoryResourceAccessor(
+                            Paths.get(StringUtil.changePrefix(config.changeLog, "filesystem:", "")).getParent()));
+            return compositeResourceAccessor;
+        }
+
+        for (String searchPath : config.searchPath.get()) {
             compositeResourceAccessor.addResourceAccessor(new DirectoryResourceAccessor(Paths.get(searchPath)));
         }
 
@@ -57,6 +58,11 @@ private ResourceAccessor resolveResourceAccessor() throws FileNotFoundException
     }
 
     private String parseChangeLog(String changeLog) {
+
+        if (changeLog.startsWith("filesystem:") && config.searchPath.isEmpty()) {
+            return Paths.get(StringUtil.changePrefix(changeLog, "filesystem:", "")).getFileName().toString();
+        }
+
         if (changeLog.startsWith("filesystem:")) {
             return StringUtil.changePrefix(changeLog, "filesystem:", "");
         }
diff --git a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseConfig.java b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseConfig.java
index b82a69fdf55a4..3af8105e1c621 100644
--- a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseConfig.java
+++ b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseConfig.java
@@ -1,7 +1,6 @@
 package io.quarkus.liquibase.runtime;
 
 import static io.quarkus.liquibase.runtime.LiquibaseDataSourceBuildTimeConfig.DEFAULT_CHANGE_LOG;
-import static io.quarkus.liquibase.runtime.LiquibaseDataSourceBuildTimeConfig.DEFAULT_SEARCH_PATH;
 import static io.quarkus.liquibase.runtime.LiquibaseDataSourceRuntimeConfig.DEFAULT_LOCK_TABLE;
 import static io.quarkus.liquibase.runtime.LiquibaseDataSourceRuntimeConfig.DEFAULT_LOG_TABLE;
 
@@ -22,7 +21,7 @@ public class LiquibaseConfig {
     /**
      * The search path for DirectoryResourceAccessor
      */
-    public List<String> searchPath = List.of(DEFAULT_SEARCH_PATH);
+    public Optional<List<String>> searchPath = Optional.empty();
 
     /**
      * The migrate at start flag
diff --git a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseDataSourceBuildTimeConfig.java b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseDataSourceBuildTimeConfig.java
index 47e7fc0000c34..f4d9c03c3ae44 100644
--- a/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseDataSourceBuildTimeConfig.java
+++ b/extensions/liquibase/runtime/src/main/java/io/quarkus/liquibase/runtime/LiquibaseDataSourceBuildTimeConfig.java
@@ -1,6 +1,7 @@
 package io.quarkus.liquibase.runtime;
 
 import java.util.List;
+import java.util.Optional;
 
 import io.quarkus.runtime.annotations.ConfigGroup;
 import io.quarkus.runtime.annotations.ConfigItem;
@@ -12,7 +13,6 @@
 public final class LiquibaseDataSourceBuildTimeConfig {
 
     static final String DEFAULT_CHANGE_LOG = "db/changeLog.xml";
-    static final String DEFAULT_SEARCH_PATH = "/";
 
     /**
      * Creates a {@link LiquibaseDataSourceBuildTimeConfig} with default settings.
@@ -22,7 +22,7 @@ public final class LiquibaseDataSourceBuildTimeConfig {
     public static final LiquibaseDataSourceBuildTimeConfig defaultConfig() {
         LiquibaseDataSourceBuildTimeConfig defaultConfig = new LiquibaseDataSourceBuildTimeConfig();
         defaultConfig.changeLog = DEFAULT_CHANGE_LOG;
-        defaultConfig.searchPath = List.of(DEFAULT_SEARCH_PATH);
+        defaultConfig.searchPath = Optional.empty();
         return defaultConfig;
     }
 
@@ -35,6 +35,6 @@ public static final LiquibaseDataSourceBuildTimeConfig defaultConfig() {
     /**
      * The search path for DirectoryResourceAccessor
      */
-    @ConfigItem(defaultValue = "/")
-    public List<String> searchPath;
+    @ConfigItem
+    public Optional<List<String>> searchPath;
 }

From b88dcfa48ce01b3622ecc0958d7f7672192634b6 Mon Sep 17 00:00:00 2001
From: Juan Jose Garcia <juangarciavxx@gmail.com>
Date: Mon, 1 Apr 2024 12:38:45 -0500
Subject: [PATCH 2/2] Improvement in liquibase-mongodb search-path handling in
 ResourceAccessor

---
 .../mongodb/LiquibaseMongodbFactory.java      | 30 ++++++++++++-------
 .../LiquibaseMongodbBuildTimeConfig.java      |  5 ++--
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/LiquibaseMongodbFactory.java b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/LiquibaseMongodbFactory.java
index ef8819d730185..0286f923a9614 100644
--- a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/LiquibaseMongodbFactory.java
+++ b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/LiquibaseMongodbFactory.java
@@ -40,21 +40,24 @@ public LiquibaseMongodbFactory(LiquibaseMongodbConfig config,
 
     private ResourceAccessor resolveResourceAccessor() throws FileNotFoundException {
 
-        if (liquibaseMongodbBuildTimeConfig.changeLog.startsWith("classpath:")) {
-            return new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader());
-        }
-
-        if (!liquibaseMongodbBuildTimeConfig.changeLog.startsWith("filesystem:") &&
-                liquibaseMongodbBuildTimeConfig.searchPath.size() == 1 &&
-                liquibaseMongodbBuildTimeConfig.searchPath.get(0).equals("/")) {
-            return new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader());
-        }
-
         CompositeResourceAccessor compositeResourceAccessor = new CompositeResourceAccessor();
         compositeResourceAccessor
                 .addResourceAccessor(new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader()));
 
-        for (String searchPath : liquibaseMongodbBuildTimeConfig.searchPath) {
+        if (!liquibaseMongodbBuildTimeConfig.changeLog.startsWith("filesystem:")
+                && liquibaseMongodbBuildTimeConfig.searchPath.isEmpty()) {
+            return compositeResourceAccessor;
+        }
+
+        if (liquibaseMongodbBuildTimeConfig.searchPath.isEmpty()) {
+            compositeResourceAccessor.addResourceAccessor(
+                    new DirectoryResourceAccessor(
+                            Paths.get(StringUtil.changePrefix(liquibaseMongodbBuildTimeConfig.changeLog, "filesystem:", ""))
+                                    .getParent()));
+            return compositeResourceAccessor;
+        }
+
+        for (String searchPath : liquibaseMongodbBuildTimeConfig.searchPath.get()) {
             compositeResourceAccessor.addResourceAccessor(new DirectoryResourceAccessor(Paths.get(searchPath)));
         }
 
@@ -62,6 +65,11 @@ private ResourceAccessor resolveResourceAccessor() throws FileNotFoundException
     }
 
     private String parseChangeLog(String changeLog) {
+
+        if (changeLog.startsWith("filesystem:") && liquibaseMongodbBuildTimeConfig.searchPath.isEmpty()) {
+            return Paths.get(StringUtil.changePrefix(changeLog, "filesystem:", "")).getFileName().toString();
+        }
+
         if (changeLog.startsWith("filesystem:")) {
             return StringUtil.changePrefix(changeLog, "filesystem:", "");
         }
diff --git a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbBuildTimeConfig.java b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbBuildTimeConfig.java
index 9267af734848b..a06832603b4af 100644
--- a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbBuildTimeConfig.java
+++ b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbBuildTimeConfig.java
@@ -1,6 +1,7 @@
 package io.quarkus.liquibase.mongodb.runtime;
 
 import java.util.List;
+import java.util.Optional;
 
 import io.quarkus.runtime.annotations.ConfigItem;
 import io.quarkus.runtime.annotations.ConfigPhase;
@@ -21,6 +22,6 @@ public class LiquibaseMongodbBuildTimeConfig {
     /**
      * The search path for DirectoryResourceAccessor
      */
-    @ConfigItem(defaultValue = "/")
-    public List<String> searchPath;
+    @ConfigItem
+    public Optional<List<String>> searchPath;
 }