diff --git a/liquibase-core/src/main/java/liquibase/changelog/ChangeLogParameters.java b/liquibase-core/src/main/java/liquibase/changelog/ChangeLogParameters.java index 5d7f1e5ad0a..c3b9d6f0259 100644 --- a/liquibase-core/src/main/java/liquibase/changelog/ChangeLogParameters.java +++ b/liquibase-core/src/main/java/liquibase/changelog/ChangeLogParameters.java @@ -132,7 +132,7 @@ public void set(String key, String value, ContextExpression contexts, Labels lab changeLog)); } else { ChangeLogParameter param = findParameter(key, changeLog); - if (param != null && ! param.isGlobal() && param.getChangeLog() == changeLog) { + if (param != null && isDuplicate(param) && ! param.isGlobal() && param.getChangeLog() == changeLog) { changeLogParameters.remove(param); } //this is a non-global param, just add it @@ -140,6 +140,15 @@ public void set(String key, String value, ContextExpression contexts, Labels lab } } + private boolean isDuplicate(ChangeLogParameter param) { + for (ChangeLogParameter parameter : changeLogParameters) { + if (param != parameter && param.isDuplicate(parameter)) { + return true; + } + } + return false; + } + /** * Return the value of a parameter * @@ -343,6 +352,19 @@ public boolean isValid() { return isValid; } + public boolean isDuplicate(ChangeLogParameter other) { + String contextString = (this.getValidContexts() != null ? this.getValidContexts().toString() : null); + String labelsString = (this.getLabels() != null ? this.getLabels().toString() : null); + String databases = (this.getValidDatabases() != null ? StringUtil.join(this.getValidDatabases(), ",") : null); + + String otherContextString = (other.getValidContexts() != null ? other.getValidContexts().toString() : null); + String otherLabelsString = (other.getLabels() != null ? other.getLabels().toString() : null); + String otherDatabases = (other.getValidDatabases() != null ? StringUtil.join(other.getValidDatabases(), ",") : null); + return StringUtil.equalsIgnoreCaseAndEmpty(contextString, otherContextString) && + StringUtil.equalsIgnoreCaseAndEmpty(labelsString, otherLabelsString) && + StringUtil.equalsIgnoreCaseAndEmpty(databases, otherDatabases); + } + public boolean isGlobal() { return global; }