throw new CommandLineParsingException(e.getMessage(), e);
}
FileSystemResourceAccessor fsOpener = new FileSystemResourceAccessor();
CommandLineResourceAccessor clOpener = new CommandLineResourceAccessor(classLoader);
Database database = CommandLineUtils.createDatabaseObject(classLoader, this.url,
this.username, this.password, this.driver, this.defaultCatalogName,this.defaultSchemaName, Boolean.parseBoolean(outputDefaultCatalog), Boolean.parseBoolean(outputDefaultSchema), this.databaseClass, this.driverPropertiesFile, this.propertyProviderClass, this.liquibaseCatalogName, this.liquibaseSchemaName);
try {
CompositeResourceAccessor fileOpener = new CompositeResourceAccessor(fsOpener, clOpener);
boolean includeCatalog = Boolean.parseBoolean(getCommandParam("includeCatalog", "false"));
boolean includeSchema = Boolean.parseBoolean(getCommandParam("includeSchema", "false"));
boolean includeTablespace = Boolean.parseBoolean(getCommandParam("includeTablespace", "false"));
DiffOutputControl diffOutputControl = new DiffOutputControl(includeCatalog, includeSchema, includeTablespace);
String referenceSchemaNames = getCommandParam("schemas", null);
CompareControl.SchemaComparison[] finalSchemaComparisons;
CatalogAndSchema[] finalSchemas;
if (referenceSchemaNames == null) {
finalSchemaComparisons = new CompareControl.SchemaComparison[] {new CompareControl.SchemaComparison(new CatalogAndSchema(defaultCatalogName, defaultSchemaName), new CatalogAndSchema(defaultCatalogName, defaultSchemaName))};
finalSchemas = new CatalogAndSchema[] {new CatalogAndSchema(defaultCatalogName, defaultSchemaName)};
} else {
List<CompareControl.SchemaComparison> schemaComparisons = new ArrayList<CompareControl.SchemaComparison>();
List<CatalogAndSchema> schemas = new ArrayList<CatalogAndSchema>();
for (String schema : referenceSchemaNames.split(",")) {
CatalogAndSchema correctedSchema = new CatalogAndSchema(null, schema).customize(database);
schemaComparisons.add(new CompareControl.SchemaComparison(correctedSchema, correctedSchema));
schemas.add(correctedSchema);
diffOutputControl.addIncludedSchema(correctedSchema);
}
finalSchemaComparisons = schemaComparisons.toArray(new CompareControl.SchemaComparison[schemaComparisons.size()]);
finalSchemas = schemas.toArray(new CatalogAndSchema[schemas.size()]);
}
for (CompareControl.SchemaComparison schema : finalSchemaComparisons) {
diffOutputControl.addIncludedSchema(schema.getReferenceSchema());
diffOutputControl.addIncludedSchema(schema.getComparisonSchema());
}
if ("diff".equalsIgnoreCase(command)) {
CommandLineUtils.doDiff(createReferenceDatabaseFromCommandParams(commandParams), database, StringUtils.trimToNull(diffTypes), finalSchemaComparisons);
return;
} else if ("diffChangeLog".equalsIgnoreCase(command)) {
CommandLineUtils.doDiffToChangeLog(changeLogFile, createReferenceDatabaseFromCommandParams(commandParams), database, diffOutputControl, StringUtils.trimToNull(diffTypes), finalSchemaComparisons);
return;
} else if ("generateChangeLog".equalsIgnoreCase(command)) {
String changeLogFile = this.changeLogFile;
if (changeLogFile == null) {
changeLogFile = ""; //will output to stdout
}
// By default the generateChangeLog command is destructive, and
// Liquibase's attempt to append doesn't work properly. Just
// fail the build if the file already exists.
File file = new File(changeLogFile);
if ( file.exists() ) {
throw new LiquibaseException("ChangeLogFile " + changeLogFile + " already exists!");
}
CommandLineUtils.doGenerateChangeLog(changeLogFile, database, finalSchemas, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataOutputDirectory), diffOutputControl);
return;
} else if ("snapshot".equalsIgnoreCase(command)) {
SnapshotCommand command = new SnapshotCommand();
command.setDatabase(database);
command.setSchemas(getCommandParam("schemas", database.getDefaultSchema().getSchemaName()));
System.out.println(command.execute());
return;
} else if ("executeSql".equalsIgnoreCase(command)) {
ExecuteSqlCommand command = new ExecuteSqlCommand();
command.setDatabase(database);
command.setSql(getCommandParam("sql", null));
command.setSqlFile(getCommandParam("sqlFile", null));
System.out.println(command.execute());
return;
} else if ("snapshotReference".equalsIgnoreCase(command)) {
SnapshotCommand command = new SnapshotCommand();
Database referenceDatabase = createReferenceDatabaseFromCommandParams(commandParams);
command.setDatabase(referenceDatabase);
command.setSchemas(getCommandParam("schemas", referenceDatabase.getDefaultSchema().getSchemaName()));
System.out.println(command.execute());
return;
}