1 /*
2  * Copyright (C) 2010 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.build;
17 
18 import com.android.tradefed.build.BuildInfoKey.BuildInfoFileKey;
19 import com.android.tradefed.device.ITestDevice;
20 
21 import java.io.File;
22 import java.io.Serializable;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 
28 /** Holds information about the build under test. */
29 public interface IBuildInfo extends Serializable {
30 
31     /** Some properties that a {@link IBuildInfo} can have to tweak some handling of it. */
32     public enum BuildInfoProperties {
33         DO_NOT_COPY_ON_SHARDING,
34         DO_NOT_LINK_TESTS_DIR,
35     }
36 
37     /**
38      * Default value when build ID is unknown.
39      */
40     public final static String UNKNOWN_BUILD_ID = "-1";
41 
42     /**
43      * Returns the unique identifier of build under test. Should never be null. Defaults to
44      * {@link #UNKNOWN_BUILD_ID}.
45      */
getBuildId()46     public String getBuildId();
47 
48     /**
49      * Sets the unique identifier of build under test. Should never be null.
50      */
setBuildId(String buildId)51     public void setBuildId(String buildId);
52 
53     /**
54      * Return a unique name for the tests being run.
55      */
getTestTag()56     public String getTestTag();
57 
58     /**
59      * Sets the unique name for the tests being run.
60      */
setTestTag(String testTag)61     public void setTestTag(String testTag);
62 
63     /**
64      * Return complete name for the build being tested.
65      * <p/>
66      * A common implementation is to construct the build target name from a combination of
67      * the build flavor and branch name. [ie (branch name)-(build flavor)]
68      */
getBuildTargetName()69     public String getBuildTargetName();
70 
71     /**
72      * Optional method to return the type of build being tested.
73      * <p/>
74      * A common implementation for Android platform builds is to return
75      * (build product)-(build os)-(build variant).
76      * ie generic-linux-userdebug
77      *
78      * @return the build flavor or <code>null</code> if unset/not applicable
79      */
getBuildFlavor()80     public String getBuildFlavor();
81 
82     /**
83      * @return the {@link ITestDevice} serial that this build was executed on. Returns <code>null
84      * </code> if no device is associated with this build.
85      */
getDeviceSerial()86     public String getDeviceSerial();
87 
88     /**
89      * Set the build flavor.
90      *
91      * @param buildFlavor
92      */
setBuildFlavor(String buildFlavor)93     public void setBuildFlavor(String buildFlavor);
94 
95     /**
96      * Optional method to return the source control branch that the build being tested was
97      * produced from.
98      *
99      * @return the build branch or <code>null</code> if unset/not applicable
100      */
getBuildBranch()101     public String getBuildBranch();
102 
103     /**
104      * Set the build branch
105      *
106      * @param branch the branch name
107      */
setBuildBranch(String branch)108     public void setBuildBranch(String branch);
109 
110     /**
111      * Set the {@link ITestDevice} serial associated with this build.
112      *
113      * @param serial the serial number of the {@link ITestDevice} that this build was executed with.
114      */
setDeviceSerial(String serial)115     public void setDeviceSerial(String serial);
116 
117     /**
118      * Get a set of name-value pairs of additional attributes describing the build.
119      *
120      * @return a {@link Map} of build attributes. Will not be <code>null</code>, but may be empty.
121      */
getBuildAttributes()122     public Map<String, String> getBuildAttributes();
123 
124     /**
125      * Add a build attribute
126      *
127      * @param attributeName the unique attribute name
128      * @param attributeValue the attribute value
129      */
addBuildAttribute(String attributeName, String attributeValue)130     public void addBuildAttribute(String attributeName, String attributeValue);
131 
132     /**
133      * Set the {@link BuildInfoProperties} for the {@link IBuildInfo} instance. Override any
134      * existing properties set before.
135      *
136      * @param properties The list of properties to add.
137      */
setProperties(BuildInfoProperties... properties)138     public void setProperties(BuildInfoProperties... properties);
139 
140     /** Returns a copy of the properties currently set on the {@link IBuildInfo}. */
getProperties()141     public Set<BuildInfoProperties> getProperties();
142 
143     /**
144      * Helper method to retrieve a file with given a {@link BuildInfoFileKey}.
145      *
146      * @param key the {@link BuildInfoFileKey} that is requested.
147      * @return the image file or <code>null</code> if not found
148      */
getFile(BuildInfoFileKey key)149     public default File getFile(BuildInfoFileKey key) {
150         // Default implementation for projects that don't extend BuildInfo class.
151         return null;
152     }
153 
154     /**
155      * Helper method to retrieve a file with given name.
156      * @param name
157      * @return the image file or <code>null</code> if not found
158      */
getFile(String name)159     public File getFile(String name);
160 
161     /**
162      * Helper method to retrieve a {@link VersionedFile} with a given name.
163      *
164      * @param name
165      * @return The versioned file or <code>null</code> if not found
166      */
getVersionedFile(String name)167     public default VersionedFile getVersionedFile(String name) {
168         // Default implementation for projects that don't extend BuildInfo class.
169         return null;
170     }
171 
172     /**
173      * Helper method to retrieve a {@link VersionedFile} with a given a {@link BuildInfoFileKey}.
174      *
175      * @param key The {@link BuildInfoFileKey} requested.
176      * @return The versioned file or <code>null</code> if not found
177      */
getVersionedFile(BuildInfoFileKey key)178     public default VersionedFile getVersionedFile(BuildInfoFileKey key) {
179         // Default implementation for projects that don't extend BuildInfo class.
180         return null;
181     }
182 
183     /**
184      * Returns all {@link VersionedFile}s stored in this {@link BuildInfo}.
185      */
getFiles()186     public Collection<VersionedFile> getFiles();
187 
188     /**
189      * Helper method to retrieve a file version with given name.
190      * @param name
191      * @return the image version or <code>null</code> if not found
192      */
getVersion(String name)193     public String getVersion(String name);
194 
195     /**
196      * Helper method to retrieve a file version with given a {@link BuildInfoFileKey}.
197      *
198      * @param key The {@link BuildInfoFileKey} requested.
199      * @return the image version or <code>null</code> if not found
200      */
getVersion(BuildInfoFileKey key)201     public default String getVersion(BuildInfoFileKey key) {
202         // Default implementation for project that don't extends BuildInfo class.
203         return null;
204     }
205 
206     /**
207      * Stores an file with given name in this build info.
208      *
209      * @param name the unique name of the file
210      * @param file the local {@link File}
211      * @param version the file version
212      */
setFile(String name, File file, String version)213     public void setFile(String name, File file, String version);
214 
215     /**
216      * Stores an file given a {@link BuildInfoFileKey} in this build info.
217      *
218      * @param key the unique name of the file based on {@link BuildInfoFileKey}.
219      * @param file the local {@link File}
220      * @param version the file version
221      */
setFile(BuildInfoFileKey key, File file, String version)222     public default void setFile(BuildInfoFileKey key, File file, String version) {
223         // Default implementation for projects that don't extend BuildInfo class.
224     }
225 
226     /**
227      * Clean up any temporary build files
228      */
cleanUp()229     public void cleanUp();
230 
231     /** Version of {@link #cleanUp()} where some files are not deleted. */
cleanUp(List<File> doNotDelete)232     public void cleanUp(List<File> doNotDelete);
233 
234     /**
235      * Clones the {@link IBuildInfo} object.
236      */
clone()237     public IBuildInfo clone();
238 }
239