use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class ChangeLogParserFactoryTest method unregister_instance.
@Test
public void unregister_instance() {
ChangeLogParserFactory factory = ChangeLogParserFactory.getInstance();
factory.unregisterAllParsers();
assumeThat(ChangeLogParserFactory.getInstance().getParsers(), empty());
ChangeLogParser mockChangeLogParser = new MockChangeLogParser(".test");
factory.register(new XMLChangeLogSAXParser());
factory.register(mockChangeLogParser);
factory.register(new SqlChangeLogParser());
assertEquals(3, factory.getParsers().size());
factory.unregister(mockChangeLogParser);
assertEquals(2, factory.getParsers().size());
}
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) throws LiquibaseException {
if (fileName.equalsIgnoreCase(".svn") || fileName.equalsIgnoreCase("cvs")) {
return false;
}
String relativeBaseFileName = this.getPhysicalFilePath();
if (isRelativePath) {
// workaround for FilenameUtils.normalize() returning null for relative paths like ../conf/liquibase.xml
String tempFile = FilenameUtils.concat(FilenameUtils.getFullPath(relativeBaseFileName), fileName);
if (tempFile != null && new File(tempFile).exists() == true) {
fileName = tempFile;
} else {
fileName = FilenameUtils.getFullPath(relativeBaseFileName) + fileName;
}
}
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);
} finally {
if (rootChangeLog == null) {
ROOT_CHANGE_LOG.remove();
}
if (parentChangeLog == null) {
PARENT_CHANGE_LOG.remove();
} else {
PARENT_CHANGE_LOG.set(parentChangeLog);
}
}
} catch (UnknownChangelogFormatException e) {
if (StringUtils.trimToEmpty(fileName).matches("\\.\\w+$")) {
LogFactory.getInstance().getLog().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 Liquibase method getDatabaseChangeLog.
public DatabaseChangeLog getDatabaseChangeLog() throws LiquibaseException {
if (databaseChangeLog == null && changeLogFile != null) {
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor);
databaseChangeLog = parser.parse(changeLogFile, changeLogParameters, resourceAccessor);
}
return databaseChangeLog;
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class ChangeLogParserFactoryTest method getParser_byExtension.
@Test
public void getParser_byExtension() 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("xml", new JUnitResourceAccessor());
assertNotNull(parser);
assertSame(xmlChangeLogParser, parser);
}
use of liquibase.parser.ChangeLogParser in project liquibase by liquibase.
the class DeactivateChangelogCommandStep 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);
}
Aggregations