use of liquibase.configuration.GlobalConfiguration in project liquibase by liquibase.
the class BaseLiquibaseTask method shouldRun.
protected boolean shouldRun() {
LiquibaseConfiguration configuration = LiquibaseConfiguration.getInstance();
GlobalConfiguration globalConfiguration = configuration.getConfiguration(GlobalConfiguration.class);
if (!globalConfiguration.getShouldRun()) {
log("Liquibase did not run because " + configuration.describeValueLookupLogic(globalConfiguration.getProperty(GlobalConfiguration.SHOULD_RUN)) + " was set to false", Project.MSG_INFO);
return false;
}
return true;
}
use of liquibase.configuration.GlobalConfiguration in project liquibase by liquibase.
the class BaseLiquibaseTask method createPrintStream.
/**
* @deprecated Subclasses of this class should either instantiate their own output writers or use
* {@link liquibase.integration.ant.AbstractChangeLogBasedTask} if the task involves a change log.
*/
@Deprecated
public PrintStream createPrintStream() throws IOException {
if (getOutputFile() == null) {
return null;
}
GlobalConfiguration globalConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
String encoding = globalConfiguration.getOutputEncoding();
return new PrintStream(getOutputFile().getOutputStream(), false, encoding);
}
use of liquibase.configuration.GlobalConfiguration in project liquibase by liquibase.
the class BaseLiquibaseTask method getDefaultOutputEncoding.
protected String getDefaultOutputEncoding() {
LiquibaseConfiguration liquibaseConfiguration = LiquibaseConfiguration.getInstance();
GlobalConfiguration globalConfiguration = liquibaseConfiguration.getConfiguration(GlobalConfiguration.class);
return globalConfiguration.getOutputEncoding();
}
use of liquibase.configuration.GlobalConfiguration in project liquibase by liquibase.
the class BaseLiquibaseTask method createOutputWriter.
/**
* @deprecated Subclasses of this class should either instantiate their own output writers or use
* {@link liquibase.integration.ant.AbstractChangeLogBasedTask} if their task involves a change log.
*/
@Deprecated
public Writer createOutputWriter() throws IOException {
if (getOutputFile() == null) {
return null;
}
GlobalConfiguration globalConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
String encoding = globalConfiguration.getOutputEncoding();
return new OutputStreamWriter(getOutputFile().getOutputStream(), encoding);
}
use of liquibase.configuration.GlobalConfiguration in project liquibase by liquibase.
the class Main method run.
public static void run(String[] args) throws CommandLineParsingException, IOException, LiquibaseException {
try {
GlobalConfiguration globalConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class);
if (!globalConfiguration.getShouldRun()) {
System.err.println("Liquibase did not run because '" + LiquibaseConfiguration.getInstance().describeValueLookupLogic(globalConfiguration.getProperty(GlobalConfiguration.SHOULD_RUN)) + " was set to false");
return;
}
// if (!System.getProperties().contains("file.encoding")) {
// System.setProperty("file.encoding", "UTF-8");
// }
Main main = new Main();
if (args.length == 1 && "--help".equals(args[0])) {
main.printHelp(System.err);
return;
} else if (args.length == 1 && "--version".equals(args[0])) {
System.err.println("Liquibase Version: " + LiquibaseUtil.getBuildVersion() + StreamUtil.getLineSeparator());
return;
}
try {
main.parseOptions(args);
} catch (CommandLineParsingException e) {
// Print the help before throwing the exception
main.printHelp(Arrays.asList(e.getMessage()), System.err);
throw e;
}
File propertiesFile = new File(main.defaultsFile);
String localDefaultsPathName = main.defaultsFile.replaceFirst("(\\.[^\\.]+)$", ".local$1");
File localPropertiesFile = new File(localDefaultsPathName);
if (localPropertiesFile.exists()) {
FileInputStream stream = new FileInputStream(localPropertiesFile);
try {
main.parsePropertiesFile(stream);
} finally {
stream.close();
}
} else {
InputStream resourceAsStream = main.getClass().getClassLoader().getResourceAsStream(localDefaultsPathName);
if (resourceAsStream != null) {
try {
main.parsePropertiesFile(resourceAsStream);
} finally {
resourceAsStream.close();
}
}
}
if (propertiesFile.exists()) {
FileInputStream stream = new FileInputStream(propertiesFile);
try {
main.parsePropertiesFile(stream);
} finally {
stream.close();
}
} else {
InputStream resourceAsStream = main.getClass().getClassLoader().getResourceAsStream(main.defaultsFile);
if (resourceAsStream != null) {
try {
main.parsePropertiesFile(resourceAsStream);
} finally {
resourceAsStream.close();
}
}
}
List<String> setupMessages = main.checkSetup();
if (setupMessages.size() > 0) {
main.printHelp(setupMessages, System.err);
return;
}
main.applyDefaults();
main.configureClassLoader();
main.doMigration();
if ("update".equals(main.command)) {
System.err.println("Liquibase Update Successful");
} else if (main.command.startsWith("rollback") && !main.command.endsWith("SQL")) {
System.err.println("Liquibase Rollback Successful");
} else if (!main.command.endsWith("SQL")) {
System.err.println("Liquibase '" + main.command + "' Successful");
}
} catch (Throwable e) {
String message = e.getMessage();
if (e.getCause() != null) {
message = e.getCause().getMessage();
}
if (message == null) {
message = "Unknown Reason";
}
// trace because the logger already did that upstream.
try {
if (e.getCause() instanceof ValidationFailedException) {
((ValidationFailedException) e.getCause()).printDescriptiveError(System.out);
} else {
System.err.println("Unexpected error running Liquibase: " + message + "\n");
LogFactory.getInstance().getLog().severe(message, e);
System.err.println(generateLogLevelWarningMessage());
}
} catch (Exception e1) {
e.printStackTrace();
}
throw new LiquibaseException("Unexpected error running Liquibase: " + message, e);
}
}
Aggregations