1 /*
2  * Copyright (C) 2017 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.invoker.shard;
17 
18 import com.android.tradefed.build.ExistingBuildProvider;
19 import com.android.tradefed.build.IBuildInfo;
20 import com.android.tradefed.config.ConfigurationException;
21 import com.android.tradefed.config.IConfiguration;
22 import com.android.tradefed.invoker.IInvocationContext;
23 import com.android.tradefed.log.LogUtil.CLog;
24 
25 /**
26  * Helper class that handles cloning a build info from the command line. Shard will get the build
27  * info directly by using {@link ExistingBuildProvider} instead of downloading anything.
28  */
29 public class ShardBuildCloner {
30 
31     /**
32      * Helper to set the Sharded configuration build provider to the {@link ExistingBuildProvider}.
33      *
34      * @param fromConfig Original configuration
35      * @param toConfig cloned configuration recreated from the command line.
36      * @param context invocation context
37      */
cloneBuildInfos( IConfiguration fromConfig, IConfiguration toConfig, IInvocationContext context)38     public static void cloneBuildInfos(
39             IConfiguration fromConfig, IConfiguration toConfig, IInvocationContext context) {
40         for (String deviceName : context.getDeviceConfigNames()) {
41             IBuildInfo toBuild = context.getBuildInfo(deviceName).clone();
42             try {
43                 toConfig.getDeviceConfigByName(deviceName)
44                         .addSpecificConfig(
45                                 new ExistingBuildProvider(
46                                         toBuild,
47                                         fromConfig
48                                                 .getDeviceConfigByName(deviceName)
49                                                 .getBuildProvider()));
50             } catch (ConfigurationException e) {
51                 // Should never happen, no action taken
52                 CLog.e(e);
53             }
54         }
55     }
56 }
57