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.cts.tradefed.build; 17 18 import com.android.tradefed.build.BuildRetrievalError; 19 import com.android.tradefed.build.DeviceBuildInfo; 20 import com.android.tradefed.build.FolderBuildInfo; 21 import com.android.tradefed.build.IBuildInfo; 22 import com.android.tradefed.build.IBuildProvider; 23 import com.android.tradefed.build.IDeviceBuildProvider; 24 import com.android.tradefed.build.IFolderBuildInfo; 25 import com.android.tradefed.config.Option; 26 import com.android.tradefed.device.DeviceNotAvailableException; 27 import com.android.tradefed.device.ITestDevice; 28 29 import java.io.File; 30 import java.util.regex.Pattern; 31 32 /** 33 * A simple {@link IBuildProvider} that uses a pre-existing CTS install. 34 */ 35 public class CtsBuildProvider implements IDeviceBuildProvider { 36 37 private static final Pattern RELEASE_BUILD = Pattern.compile("^[A-Z]{3}\\d{2}[A-Z]{0,1}$"); 38 39 @Option(name="cts-install-path", description="the path to the cts installation to use") 40 private String mCtsRootDirPath = System.getProperty("CTS_ROOT"); 41 42 @Option(name="use-device-build-info", description="Bootstrap build info from device") 43 private boolean mUseDeviceBuildInfo = false; 44 45 @Option(name="test-tag", description="test tag name to supply.") 46 private String mTestTag = "cts"; 47 48 @Option(name="branch", description="build branch name to supply.") 49 private String mBranch = null; 50 51 public static final String CTS_BUILD_VERSION = "7.0_r0"; 52 public static final String CTS_PACKAGE = "com.android.cts.tradefed.testtype"; 53 54 /** 55 * {@inheritDoc} 56 */ 57 @Override getBuild()58 public IBuildInfo getBuild() { 59 if (mCtsRootDirPath == null) { 60 throw new IllegalArgumentException("Missing --cts-install-path"); 61 } 62 IFolderBuildInfo ctsBuild = new FolderBuildInfo( 63 Package.getPackage(CTS_PACKAGE).getImplementationVersion(), 64 mTestTag, mTestTag); 65 ctsBuild.setRootDir(new File(mCtsRootDirPath)); 66 if (mBranch != null) { 67 ctsBuild.setBuildBranch(mBranch); 68 } 69 return ctsBuild; 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 @Override getBuild(ITestDevice device)76 public IBuildInfo getBuild(ITestDevice device) 77 throws BuildRetrievalError, DeviceNotAvailableException { 78 if (!mUseDeviceBuildInfo) { 79 // return a regular build info without extracting device attributes into standard 80 // build info fields 81 return getBuild(); 82 } else { 83 String buildId = device.getBuildId(); 84 String buildFlavor = device.getBuildFlavor(); 85 IBuildInfo info = new DeviceBuildInfo(buildId, mTestTag, buildFlavor); 86 if (mBranch == null) { 87 // if branch is not specified via param, make a pseudo branch name based on platform 88 // version and product info from device 89 mBranch = String.format("%s-%s-%s-%s", 90 device.getProperty("ro.product.brand"), 91 device.getProperty("ro.product.name"), 92 device.getProductVariant(), 93 device.getProperty("ro.build.version.release")); 94 } 95 info.setBuildBranch(mBranch); 96 info.setBuildFlavor(buildFlavor); 97 String buildAlias = device.getBuildAlias(); 98 if (RELEASE_BUILD.matcher(buildAlias).matches()) { 99 info.addBuildAttribute("build_alias", buildAlias); 100 } 101 return info; 102 } 103 } 104 105 /** 106 * {@inheritDoc} 107 */ 108 @Override buildNotTested(IBuildInfo info)109 public void buildNotTested(IBuildInfo info) { 110 // ignore 111 } 112 113 /** 114 * {@inheritDoc} 115 */ 116 @Override cleanUp(IBuildInfo info)117 public void cleanUp(IBuildInfo info) { 118 // ignore 119 } 120 } 121