Search in sources :

Example 1 with ParsedNodeException

use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.

the class CustomChangeWrapper method customLoadLogic.

@Override
public void customLoadLogic(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    ParsedNode paramsNode = parsedNode.getChild(null, "params");
    if (paramsNode == null) {
        paramsNode = parsedNode;
    }
    for (ParsedNode child : paramsNode.getChildren(null, "param")) {
        Object value = child.getValue();
        if (value == null) {
            value = child.getChildValue(null, "value");
        }
        if (value != null) {
            value = value.toString();
        }
        this.setParam(child.getChildValue(null, "name", String.class), (String) value);
    }
    CustomChange customChange = null;
    try {
        customChange = (CustomChange) Class.forName(className, false, resourceAccessor.toClassLoader()).newInstance();
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
    for (ParsedNode node : parsedNode.getChildren()) {
        Object value = node.getValue();
        if (value != null && ObjectUtil.hasProperty(customChange, node.getName())) {
            this.setParam(node.getName(), value.toString());
        }
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException)

Example 2 with ParsedNodeException

use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.

the class ChangeSet method handleRollbackNode.

protected void handleRollbackNode(ParsedNode rollbackNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
    String changeSetId = rollbackNode.getChildValue(null, "changeSetId", String.class);
    if (changeSetId != null) {
        String changeSetAuthor = rollbackNode.getChildValue(null, "changeSetAuthor", String.class);
        String changeSetPath = rollbackNode.getChildValue(null, "changeSetPath", getFilePath());
        DatabaseChangeLog changeLog = this.getChangeLog();
        ChangeSet changeSet = changeLog.getChangeSet(changeSetPath, changeSetAuthor, changeSetId);
        while (changeSet == null && changeLog != null) {
            changeLog = changeLog.getParentChangeLog();
            if (changeLog != null) {
                changeSet = changeLog.getChangeSet(changeSetPath, changeSetAuthor, changeSetId);
            }
        }
        if (changeSet == null) {
            throw new ParsedNodeException("Change set " + new ChangeSet(changeSetId, changeSetAuthor, false, false, changeSetPath, null, null, null).toString(false) + " does not exist");
        }
        for (Change change : changeSet.getChanges()) {
            rollback.getChanges().add(change);
        }
        return;
    }
    boolean foundValue = false;
    for (ParsedNode childNode : rollbackNode.getChildren()) {
        Change rollbackChange = toChange(childNode, resourceAccessor);
        if (rollbackChange != null) {
            addRollbackChange(rollbackChange);
            foundValue = true;
        }
    }
    Object value = rollbackNode.getValue();
    if (value != null) {
        if (value instanceof String) {
            String finalValue = StringUtils.trimToNull((String) value);
            if (finalValue != null) {
                String[] strings = StringUtils.processMutliLineSQL(finalValue, true, true, ";");
                for (String string : strings) {
                    addRollbackChange(new RawSQLChange(string));
                    foundValue = true;
                }
            }
        } else {
            throw new ParsedNodeException("Unexpected object: " + value.getClass().getName() + " '" + value.toString() + "'");
        }
    }
    if (!foundValue) {
        addRollbackChange(new EmptyChange());
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) RawSQLChange(liquibase.change.core.RawSQLChange) ParsedNodeException(liquibase.parser.core.ParsedNodeException) Change(liquibase.change.Change) EmptyChange(liquibase.change.core.EmptyChange) RawSQLChange(liquibase.change.core.RawSQLChange) DbmsTargetedChange(liquibase.change.DbmsTargetedChange) EmptyChange(liquibase.change.core.EmptyChange)

Example 3 with ParsedNodeException

use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.

the class DatabaseChangeLog method expandExpressions.

protected void expandExpressions(ParsedNode parsedNode) {
    if (changeLogParameters == null) {
        return;
    }
    try {
        Object value = parsedNode.getValue();
        if (value != null && value instanceof String) {
            parsedNode.setValue(changeLogParameters.expandExpressions(parsedNode.getValue(String.class), this));
        }
        List<ParsedNode> children = parsedNode.getChildren();
        if (children != null) {
            for (ParsedNode child : children) {
                expandExpressions(child);
            }
        }
    } catch (ParsedNodeException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 4 with ParsedNodeException

use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.

the class DatabaseChangeLog method handleChildNode.

protected void handleChildNode(ParsedNode node, ResourceAccessor resourceAccessor) throws ParsedNodeException, SetupException {
    expandExpressions(node);
    String nodeName = node.getName();
    if (nodeName.equals("changeSet")) {
        this.addChangeSet(createChangeSet(node, resourceAccessor));
    } else if (nodeName.equals("include")) {
        String path = node.getChildValue(null, "file", String.class);
        if (path == null) {
            throw new UnexpectedLiquibaseException("No 'file' attribute on 'include'");
        }
        path = path.replace('\\', '/');
        ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
        try {
            include(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceAccessor, includeContexts);
        } catch (LiquibaseException e) {
            throw new SetupException(e);
        }
    } else if (nodeName.equals("includeAll")) {
        String path = node.getChildValue(null, "path", String.class);
        String resourceFilterDef = node.getChildValue(null, "filter", String.class);
        if (resourceFilterDef == null) {
            resourceFilterDef = node.getChildValue(null, "resourceFilter", String.class);
        }
        IncludeAllFilter resourceFilter = null;
        if (resourceFilterDef != null) {
            try {
                resourceFilter = (IncludeAllFilter) Class.forName(resourceFilterDef).newInstance();
            } catch (Exception e) {
                throw new SetupException(e);
            }
        }
        String resourceComparatorDef = node.getChildValue(null, "resourceComparator", String.class);
        Comparator<?> resourceComparator = null;
        if (resourceComparatorDef != null) {
            try {
                resourceComparator = (Comparator<?>) Class.forName(resourceComparatorDef).newInstance();
            } catch (Exception e) {
                //take default comparator
                LogFactory.getInstance().getLog().info("no resourceComparator defined - taking default implementation");
                resourceComparator = getStandardChangeLogComparator();
            }
        }
        ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
        includeAll(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceFilter, node.getChildValue(null, "errorIfMissingOrEmpty", true), getStandardChangeLogComparator(), resourceAccessor, includeContexts);
    } else if (nodeName.equals("preConditions")) {
        this.preconditionContainer = new PreconditionContainer();
        try {
            this.preconditionContainer.load(node, resourceAccessor);
        } catch (ParsedNodeException e) {
            e.printStackTrace();
        }
    } else if (nodeName.equals("property")) {
        try {
            String context = node.getChildValue(null, "context", String.class);
            String dbms = node.getChildValue(null, "dbms", String.class);
            String labels = node.getChildValue(null, "labels", String.class);
            Boolean global = node.getChildValue(null, "global", Boolean.class);
            if (global == null) {
                // okay behave like liquibase < 3.4 and set global == true
                global = true;
            }
            String file = node.getChildValue(null, "file", String.class);
            if (file == null) {
                // direct referenced property, no file
                String name = node.getChildValue(null, "name", String.class);
                String value = node.getChildValue(null, "value", String.class);
                this.changeLogParameters.set(name, value, context, labels, dbms, global, this);
            } else {
                // read properties from the file
                Properties props = new Properties();
                InputStream propertiesStream = StreamUtil.singleInputStream(file, resourceAccessor);
                if (propertiesStream == null) {
                    LogFactory.getInstance().getLog().info("Could not open properties file " + file);
                } else {
                    props.load(propertiesStream);
                    for (Map.Entry entry : props.entrySet()) {
                        this.changeLogParameters.set(entry.getKey().toString(), entry.getValue().toString(), context, labels, dbms, global, this);
                    }
                }
            }
        } catch (IOException e) {
            throw new ParsedNodeException(e);
        }
    }
}
Also used : PreconditionContainer(liquibase.precondition.core.PreconditionContainer) InputStream(java.io.InputStream) ContextExpression(liquibase.ContextExpression) IOException(java.io.IOException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) SetupException(liquibase.exception.SetupException) UnknownChangelogFormatException(liquibase.exception.UnknownChangelogFormatException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ValidationFailedException(liquibase.exception.ValidationFailedException) LiquibaseException(liquibase.exception.LiquibaseException) SetupException(liquibase.exception.SetupException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 5 with ParsedNodeException

use of liquibase.parser.core.ParsedNodeException in project liquibase by liquibase.

the class XMLChangeLogSAXHandler method startElement.

@Override
public void startElement(String uri, String localName, String qualifiedName, Attributes attributes) throws SAXException {
    ParsedNode node = new ParsedNode(null, localName);
    try {
        if (attributes != null) {
            for (int i = 0; i < attributes.getLength(); i++) {
                try {
                    node.addChild(null, attributes.getLocalName(i), attributes.getValue(i));
                } catch (NullPointerException e) {
                    throw e;
                }
            }
        }
        if (!nodeStack.isEmpty()) {
            nodeStack.peek().addChild(node);
        }
        if (nodeStack.isEmpty()) {
            databaseChangeLogTree = node;
        }
        nodeStack.push(node);
        textStack.push(new StringBuffer());
    } catch (ParsedNodeException e) {
        throw new SAXException(e);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException) SAXException(org.xml.sax.SAXException)

Aggregations

ParsedNodeException (liquibase.parser.core.ParsedNodeException)14 ParsedNode (liquibase.parser.core.ParsedNode)12 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 ContextExpression (liquibase.ContextExpression)2 Change (liquibase.change.Change)2 DbmsTargetedChange (liquibase.change.DbmsTargetedChange)2 EmptyChange (liquibase.change.core.EmptyChange)2 RawSQLChange (liquibase.change.core.RawSQLChange)2 PreconditionContainer (liquibase.precondition.core.PreconditionContainer)2 DatabaseObject (liquibase.structure.DatabaseObject)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BigInteger (java.math.BigInteger)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Matcher (java.util.regex.Matcher)1 Labels (liquibase.Labels)1