Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1708 from liquibase/LB-1249-hooks
Command Framework : Hooks Edition
- Loading branch information
Showing
209 changed files
with
12,650 additions
and
2,406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
liquibase-core/src/main/java/liquibase/command/AbstractCliWrapperCommandStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package liquibase.command; | ||
|
||
import liquibase.Scope; | ||
import liquibase.configuration.ConfiguredValue; | ||
import liquibase.configuration.LiquibaseConfiguration; | ||
import liquibase.exception.CommandExecutionException; | ||
import liquibase.integration.IntegrationConfiguration; | ||
import liquibase.util.StringUtil; | ||
|
||
import java.util.*; | ||
import java.util.logging.Level; | ||
|
||
/** | ||
* Convenience base class for {@link CommandStep}s that simply wrap calls to {@link liquibase.integration.commandline.Main} | ||
* | ||
* @deprecated | ||
*/ | ||
public abstract class AbstractCliWrapperCommandStep extends AbstractCommandStep { | ||
|
||
protected String[] createArgs(CommandScope commandScope) throws CommandExecutionException { | ||
return createArgs(commandScope, new ArrayList<String>()); | ||
} | ||
|
||
protected String[] createArgs(CommandScope commandScope, List<String> rhsArgs) throws CommandExecutionException { | ||
List<String> argsList = new ArrayList<>(); | ||
Map<String, CommandArgumentDefinition<?>> arguments = commandScope.getCommand().getArguments(); | ||
arguments.entrySet().forEach( arg -> { | ||
if (rhsArgs.contains(arg.getKey())) { | ||
return; | ||
} | ||
String argValue = (commandScope.getArgumentValue(arg.getValue()) != null ? commandScope.getArgumentValue(arg.getValue()).toString() : null); | ||
if (argValue != null) { | ||
argsList.add("--" + arg.getKey() + "=" + commandScope.getArgumentValue(arg.getValue()).toString()); | ||
} | ||
}); | ||
|
||
|
||
final Level logLevel = IntegrationConfiguration.LOG_LEVEL.getCurrentValue(); | ||
if (logLevel != null) { | ||
argsList.add("--logLevel=" + logLevel); | ||
} | ||
|
||
String classpath = IntegrationConfiguration.CLASSPATH.getCurrentValue(); | ||
if (classpath != null) { | ||
argsList.add("--classpath=" + classpath); | ||
} | ||
|
||
argsList.add(commandScope.getCommand().getName()[0]); | ||
if (! rhsArgs.isEmpty()) { | ||
arguments.entrySet().forEach(arg -> { | ||
if (!rhsArgs.contains(arg.getKey())) { | ||
return; | ||
} | ||
String argValue = (commandScope.getArgumentValue(arg.getValue()) != null ? commandScope.getArgumentValue(arg.getValue()).toString() : null); | ||
if (argValue != null) { | ||
argsList.add("--" + arg.getKey() + "=" + commandScope.getArgumentValue(arg.getValue()).toString()); | ||
} | ||
}); | ||
} | ||
String[] args = new String[argsList.size()]; | ||
argsList.toArray(args); | ||
return args; | ||
} | ||
|
||
protected String[] createParametersFromArgs(String[] args, String ... params) { | ||
List<String> argsList = new ArrayList(Arrays.asList(args)); | ||
List<String> toRemove = new ArrayList<>(); | ||
List<String> matchingArgs = new ArrayList<>(); | ||
for (String arg : argsList) { | ||
for (String paramName : params) { | ||
if (arg.startsWith(paramName) || arg.startsWith("--" + paramName)) { | ||
String trimmed = arg.trim(); | ||
if (trimmed.charAt(trimmed.length()-1) == '=') { | ||
trimmed = trimmed.replaceAll("=",""); | ||
} | ||
if (paramName.startsWith("--")) { | ||
matchingArgs.add(trimmed); | ||
} else { | ||
String[] parts = trimmed.split("="); | ||
if (parts.length > 1) { | ||
matchingArgs.add(parts[1]); | ||
} else { | ||
matchingArgs.add(trimmed); | ||
} | ||
} | ||
toRemove.add(arg); | ||
} | ||
} | ||
} | ||
|
||
// | ||
// Special handling for command parameters | ||
// | ||
if (matchingArgs.size() > 0) { | ||
argsList.removeAll(toRemove); | ||
argsList.remove(Collections.singleton(null)); | ||
args = new String[argsList.size() + matchingArgs.size()]; | ||
for (int i=0; i < argsList.size(); i++) { | ||
args[i] = argsList.get(i); | ||
} | ||
|
||
int l = args.length - matchingArgs.size(); | ||
for (String matchingArg : matchingArgs) { | ||
args[l] = matchingArg; | ||
l++; | ||
} | ||
} | ||
return args; | ||
} | ||
|
||
protected void addStatusMessage(CommandResultsBuilder resultsBuilder, int statusCode) { | ||
if (statusCode == 0) { | ||
resultsBuilder.addResult("statusMessage", "Successfully executed " + getName()[0]); | ||
} | ||
else { | ||
resultsBuilder.addResult("statusMessage", "Unsuccessfully executed " + getName()[0]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
liquibase-core/src/main/java/liquibase/command/AbstractCommandStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package liquibase.command; | ||
|
||
import liquibase.exception.CommandValidationException; | ||
import liquibase.util.StringUtil; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Convenience base class for {@link CommandStep} implementations. | ||
*/ | ||
public abstract class AbstractCommandStep implements CommandStep { | ||
|
||
/** | ||
* @return {@link #ORDER_DEFAULT} if the command scope's name matches {@link #getName()}. Otherwise {@link #ORDER_NOT_APPLICABLE} | ||
*/ | ||
@Override | ||
public int getOrder(CommandDefinition commandDefinition) { | ||
final String[] thisCommandName = getName(); | ||
|
||
if ((thisCommandName != null) && StringUtil.join(Arrays.asList(thisCommandName), " ").equalsIgnoreCase(StringUtil.join(Arrays.asList(commandDefinition.getName()), " "))) { | ||
return ORDER_DEFAULT; | ||
} else { | ||
return ORDER_NOT_APPLICABLE; | ||
} | ||
} | ||
|
||
/** | ||
* Default implementation does no validation. | ||
*/ | ||
@Override | ||
public void validate(CommandScope commandScope) throws CommandValidationException { | ||
} | ||
|
||
/** | ||
* Default implementation makes no changes | ||
*/ | ||
@Override | ||
public void adjustCommandDefinition(CommandDefinition commandDefinition) { | ||
|
||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
liquibase-core/src/main/java/liquibase/command/AbstractSelfConfiguratingCommand.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.