use of liquibase.exception.ChangeLogParseException in project liquibase by liquibase.
the class YamlChangeLogParser method parse.
@Override
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
Yaml yaml = new Yaml();
try {
InputStream changeLogStream = StreamUtil.singleInputStream(physicalChangeLogLocation, resourceAccessor);
if (changeLogStream == null) {
throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist");
}
Map parsedYaml;
try {
parsedYaml = yaml.loadAs(changeLogStream, Map.class);
} catch (Exception e) {
throw new ChangeLogParseException("Syntax error in " + getSupportedFileExtensions()[0] + ": " + e.getMessage(), e);
}
if (parsedYaml == null || parsedYaml.size() == 0) {
throw new ChangeLogParseException("Empty file " + physicalChangeLogLocation);
}
DatabaseChangeLog changeLog = new DatabaseChangeLog(physicalChangeLogLocation);
Object rootList = parsedYaml.get("databaseChangeLog");
if (rootList == null) {
throw new ChangeLogParseException("Could not find databaseChangeLog node");
}
if (!(rootList instanceof List)) {
throw new ChangeLogParseException("databaseChangeLog does not contain a list of entries. Each changeSet must begin ' - changeSet:'");
}
for (Object obj : (List) rootList) {
if (obj instanceof Map && ((Map) obj).containsKey("property")) {
Map property = (Map) ((Map) obj).get("property");
ContextExpression context = new ContextExpression((String) property.get("context"));
Labels labels = new Labels((String) property.get("labels"));
Boolean global = getGlobalParam(property);
if (property.containsKey("name")) {
Object value = property.get("value");
if (value != null) {
// TODO: not nice...
value = value.toString();
}
changeLogParameters.set((String) property.get("name"), (String) value, context, labels, (String) property.get("dbms"), global, changeLog);
} else if (property.containsKey("file")) {
Properties props = new Properties();
InputStream propertiesStream = StreamUtil.singleInputStream((String) property.get("file"), resourceAccessor);
if (propertiesStream == null) {
log.info("Could not open properties file " + property.get("file"));
} else {
props.load(propertiesStream);
for (Map.Entry entry : props.entrySet()) {
changeLogParameters.set(entry.getKey().toString(), entry.getValue().toString(), context, labels, (String) property.get("dbms"), global, changeLog);
}
}
}
}
}
replaceParameters(parsedYaml, changeLogParameters, changeLog);
changeLog.setChangeLogParameters(changeLogParameters);
ParsedNode databaseChangeLogNode = new ParsedNode(null, "databaseChangeLog");
databaseChangeLogNode.setValue(rootList);
changeLog.load(databaseChangeLogNode, resourceAccessor);
return changeLog;
} catch (Throwable e) {
if (e instanceof ChangeLogParseException) {
throw (ChangeLogParseException) e;
}
throw new ChangeLogParseException("Error parsing " + physicalChangeLogLocation, e);
}
}
use of liquibase.exception.ChangeLogParseException in project liquibase by liquibase.
the class AbstractIntegrationTest method invalidIncludeDoesntBreakLiquibase.
@Test
public void invalidIncludeDoesntBreakLiquibase() throws Exception {
if (database == null) {
return;
}
Liquibase liquibase = createLiquibase(invalidReferenceChangeLog);
try {
liquibase.update(new Contexts());
fail("Did not fail with invalid include");
} catch (ChangeLogParseException ignored) {
//expected
}
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
assertFalse(lockService.hasChangeLogLock());
}
Aggregations