View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * CacheResult
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 }