-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
AbstractLiquibaseFlowMojo.java
67 lines (59 loc) · 2.34 KB
/
AbstractLiquibaseFlowMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.liquibase.maven.plugins;
import liquibase.Liquibase;
import liquibase.Scope;
import liquibase.command.CommandScope;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.exception.CommandExecutionException;
import liquibase.exception.LiquibaseException;
import org.liquibase.maven.property.PropertyElement;
import org.liquibase.maven.provider.FlowCommandArgumentValueProvider;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Map;
public abstract class AbstractLiquibaseFlowMojo extends AbstractLiquibaseMojo {
/**
* Specifies the <i>flowFile</i> to use. If not specified, the default
* checks will be used and no file will be created.
*
* @parameter property="liquibase.flowFile"
*/
@PropertyElement
protected String flowFile;
/**
* @parameter property="liquibase.outputFile"
*/
@PropertyElement
protected File outputFile;
/**
* Arbitrary map of parameters that the underlying liquibase command will use. These arguments will be passed
* verbatim to the underlying liquibase command that is being run.
*
* @parameter property="flowCommandArguments"
*/
@PropertyElement
protected Map<String, Object> flowCommandArguments;
@Override
public boolean databaseConnectionRequired() {
return false;
}
@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
CommandScope liquibaseCommand = new CommandScope(getCommandName());
liquibaseCommand.addArgumentValue("flowFile", flowFile);
liquibaseCommand.addArgumentValue("flowIntegration", "maven");
if (flowCommandArguments != null) {
FlowCommandArgumentValueProvider flowCommandArgumentValueProvider = new FlowCommandArgumentValueProvider(flowCommandArguments);
Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).registerProvider(flowCommandArgumentValueProvider);
}
if (outputFile != null) {
try {
liquibaseCommand.setOutput(new FileOutputStream(outputFile));
} catch (FileNotFoundException e) {
throw new CommandExecutionException(e);
}
}
liquibaseCommand.execute();
}
public abstract String[] getCommandName();
}