1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.result.skipped;
17 
18 import java.util.List;
19 
20 /** Represents the results of a single build analysis. */
21 public class BuildAnalysis {
22 
23     private final boolean mDeviceImageChanged;
24     private final boolean mHasTestsArtifacts;
25     private boolean mHasChangesInTests = false;
26 
BuildAnalysis(boolean deviceImageChanged, boolean hasTestsArtifacts)27     public BuildAnalysis(boolean deviceImageChanged, boolean hasTestsArtifacts) {
28         this.mDeviceImageChanged = deviceImageChanged;
29         this.mHasTestsArtifacts = hasTestsArtifacts;
30     }
31 
deviceImageChanged()32     public boolean deviceImageChanged() {
33         return mDeviceImageChanged;
34     }
35 
hasTestsArtifacts()36     public boolean hasTestsArtifacts() {
37         return mHasTestsArtifacts;
38     }
39 
hasChangesInTestsArtifacts()40     public boolean hasChangesInTestsArtifacts() {
41         return mHasChangesInTests;
42     }
43 
setChangesInTests(boolean hasChanges)44     public void setChangesInTests(boolean hasChanges) {
45         mHasChangesInTests = hasChanges;
46     }
47 
48     @Override
toString()49     public String toString() {
50         return "BuildAnalysis [mDeviceImageChanged="
51                 + mDeviceImageChanged
52                 + ", mHasTestsArtifacts="
53                 + mHasTestsArtifacts
54                 + ", mHasChangesInTests="
55                 + mHasChangesInTests
56                 + "]";
57     }
58 
mergeReports(List<BuildAnalysis> reports)59     public static BuildAnalysis mergeReports(List<BuildAnalysis> reports) {
60         boolean deviceImageChanged = false;
61         boolean hasTestsArtifacts = false;
62         // Anchor toward things changing
63         for (BuildAnalysis rep : reports) {
64             deviceImageChanged |= rep.deviceImageChanged();
65             hasTestsArtifacts |= rep.hasTestsArtifacts();
66         }
67         return new BuildAnalysis(deviceImageChanged, hasTestsArtifacts);
68     }
69 }
70