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 public class DeltaBuilder implements Delta {
48
49
50
51
52 public static DeltaBuilder update(Version toVersion, String description, Task task) {
53 return update(toVersion, description).addTask(task);
54 }
55
56 public static DeltaBuilder update(String toVersionString, String description) {
57 return update(Version.parseVersion(toVersionString), description);
58 }
59
60 public static DeltaBuilder update(Version toVersion, String description) {
61 return new DeltaBuilder(toVersion, description, DeltaType.update);
62 }
63
64 public static DeltaBuilder install(Version version, String description) {
65 return new DeltaBuilder(version, description, DeltaType.install);
66 }
67
68 public static DeltaBuilder startup(ModuleDefinition moduleDef, List<Task> tasks) {
69 final String description = "Tasks executed before starting up module " + moduleDef.getDescription();
70 return startup(moduleDef.getVersion(), description).addTasks(tasks);
71 }
72
73 public static DeltaBuilder checkPrecondition(String minimalVersion, String newVersion) {
74 return update(minimalVersion, "minimal version required for updating to " + newVersion).addCondition(
75 new FalseCondition("checkPrerequisite", "Updating to " + newVersion + " is only supported from "
76 + minimalVersion + " or higher."));
77 }
78
79
80
81
82 public static DeltaBuilder startup(Version version, String description) {
83 return new DeltaBuilder(version, description, DeltaType.startup);
84 }
85
86 private final Version version;
87 private final String description;
88 private final DeltaType type;
89 private final List<Task> tasks;
90 private final List<Condition> conditions;
91
92 private DeltaBuilder(Version version, String description, DeltaType type) {
93 this.version = version;
94 this.description = description;
95 this.type = type;
96 this.tasks = new ArrayList<Task>();
97 this.conditions = new ArrayList<Condition>();
98 }
99
100 public DeltaBuilder addTask(Task t) {
101 tasks.add(t);
102 return this;
103 }
104
105 public DeltaBuilder addTasks(List<Task> tasks) {
106 this.tasks.addAll(tasks);
107 return this;
108 }
109
110 public DeltaBuilder addCondition(Condition c) {
111 conditions.add(c);
112 return this;
113 }
114
115 public DeltaBuilder addConditions(List<Condition> conditions) {
116 this.conditions.addAll(conditions);
117 return this;
118 }
119
120 @Override
121 public Version getVersion() {
122 return version;
123 }
124
125 @Override
126 public String getDescription() {
127 return description;
128 }
129
130 @Override
131 public List<Condition> getConditions() {
132 return conditions;
133 }
134
135 @Override
136 public List<Task> getTasks() {
137 return tasks;
138 }
139
140 @Override
141 public DeltaType getType() {
142 return type;
143 }
144
145 }