1 /* 2 * Copyright (C) 2011 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.Option.Importance; 20 import com.android.tradefed.config.OptionClass; 21 22 import java.io.File; 23 24 /** 25 * A {@link IBuildProvider} that constructs a {@link IFolderBuildInfo} based on a provided local 26 * path 27 */ 28 @OptionClass(alias = "local-folder") 29 public class LocalFolderBuildProvider extends StubBuildProvider { 30 31 private static final String FOLDER_OPTION_NAME = "folder-path"; 32 33 @Option(name = FOLDER_OPTION_NAME, description = 34 "the local filesystem path to build root directory to test.", 35 importance = Importance.IF_UNSET) 36 private File mLocalFolder = null; 37 38 /** 39 * {@inheritDoc} 40 */ 41 @Override getBuild()42 public IBuildInfo getBuild() throws BuildRetrievalError { 43 if (mLocalFolder == null) { 44 throw new IllegalArgumentException(String.format("missing --%s option", 45 FOLDER_OPTION_NAME)); 46 } 47 if (!mLocalFolder.exists()) { 48 throw new IllegalArgumentException(String.format("path '%s' does not exist. " + 49 "Please provide a valid folder via --%s", 50 mLocalFolder.getAbsolutePath(), FOLDER_OPTION_NAME)); 51 } 52 // utilize parent build provider to set build id, test target name etc attributes if 53 // desired 54 IBuildInfo parentBuild = super.getBuild(); 55 IFolderBuildInfo folderBuild = new FolderBuildInfo((BuildInfo)parentBuild); 56 folderBuild.setRootDir(mLocalFolder); 57 return folderBuild; 58 } 59 60 /** 61 * {@inheritDoc} 62 */ 63 @Override cleanUp(IBuildInfo info)64 public void cleanUp(IBuildInfo info) { 65 // ignore 66 } 67 } 68