use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class ConvertCommand method run.
@Override
protected CommandResult run() throws Exception {
List<ResourceAccessor> openers = new ArrayList<ResourceAccessor>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(classpath));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(outFile);
try {
outSerializer.write(changeLog.getChangeSets(), outputStream);
} finally {
outputStream.flush();
outputStream.close();
}
return new CommandResult("Converted successfully");
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class DatabaseChangeLog method include.
public boolean include(String fileName, boolean isRelativePath, ResourceAccessor resourceAccessor, ContextExpression includeContexts, LabelExpression labelExpression, Boolean ignore, boolean logEveryUnknownFileFormat) throws LiquibaseException {
if (".svn".equalsIgnoreCase(fileName) || "cvs".equalsIgnoreCase(fileName)) {
return false;
}
String relativeBaseFileName = this.getPhysicalFilePath();
if (isRelativePath) {
relativeBaseFileName = relativeBaseFileName.replaceFirst("classpath:", "");
fileName = FilenameUtil.concat(FilenameUtil.getDirectory(relativeBaseFileName), fileName);
}
fileName = fileName.replaceFirst("classpath:", "");
DatabaseChangeLog changeLog;
try {
DatabaseChangeLog rootChangeLog = ROOT_CHANGE_LOG.get();
if (rootChangeLog == null) {
ROOT_CHANGE_LOG.set(this);
}
DatabaseChangeLog parentChangeLog = PARENT_CHANGE_LOG.get();
PARENT_CHANGE_LOG.set(this);
try {
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(fileName, resourceAccessor);
changeLog = parser.parse(fileName, changeLogParameters, resourceAccessor);
changeLog.setIncludeContexts(includeContexts);
changeLog.setIncludeLabels(labelExpression);
changeLog.setIncludeIgnore(ignore != null ? ignore.booleanValue() : false);
} finally {
if (rootChangeLog == null) {
ROOT_CHANGE_LOG.remove();
}
if (parentChangeLog == null) {
PARENT_CHANGE_LOG.remove();
} else {
PARENT_CHANGE_LOG.set(parentChangeLog);
}
}
} catch (UnknownChangelogFormatException e) {
// This matches only an extension, but filename can be a full path, too. Is it right?
boolean matchesFileExtension = StringUtil.trimToEmpty(fileName).matches("\\.\\w+$");
if (matchesFileExtension || logEveryUnknownFileFormat) {
Scope.getCurrentScope().getLog(getClass()).warning("included file " + relativeBaseFileName + "/" + fileName + " is not a recognized file type");
}
return false;
}
PreconditionContainer preconditions = changeLog.getPreconditions();
if (preconditions != null) {
if (null == this.getPreconditions()) {
this.setPreconditions(new PreconditionContainer());
}
this.getPreconditions().addNestedPrecondition(preconditions);
}
for (ChangeSet changeSet : changeLog.getChangeSets()) {
addChangeSet(changeSet);
}
return true;
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class InternalDropAllCommandStep method parseChangeLogFile.
private DatabaseChangeLog parseChangeLogFile(String changeLogFile) throws LiquibaseException {
ResourceAccessor resourceAccessor = Scope.getCurrentScope().getResourceAccessor();
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor);
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
return parser.parse(changeLogFile, changeLogParameters, resourceAccessor);
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class ConvertCommandStep method run.
@Override
public void run(CommandResultsBuilder resultsBuilder) throws Exception {
CommandScope commandScope = resultsBuilder.getCommandScope();
String src = commandScope.getArgumentValue(SRC_ARG);
String out = commandScope.getArgumentValue(OUT_ARG);
String classpath = commandScope.getArgumentValue(CLASSPATH_ARG);
List<ResourceAccessor> openers = new ArrayList<>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(new File(classpath)));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
try (FileOutputStream outputStream = new FileOutputStream(outFile)) {
outSerializer.write(changeLog.getChangeSets(), outputStream);
}
Scope.getCurrentScope().getUI().sendMessage("Converted successfully");
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class ChangeLogParserFactoryTest method getParser_byFile.
@Test
public void getParser_byFile() throws Exception {
ChangeLogParserFactory.getInstance().unregisterAllParsers();
assumeThat(ChangeLogParserFactory.getInstance().getParsers(), empty());
XMLChangeLogSAXParser xmlChangeLogParser = new XMLChangeLogSAXParser();
ChangeLogParserFactory.getInstance().register(xmlChangeLogParser);
ChangeLogParserFactory.getInstance().register(new SqlChangeLogParser());
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser("path/to/a/file.xml", new JUnitResourceAccessor());
assertNotNull(parser);
assertSame(xmlChangeLogParser, parser);
}
Aggregations