liquibase.integration.commandline.CommandRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
The newest version!
package liquibase.integration.commandline;
import liquibase.Scope;
import liquibase.command.CommandResults;
import liquibase.command.CommandScope;
import liquibase.command.CommonArgumentNames;
import liquibase.exception.CommandValidationException;
import liquibase.exception.MissingRequiredArgumentException;
import liquibase.io.OutputFileHandler;
import liquibase.io.OutputFileHandlerFactory;
import liquibase.util.StringUtil;
import picocli.CommandLine;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class CommandRunner implements Callable {
private CommandLine.Model.CommandSpec spec;
@Override
public CommandResults call() throws Exception {
List command = new ArrayList<>();
command.add(spec.commandLine().getCommandName());
CommandLine parentCommand = spec.commandLine().getParent();
while (!parentCommand.getCommandName().equals("liquibase")) {
command.add(0, parentCommand.getCommandName());
parentCommand = parentCommand.getParent();
}
final String[] commandName = LiquibaseCommandLine.getCommandNames(spec.commandLine());
for (int i=0; i initProjectArguments = Stream.of(CommonArgumentNames.CHANGELOG_FILE, CommonArgumentNames.URL, CommonArgumentNames.USERNAME, CommonArgumentNames.PASSWORD).map(CommonArgumentNames::getArgumentName).collect(Collectors.toSet());
throw new CommandValidationException(cve.getMessage() + (initProjectArguments.contains(((MissingRequiredArgumentException) cause).getArgumentName()) ? ". If you need to configure new liquibase project files and arguments, run the 'liquibase init project' command." : ""));
} else {
throw cve;
}
} finally {
outputFileHandler.close();
}
}
public void setSpec(CommandLine.Model.CommandSpec spec) {
this.spec = spec;
}
}