Skip to content

Commit

Permalink
Merge pull request #1127 from liquibase/DAT-4575
Browse files Browse the repository at this point in the history
Report invalid format option even when no license DAT-4575
  • Loading branch information
nvoxland authored May 11, 2020
2 parents 4a8a306 + 691fece commit d061765
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public static int run(String[] args) throws LiquibaseException {
if (licenseService != null) {
if (main.liquibaseProLicenseKey == null) {
log.info(LogType.LOG,
"The command '" + main.command +
"' requires a Liquibase Pro license, available at https://www.liquibase.org/download or sales@liquibase.com");
"The command '" + main.command +
"' requires a Liquibase Pro license, available at https://www.liquibase.org/download or sales@liquibase.com");
} else {
Location licenseKeyLocation =
new Location("property liquibaseProLicenseKey", LocationType.BASE64_STRING, main.liquibaseProLicenseKey);
Expand Down Expand Up @@ -285,9 +285,9 @@ public static int run(String[] args) throws LiquibaseException {
}

if (main.commandParams.contains("--help") &&
(main.command.startsWith("rollbackOneChangeSet") ||
main.command.startsWith("rollbackOneUpdate") ||
(main.command.startsWith("diff") && main.isFormattedDiff()))) {
(main.command.startsWith("rollbackOneChangeSet") ||
main.command.startsWith("rollbackOneUpdate") ||
(main.command.startsWith("diff") && main.isFormattedDiff()))) {
//don't need to check setup
} else {
List<String> setupMessages = main.checkSetup();
Expand Down Expand Up @@ -541,8 +541,8 @@ private static boolean isStandardOutputRequired(String command) {
private static boolean isChangeLogRequired(String command) {
return command.toLowerCase().startsWith(COMMANDS.UPDATE)
|| (command.toLowerCase().startsWith(COMMANDS.ROLLBACK) &&
(!command.equalsIgnoreCase(COMMANDS.ROLLBACK_ONE_CHANGE_SET) &&
!command.equalsIgnoreCase(COMMANDS.ROLLBACK_ONE_UPDATE)))
(!command.equalsIgnoreCase(COMMANDS.ROLLBACK_ONE_CHANGE_SET) &&
!command.equalsIgnoreCase(COMMANDS.ROLLBACK_ONE_UPDATE)))
|| COMMANDS.CALCULATE_CHECKSUM.equalsIgnoreCase(command)
|| COMMANDS.STATUS.equalsIgnoreCase(command)
|| COMMANDS.VALIDATE.equalsIgnoreCase(command)
Expand Down Expand Up @@ -887,17 +887,15 @@ private void checkForUnexpectedCommandParameter(List<String> messages) {
messages.add(String.format(coreBundle.getString("unexpected.command.parameter"), cmdParm));
}
}
}
else if (COMMANDS.ROLLBACK_ONE_UPDATE.equalsIgnoreCase(command)) {
} else if (COMMANDS.ROLLBACK_ONE_UPDATE.equalsIgnoreCase(command)) {
for (String cmdParm : commandParams) {
if (!cmdParm.startsWith("--" + OPTIONS.DEPLOYMENT_ID)
&& !cmdParm.startsWith("--" + OPTIONS.HELP)
&& !cmdParm.startsWith("--" + OPTIONS.FORCE)) {
messages.add(String.format(coreBundle.getString("unexpected.command.parameter"), cmdParm));
}
}
}
else if (COMMANDS.ROLLBACK_ONE_UPDATE_SQL.equalsIgnoreCase(command)) {
} else if (COMMANDS.ROLLBACK_ONE_UPDATE_SQL.equalsIgnoreCase(command)) {
for (String cmdParm : commandParams) {
if (!cmdParm.startsWith("--" + OPTIONS.DEPLOYMENT_ID)
&& !cmdParm.startsWith("--" + OPTIONS.HELP)
Expand Down Expand Up @@ -1303,14 +1301,18 @@ protected void doMigration() throws Exception {
// Check for a valid license to run PRO commands
//
String formatValue = getCommandParam(OPTIONS.FORMAT, null);
if (COMMANDS.ROLLBACK_ONE_CHANGE_SET.equals(command) ||
COMMANDS.ROLLBACK_ONE_CHANGE_SET_SQL.equals(command) ||
COMMANDS.ROLLBACK_ONE_UPDATE.equals(command) ||
COMMANDS.ROLLBACK_ONE_UPDATE_SQL.equals(command) ||
(COMMANDS.DIFF.equals(command) && formatValue != null && ! formatValue.toLowerCase().equals("txt"))) {
if (isLicenseableCommand(formatValue)) {
if (isFormattedDiff()) {
if (formatValue != null && ! formatValue.equalsIgnoreCase("json")) {
String messageString =
"\nWARNING: The diff command optional Pro parameter '--format' " +
"currently supports only 'TXT' or 'JSON' as values. (Blank defaults to 'TXT')";
throw new LiquibaseException(String.format(messageString));
}
}
if (!commandParams.contains("--help") && !liquibaseProLicenseValid) {
String warningAboutCommand = command;
if (command.equals(COMMANDS.DIFF) && formatValue != null && ! formatValue.isEmpty()) {
if (command.equalsIgnoreCase(COMMANDS.DIFF) && formatValue != null && !formatValue.isEmpty()) {
warningAboutCommand = "diff --format=" + formatValue;
}
String messageString = String.format(coreBundle.getString("no.pro.license.found"), warningAboutCommand);
Expand Down Expand Up @@ -1386,11 +1388,11 @@ protected void doMigration() throws Exception {
diffOutputControl.addIncludedSchema(schema.getComparisonSchema());
}

if (COMMANDS.DIFF.equals(command)) {
if (COMMANDS.DIFF.equalsIgnoreCase(command)) {
if (commandParams.contains("--help")) {
System.out.println("liquibase diff" +
"\n" +
" Outputs a description of differences. If you have a Liquibase Pro key, you can output the differences as JSON using the --format=JSON option\n");
"\n" +
" Outputs a description of differences. If you have a Liquibase Pro key, you can output the differences as JSON using the --format=JSON option\n");
System.exit(0);
}
if (isFormattedDiff()) {
Expand All @@ -1404,12 +1406,11 @@ protected void doMigration() throws Exception {
argsMap.put("diffCommand", diffCommand);
((AbstractSelfConfiguratingCommand) liquibaseCommand).configure(argsMap);
liquibaseCommand.execute();
}
else {
} else {
CommandLineUtils.doDiff(
createReferenceDatabaseFromCommandParams(commandParams, fileOpener),
database,
StringUtils.trimToNull(diffTypes), finalSchemaComparisons, objectChangeFilter, new PrintStream(getOutputStream()));
createReferenceDatabaseFromCommandParams(commandParams, fileOpener),
database,
StringUtils.trimToNull(diffTypes), finalSchemaComparisons, objectChangeFilter, new PrintStream(getOutputStream()));
}
return;
} else if (COMMANDS.DIFF_CHANGELOG.equalsIgnoreCase(command)) {
Expand Down Expand Up @@ -1544,16 +1545,15 @@ protected void doMigration() throws Exception {
);
}
return;
}
else if (COMMANDS.ROLLBACK_ONE_CHANGE_SET.equals(command)) {
Map<String, Object> argsMap = new HashMap<String, Object>();
} else if (COMMANDS.ROLLBACK_ONE_CHANGE_SET.equals(command)) {
Map<String, Object> argsMap = new HashMap<>();
loadChangeSetInfoToMap(argsMap);
LiquibaseCommand liquibaseCommand = createLiquibaseCommand(database, liquibase, COMMANDS.ROLLBACK_ONE_CHANGE_SET, argsMap);
liquibaseCommand.execute();
return;
} else if (COMMANDS.ROLLBACK_ONE_CHANGE_SET_SQL.equals(command)) {
Writer outputWriter = getOutputWriter();
Map<String, Object> argsMap = new HashMap<String, Object>();
Map<String, Object> argsMap = new HashMap<>();
loadChangeSetInfoToMap(argsMap);
argsMap.put("outputWriter", outputWriter);
argsMap.put("force", true);
Expand All @@ -1563,14 +1563,14 @@ else if (COMMANDS.ROLLBACK_ONE_CHANGE_SET.equals(command)) {
outputWriter.close();
return;
} else if (COMMANDS.ROLLBACK_ONE_UPDATE.equals(command)) {
Map<String, Object> argsMap = new HashMap<String, Object>();
Map<String, Object> argsMap = new HashMap<>();
argsMap.put("deploymentId", getCommandParam(OPTIONS.DEPLOYMENT_ID, null));
LiquibaseCommand liquibaseCommand = createLiquibaseCommand(database, liquibase, COMMANDS.ROLLBACK_ONE_UPDATE, argsMap);
liquibaseCommand.execute();
return;
} else if (COMMANDS.ROLLBACK_ONE_UPDATE_SQL.equals(command)) {
Writer outputWriter = getOutputWriter();
Map<String, Object> argsMap = new HashMap<String, Object>();
Map<String, Object> argsMap = new HashMap<>();
argsMap.put("deploymentId", getCommandParam(OPTIONS.DEPLOYMENT_ID, null));
argsMap.put("outputWriter", outputWriter);
argsMap.put("force", true);
Expand Down Expand Up @@ -1766,6 +1766,14 @@ else if (COMMANDS.ROLLBACK_ONE_CHANGE_SET.equals(command)) {
}
}

private boolean isLicenseableCommand(String formatValue) {
return COMMANDS.ROLLBACK_ONE_CHANGE_SET.equalsIgnoreCase(command) ||
COMMANDS.ROLLBACK_ONE_CHANGE_SET_SQL.equalsIgnoreCase(command) ||
COMMANDS.ROLLBACK_ONE_UPDATE.equalsIgnoreCase(command) ||
COMMANDS.ROLLBACK_ONE_UPDATE_SQL.equalsIgnoreCase(command) ||
(COMMANDS.DIFF.equalsIgnoreCase(command) && formatValue != null && ! formatValue.toLowerCase().equals("txt"));
}

private void loadChangeSetInfoToMap(Map<String, Object> argsMap) throws CommandLineParsingException {
argsMap.put("changeSetId", getCommandParam(OPTIONS.CHANGE_SET_ID, null));
argsMap.put("changeSetAuthor", getCommandParam(OPTIONS.CHANGE_SET_AUTHOR, null));
Expand All @@ -1787,8 +1795,6 @@ private String getSchemaParams(Database database) throws CommandLineParsingExcep

private LiquibaseCommand createLiquibaseCommand(Database database, Liquibase liquibase, String commandName, Map<String, Object> argsMap)
throws LiquibaseException {
LiquibaseCommand liquibaseCommand = CommandFactory.getInstance().getCommand(commandName);
AbstractSelfConfiguratingCommand configuratingCommand = (AbstractSelfConfiguratingCommand) liquibaseCommand;
argsMap.put("rollbackScript", rollbackScript);
argsMap.put("changeLogFile", changeLogFile);
argsMap.put("database", database);
Expand All @@ -1809,6 +1815,8 @@ private LiquibaseCommand createLiquibaseCommand(Database database, Liquibase liq
if (this.commandParams.contains("--help")) {
argsMap.put("help", true);
}
LiquibaseCommand liquibaseCommand = CommandFactory.getInstance().getCommand(commandName);
AbstractSelfConfiguratingCommand configuratingCommand = (AbstractSelfConfiguratingCommand) liquibaseCommand;
configuratingCommand.configure(argsMap);
return liquibaseCommand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseExcepti
// Check the Pro license if --format=JSON is specified
//
if (isFormattedDiff()) {
if (format != null && ! format.equalsIgnoreCase("json")) {
String messageString =
"\nWARNING: The diff command 'diff --format=" + format + "' optional Pro parameter '--format' " +
"currently supports only 'TXT' or 'JSON' as values. (Blank defaults to 'TXT')";
throw new LiquibaseException(String.format(messageString));
}
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (!hasProLicense) {
throw new LiquibaseException("The command 'diff --format=" + format +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseExcepti
//
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (! hasProLicense) {
throw new LiquibaseException("The command 'rollbackOneChangeSet' requires a Liquibase Pro License, available at http://liquibase.org.");
throw new LiquibaseException(
"The command 'rollbackOneChangeSet' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com.");
}
Database database = liquibase.getDatabase();
LiquibaseCommand liquibaseCommand = (CommandFactory.getInstance().getCommand("rollbackOneChangeSet"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseExcepti
//
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (! hasProLicense) {
throw new LiquibaseException("The command 'rollbackOneChangeSetSQL' requires a Liquibase Pro License, available at http://liquibase.org.");
throw new LiquibaseException(
"The command 'rollbackOneChangeSetSQL' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com.");
}
Database database = liquibase.getDatabase();
LiquibaseCommand liquibaseCommand = (CommandFactory.getInstance().getCommand("rollbackOneChangeSet"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseExcepti
//
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (! hasProLicense) {
throw new LiquibaseException("The command 'rollbackOneUpdate' requires a Liquibase Pro License, available at http://liquibase.org.");
throw new LiquibaseException(
"The command 'rollbackOneUpdate' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com.");
}
Database database = liquibase.getDatabase();
LiquibaseCommand liquibaseCommand = (CommandFactory.getInstance().getCommand("rollbackOneUpdate"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseExcepti
//
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (! hasProLicense) {
throw new LiquibaseException("The command 'rollbackOneUpdateSQL' requires a Liquibase Pro License, available at http://liquibase.org.");
throw new LiquibaseException(
"The command 'rollbackOneUpdateSQL' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com.");
}
Database database = liquibase.getDatabase();
LiquibaseCommand liquibaseCommand = (CommandFactory.getInstance().getCommand("rollbackOneUpdate"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static boolean checkProLicense(String liquibaseProLicenseKey, String comm
if (liquibaseProLicenseKey == null) {
log.info("");
if (commandName != null) {
log.info("The command '" + commandName + "' requires a Liquibase Pro License, available at http://liquibase.org.");
log.info("The command '" + commandName + "' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com.");
}
log.info("");
hasProLicense = false;
Expand Down

0 comments on commit d061765

Please sign in to comment.