use of liquibase.configuration.core.DefaultsFileValueProvider in project liquibase by liquibase.
the class LiquibaseCommandLine method registerValueProviders.
private List<ConfigurationValueProvider> registerValueProviders(String[] args) throws IOException {
final LiquibaseConfiguration liquibaseConfiguration = Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class);
List<ConfigurationValueProvider> returnList = new ArrayList<>();
final CommandLineArgumentValueProvider argumentProvider = new CommandLineArgumentValueProvider(commandLine.parseArgs(args));
liquibaseConfiguration.registerProvider(argumentProvider);
returnList.add(argumentProvider);
final ConfiguredValue<String> defaultsFileConfig = LiquibaseCommandLineConfiguration.DEFAULTS_FILE.getCurrentConfiguredValue();
final File defaultsFile = new File(defaultsFileConfig.getValue());
if (defaultsFile.exists()) {
final DefaultsFileValueProvider fileProvider = new DefaultsFileValueProvider(defaultsFile);
liquibaseConfiguration.registerProvider(fileProvider);
returnList.add(fileProvider);
} else {
final InputStream defaultsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(defaultsFileConfig.getValue());
if (defaultsStream == null) {
Scope.getCurrentScope().getLog(getClass()).fine("Cannot find defaultsFile " + defaultsFile.getAbsolutePath());
if (!defaultsFileConfig.wasDefaultValueUsed()) {
// can't use UI since it's not configured correctly yet
System.err.println("Could not find defaults file " + defaultsFileConfig.getValue());
}
} else {
final DefaultsFileValueProvider fileProvider = new DefaultsFileValueProvider(defaultsStream, "File in classpath " + defaultsFileConfig.getValue());
liquibaseConfiguration.registerProvider(fileProvider);
returnList.add(fileProvider);
}
}
File localDefaultsFile = new File(defaultsFile.getAbsolutePath().replaceFirst(".properties$", ".local.properties"));
if (localDefaultsFile.exists()) {
final DefaultsFileValueProvider fileProvider = new DefaultsFileValueProvider(localDefaultsFile) {
@Override
public int getPrecedence() {
return super.getPrecedence() + 1;
}
};
liquibaseConfiguration.registerProvider(fileProvider);
returnList.add(fileProvider);
} else {
Scope.getCurrentScope().getLog(getClass()).fine("Cannot find local defaultsFile " + defaultsFile.getAbsolutePath());
}
return returnList;
}
Aggregations