forked from tomphp/untangled-conditionals-kata
/
Pipeline.java
81 lines (71 loc) · 2.36 KB
/
Pipeline.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import dependencies.Config;
import dependencies.Emailer;
import dependencies.Logger;
import dependencies.Project;
public class Pipeline {
private final Config config;
private final Emailer emailer;
private final Logger log;
public Pipeline(Config config, Emailer emailer, Logger log) {
this.config = config;
this.emailer = emailer;
this.log = log;
}
interface Notifier {
void sendNotification(String message);
}
class NotifierFactory {
Notifier build(Config config) {
if (config.sendEmailSummary()) return new EmailNotifier();
else return new NullNotifier();
}
class NullNotifier implements Notifier {
public void sendNotification(String message) {
log.info("Email disabled");
}
}
class EmailNotifier implements Notifier {
public void sendNotification(String message) {
log.info("Sending email");
emailer.send(message);
}
}
}
public void run(Project project) {
/*
hT -V-> rT -V-> d -V-> sES -V-> m1
-F-> lI
-F-> sES -V-> m2
-F-> lI
-F-> sES -V-> m3
-F-> lI
-F-> d -V-> sES -V-> m1
-F-> lI
-F-> sES -V-> m2
-F-> lI
*/
String status;
if (project.hasTests()) {
if ("success".equals(project.runTests())) {
log.info("Tests passed");
status = deploy(project);
} else {
log.error("Tests failed");
status = "Tests failed";
}
} else {
log.info("No tests");
status = deploy(project);
}
new NotifierFactory().build(config).sendNotification(status);
}
private String deploy(Project project) {
if ("success".equals(project.deploy())) {
log.info("Deployment successful");
return "Deployment completed successfully";
} else {
log.error("Deployment failed");
return "Deployment failed";
}
}
}