1 /* 2 * Copyright (C) 2018 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.config.remote; 17 18 import com.android.tradefed.build.BuildRetrievalError; 19 import com.android.tradefed.device.ITestDevice; 20 import com.android.tradefed.result.error.InfraErrorIdentifier; 21 22 import java.io.File; 23 import java.util.Map; 24 25 import javax.annotation.Nonnull; 26 27 /** 28 * Interface for objects that can resolve a remote file into a local one. For example: 29 * gs://bucket/dir/file.txt would be downloaded and changed to a local path. 30 */ 31 public interface IRemoteFileResolver { 32 33 /** 34 * Resolve the remote file. 35 * 36 * @param consideredFile {@link File} evaluated as remote. 37 * @return The resolved local file. 38 * @throws BuildRetrievalError if something goes wrong. 39 */ resolveRemoteFiles(File consideredFile)40 public default @Nonnull File resolveRemoteFiles(File consideredFile) 41 throws BuildRetrievalError { 42 throw new BuildRetrievalError( 43 "Should not have been called", InfraErrorIdentifier.ARTIFACT_UNSUPPORTED_PATH); 44 } 45 46 /** 47 * Resolve the remote file. 48 * 49 * @param consideredFile {@link File} evaluated as remote. 50 * @param queryArgs The arguments passed as a query to the URL. 51 * @return The resolved local file. 52 * @throws BuildRetrievalError if something goes wrong. 53 */ resolveRemoteFiles( File consideredFile, Map<String, String> queryArgs)54 public default @Nonnull File resolveRemoteFiles( 55 File consideredFile, Map<String, String> queryArgs) throws BuildRetrievalError { 56 return resolveRemoteFiles(consideredFile); 57 } 58 59 /** Returns the associated protocol supported for download. */ getSupportedProtocol()60 public @Nonnull String getSupportedProtocol(); 61 62 /** 63 * Optional way for the implementation to receive an {@ink ITestDevice} representation of the 64 * device under tests. 65 * 66 * @param device The {@link ITestDevice} of the current invocation. 67 */ setPrimaryDevice(ITestDevice device)68 public default void setPrimaryDevice(ITestDevice device) { 69 // Do nothing by default 70 } 71 } 72