Skip to content

Commit

Permalink
Merge pull request #502 from liquibase/DAT-16074
Browse files Browse the repository at this point in the history
[DAT-16074] Implement user friendly message for if required dependencies are not available
  • Loading branch information
vitaliimak authored Mar 19, 2024
2 parents 1a87b18 + a860644 commit 0eff364
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import liquibase.GlobalConfiguration;
import liquibase.Scope;
import liquibase.exception.DatabaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.ext.mongodb.configuration.MongoConfiguration;
import liquibase.ext.mongodb.statement.BsonUtils;
import liquibase.logging.Logger;
Expand Down Expand Up @@ -68,7 +69,42 @@ public boolean supports(String url) {
if (url == null) {
return false;
}
return url.toLowerCase().startsWith("mongodb");

boolean isMongodbConnection = url.toLowerCase().startsWith("mongodb");

showErrorMessageIfSomeRequiredDependenciesAreNotPresent(isMongodbConnection);

return isMongodbConnection;
}

private static void showErrorMessageIfSomeRequiredDependenciesAreNotPresent(boolean isMongodbConnection) {
if (isMongodbConnection) {
final String errorMessagePrefix = "The required dependencies (JAR files) are not available on the classpath:";
String errorMessage = errorMessagePrefix;

try {
Class.forName("com.mongodb.ConnectionString");
} catch (ClassNotFoundException e) {
errorMessage += "\n- mongodb-driver-core.jar";
}

try {
Class.forName("com.mongodb.client.MongoClients");
} catch (ClassNotFoundException e) {
errorMessage += "\n- mongodb-driver-sync.jar";
}

try {
Class.forName("org.bson.Transformer");
} catch (ClassNotFoundException e) {
errorMessage += "\n- bson.jar";
}

if (!errorMessage.equals(errorMessagePrefix)) {
errorMessage += "\nDownload the required dependencies and place them in the 'liquibase/lib' folder";
throw new UnexpectedLiquibaseException(errorMessage);
}
}
}

@Override
Expand Down

0 comments on commit 0eff364

Please sign in to comment.