use of liquibase.precondition.core.PreconditionContainer 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.precondition.core.PreconditionContainer in project liquibase by liquibase.
the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithPreconditionTag.
/**
* Test only the precondition tag with a precondition requiring oracle but
* giving a MSSQL database.
*/
@Test
public void testPreConditionsForOracleOnMSSQLWithPreconditionTag() {
// create the pre condition
PreconditionContainer preCondition = new PreconditionContainer();
preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
dbmsPrecondition.setType("oracle");
preCondition.addNestedPrecondition(dbmsPrecondition);
changeSet1.setPreconditions(preCondition);
MSSQLDatabase mssqlDb = new MSSQLDatabase() {
@Override
public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
return new ArrayList<RanChangeSet>();
}
@Override
public void rollback() throws DatabaseException {
//super.rollback();
}
};
boolean failedExceptionThrown = false;
boolean errorExceptionThrown = false;
try {
preCondition.check(mssqlDb, changeLog, changeSet1);
} catch (PreconditionFailedException ex) {
failedExceptionThrown = true;
} catch (PreconditionErrorException ex) {
errorExceptionThrown = true;
}
assertTrue(failedExceptionThrown);
assertFalse(errorExceptionThrown);
}
use of liquibase.precondition.core.PreconditionContainer in project liquibase by liquibase.
the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithChangeLog.
/**
* Test the same precondition from a changelog with mssql database, this
* should not fail on the validation but just mark is as handled.
*/
@Test
public void testPreConditionsForOracleOnMSSQLWithChangeLog() {
// create the pre condition
PreconditionContainer preCondition = new PreconditionContainer();
preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
dbmsPrecondition.setType("oracle");
preCondition.addNestedPrecondition(dbmsPrecondition);
changeSet1.setPreconditions(preCondition);
MSSQLDatabase mssqlDb = new MSSQLDatabase() {
@Override
public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
return new ArrayList<RanChangeSet>();
}
@Override
public void rollback() throws DatabaseException {
//super.rollback();
}
};
String[] empty = {};
boolean exceptionThrown = false;
try {
// call the validate which gives the error
changeLog.validate(mssqlDb, empty);
} catch (LiquibaseException ex) {
System.out.println(ex.getMessage());
exceptionThrown = true;
}
assertFalse(exceptionThrown);
}
Aggregations