Skip to content

Commit

Permalink
general changes to support flow file validation (DAT-10588) (#2986)
Browse files Browse the repository at this point in the history
add createIfNull(Map) method to CollectionUtil
expose separate validate() method in CommandScope
add constructor to CommandValidationException(Throwable)
  • Loading branch information
StevenMassaro committed Jun 22, 2022
1 parent 0418087 commit 5aacdb4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
16 changes: 11 additions & 5 deletions liquibase-core/src/main/java/liquibase/command/CommandScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import liquibase.Scope;
import liquibase.configuration.*;
import liquibase.exception.CommandExecutionException;
import liquibase.exception.CommandValidationException;
import liquibase.util.StringUtil;

import java.io.OutputStream;
Expand Down Expand Up @@ -131,11 +132,7 @@ public CommandScope setOutput(OutputStream outputStream) {
return this;
}

/**
* Executes the command in this scope, and returns the results.
*/
public CommandResults execute() throws CommandExecutionException {
CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
public void validate() throws CommandValidationException {
for (ConfigurationValueProvider provider : Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getProviders()) {
provider.validate(this);
}
Expand All @@ -151,6 +148,15 @@ public CommandResults execute() throws CommandExecutionException {
for (CommandStep step : pipeline) {
step.validate(this);
}
}

/**
* Executes the command in this scope, and returns the results.
*/
public CommandResults execute() throws CommandExecutionException {
CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
final List<CommandStep> pipeline = commandDefinition.getPipeline();
validate();
try {
for (CommandStep command : pipeline) {
command.run(resultsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public CommandValidationException(String message) {
super(message);
}

public CommandValidationException(Throwable cause) {
super(cause);
}

public CommandValidationException(String argument, String message, Throwable cause) {
super(buildMessage(argument, message), cause);
}
Expand Down
13 changes: 12 additions & 1 deletion liquibase-core/src/main/java/liquibase/util/CollectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static <T> T[] createIfNull(T[] arguments) {
}

/**
* Returns a new empty set if the passed array is null.
* Returns a new empty set if the passed set is null.
*/
public static <T> Set<T> createIfNull(Set<T> currentValue) {
if (currentValue == null) {
Expand All @@ -88,6 +88,17 @@ public static <T> Set<T> createIfNull(Set<T> currentValue) {
}
}

/**
* Returns a new empty map if the passed map is null.
*/
public static <T, E> Map<T, E> createIfNull(Map<T, E> currentValue) {
if (currentValue == null) {
return new HashMap<>();
} else {
return currentValue;
}
}

/**
* Converts a set of nested maps (like from yaml/json) into a flat map with dot-separated properties
*/
Expand Down

0 comments on commit 5aacdb4

Please sign in to comment.