1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.buildcache;
20
21 import org.apache.maven.buildcache.xml.Build;
22 import org.apache.maven.buildcache.xml.CacheSource;
23
24 import static java.util.Objects.requireNonNull;
25
26
27
28
29 public class CacheResult {
30
31 private final RestoreStatus status;
32 private final Build build;
33 private final CacheContext context;
34
35 private CacheResult(RestoreStatus status, Build build, CacheContext context) {
36 this.status = requireNonNull(status);
37 this.build = build;
38 this.context = context;
39 }
40
41 public static CacheResult empty(CacheContext context) {
42 requireNonNull(context);
43 return new CacheResult(RestoreStatus.EMPTY, null, context);
44 }
45
46 public static CacheResult empty() {
47 return new CacheResult(RestoreStatus.EMPTY, null, null);
48 }
49
50 public static CacheResult failure(Build build, CacheContext context) {
51 requireNonNull(build);
52 requireNonNull(context);
53 return new CacheResult(RestoreStatus.FAILURE, build, context);
54 }
55
56 public static CacheResult success(Build build, CacheContext context) {
57 requireNonNull(build);
58 requireNonNull(context);
59 return new CacheResult(RestoreStatus.SUCCESS, build, context);
60 }
61
62 public static CacheResult partialSuccess(Build build, CacheContext context) {
63 requireNonNull(build);
64 requireNonNull(context);
65 return new CacheResult(RestoreStatus.PARTIAL, build, context);
66 }
67
68 public static CacheResult failure(CacheContext context) {
69 requireNonNull(context);
70 return new CacheResult(RestoreStatus.FAILURE, null, context);
71 }
72
73 public static CacheResult rebuilded(CacheResult orig, Build build) {
74 requireNonNull(orig);
75 requireNonNull(build);
76 return new CacheResult(orig.status, build, orig.context);
77 }
78
79 public boolean isSuccess() {
80 return status == RestoreStatus.SUCCESS;
81 }
82
83 public Build getBuildInfo() {
84 return build;
85 }
86
87 public CacheSource getSource() {
88 return build != null ? build.getSource() : null;
89 }
90
91 public CacheContext getContext() {
92 return context;
93 }
94
95 public boolean isPartialSuccess() {
96 return status == RestoreStatus.PARTIAL;
97 }
98
99 public RestoreStatus getStatus() {
100 return status;
101 }
102
103 public boolean isFinal() {
104 return build != null && build.getDto().is_final();
105 }
106 }