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