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.config.Option; 19 import com.android.tradefed.config.OptionClass; 20 import com.android.tradefed.log.LogUtil.CLog; 21 22 import java.util.Arrays; 23 import java.util.HashMap; 24 import java.util.HashSet; 25 import java.util.Map; 26 import java.util.Set; 27 28 /** 29 * No-op empty implementation of a {@link IBuildProvider}. 30 * <p/> 31 * Will provide an empty {@link BuildInfo} with the provided values from options. 32 */ 33 @OptionClass(alias="stub") 34 public class StubBuildProvider implements IBuildProvider { 35 36 @Option(name="build-id", description="build id to supply.") 37 private String mBuildId = "0"; 38 39 @Option(name="build-target", description="build target name to supply.") 40 private String mBuildTargetName = "stub"; 41 42 @Option(name="branch", description="build branch name to supply.") 43 private String mBranch = null; 44 45 @Option(name="build-flavor", description="build flavor name to supply.") 46 private String mBuildFlavor = null; 47 48 @Option(name = "build-os", description = "build os name to supply.") 49 private String mBuildOs = null; 50 51 @Option(name="build-attribute", description="build attributes to supply.") 52 private Map<String, String> mBuildAttributes = new HashMap<String,String>(); 53 54 @Option( 55 name = "return-null", 56 description = "force the stub provider to return a null build. Used for testing." 57 ) 58 private boolean mReturnNull = false; 59 60 @Option( 61 name = "throw-build-error", 62 description = "force the stub provider to throw a BuildRetrievalError. Used for testing." 63 ) 64 private boolean mThrowError = false; 65 66 /** Standard platforms */ 67 private static final Set<String> STANDARD_PLATFORMS = 68 new HashSet<String>(Arrays.asList("linux", "mac")); 69 70 /** 71 * {@inheritDoc} 72 */ 73 @Override getBuild()74 public IBuildInfo getBuild() throws BuildRetrievalError { 75 if (mReturnNull) { 76 CLog.d("Returning a null build."); 77 return null; 78 } 79 if (mThrowError) { 80 throw new BuildRetrievalError("stub failed to get build."); 81 } 82 CLog.d("skipping build provider step"); 83 BuildInfo stubBuild = new BuildInfo(mBuildId, mBuildTargetName); 84 stubBuild.setBuildBranch(mBranch); 85 stubBuild.setBuildFlavor(mBuildFlavor); 86 87 String buildTarget = mBuildFlavor; 88 if (!STANDARD_PLATFORMS.contains(mBuildOs)) { 89 buildTarget += "_" + mBuildOs; 90 } 91 stubBuild.addBuildAttribute("build_target", buildTarget); 92 93 for (Map.Entry<String, String> attributeEntry : mBuildAttributes.entrySet()) { 94 stubBuild.addBuildAttribute(attributeEntry.getKey(), attributeEntry.getValue()); 95 } 96 return stubBuild; 97 } 98 99 /** 100 * {@inheritDoc} 101 */ 102 @Override buildNotTested(IBuildInfo info)103 public void buildNotTested(IBuildInfo info) { 104 // ignore 105 } 106 107 /** 108 * {@inheritDoc} 109 */ 110 @Override cleanUp(IBuildInfo info)111 public void cleanUp(IBuildInfo info) { 112 // ignore 113 } 114 } 115