1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.delta;
35
36 import info.magnolia.module.model.ModuleDefinition;
37 import info.magnolia.module.model.Version;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47
48 public class DeltaBuilder implements Delta {
49
50
51
52
53 public static DeltaBuilder update(Version v, String description, Task task) {
54 return update(v, description).addTask(task);
55 }
56
57 public static DeltaBuilder update(String versionStr, String description) {
58 return update(Version.parseVersion(versionStr), description);
59 }
60
61 public static DeltaBuilder update(Version version, String description) {
62 return new DeltaBuilder(version, description, DeltaType.update);
63 }
64
65 public static DeltaBuilder install(Version version, String description) {
66 return new DeltaBuilder(version, description, DeltaType.install);
67 }
68
69 public static DeltaBuilder startup(ModuleDefinition moduleDef, List<Task> tasks) {
70 final String description = "Tasks executed before starting up module " + moduleDef.getDescription();
71 return startup(moduleDef.getVersion(), description).addTasks(tasks);
72 }
73
74
75
76
77 public static DeltaBuilder startup(Version version, String description) {
78 return new DeltaBuilder(version, description, DeltaType.startup);
79 }
80
81 private final Version version;
82 private final String description;
83 private final DeltaType type;
84 private final List<Task> tasks;
85 private final List<Condition> conditions;
86
87 private DeltaBuilder(Version version, String description, DeltaType type) {
88 this.version = version;
89 this.description = description;
90 this.type = type;
91 this.tasks = new ArrayList<Task>();
92 this.conditions = new ArrayList<Condition>();
93 }
94
95 public DeltaBuilder addTask(Task t) {
96 tasks.add(t);
97 return this;
98 }
99
100 public DeltaBuilder addTasks(List<Task> tasks) {
101 this.tasks.addAll(tasks);
102 return this;
103 }
104
105 public DeltaBuilder addCondition(Condition c) {
106 conditions.add(c);
107 return this;
108 }
109
110 public DeltaBuilder addConditions(List<Condition> conditions) {
111 this.conditions.addAll(conditions);
112 return this;
113 }
114
115 public Version getVersion() {
116 return version;
117 }
118
119 public String getDescription() {
120 return description;
121 }
122
123 public List<Condition> getConditions() {
124 return conditions;
125 }
126
127 public List<Task> getTasks() {
128 return tasks;
129 }
130
131 public DeltaType getType() {
132 return type;
133 }
134
135 }