01: package liquibase.parser.filter;
02:
03: import liquibase.ChangeSet;
04: import liquibase.util.StringUtils;
05:
06: import java.util.Arrays;
07: import java.util.HashSet;
08: import java.util.Set;
09:
10: public class ContextChangeSetFilter implements ChangeSetFilter {
11: private Set<String> contexts;
12:
13: public ContextChangeSetFilter(String... contexts) {
14: this .contexts = new HashSet<String>();
15: if (contexts != null) {
16: if (contexts.length == 1) {
17: if (contexts[0] == null) {
18: ; //do nothing
19: } else if (contexts[0].indexOf(",") >= 0) {
20: this .contexts.addAll(StringUtils.splitAndTrim(
21: contexts[0], ","));
22: } else {
23: this .contexts.add(contexts[0]);
24: }
25: } else {
26: this .contexts.addAll(Arrays.asList(contexts));
27: }
28: }
29: }
30:
31: public boolean accepts(ChangeSet changeSet) {
32: if (contexts == null || contexts.size() == 0) {
33: return true;
34: }
35:
36: if (changeSet.getContexts() == null) {
37: return true;
38: }
39:
40: for (String context : changeSet.getContexts()) {
41: if (contexts.contains(context)) {
42: return true;
43: }
44: }
45:
46: return false;
47: }
48: }
|