1 /*
2  * Copyright (C) 2020 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.yaml;
17 
18 import com.android.tradefed.build.DependenciesResolver;
19 import com.android.tradefed.config.Configuration;
20 import com.android.tradefed.config.OptionSetter;
21 import com.android.tradefed.log.FileLogger;
22 import com.android.tradefed.result.suite.SuiteResultReporter;
23 
24 import java.io.File;
25 
26 /** Loader for the default objects available in AOSP. */
27 public class OpenObjectLoader implements IDefaultObjectLoader {
28 
29     @Override
addDefaultObjects(LoaderConfiguration loadConfiguration)30     public void addDefaultObjects(LoaderConfiguration loadConfiguration) {
31         // Only add the objects below if it's created as a stand alone configuration, in suite as
32         // a module, it will be resolving object from the top level suite.
33         if (loadConfiguration.createdAsModule()) {
34             return;
35         }
36         // Logger
37         loadConfiguration
38                 .getConfigDef()
39                 .addConfigObjectDef(Configuration.LOGGER_TYPE_NAME, FileLogger.class.getName());
40         // Result Reporters
41         loadConfiguration
42                 .getConfigDef()
43                 .addConfigObjectDef(
44                         Configuration.RESULT_REPORTER_TYPE_NAME,
45                         SuiteResultReporter.class.getName());
46         // Build
47         int classCount =
48                 loadConfiguration
49                         .getConfigDef()
50                         .addConfigObjectDef(
51                                 Configuration.BUILD_PROVIDER_TYPE_NAME,
52                                 DependenciesResolver.class.getName());
53         // Set all the dependencies on the provider
54         for (String dependency : loadConfiguration.getDependencies()) {
55             String optionName =
56                     String.format(
57                             "%s%c%d%c%s",
58                             DependenciesResolver.class.getName(),
59                             OptionSetter.NAMESPACE_SEPARATOR,
60                             classCount,
61                             OptionSetter.NAMESPACE_SEPARATOR,
62                             "dependency");
63             loadConfiguration
64                     .getConfigDef()
65                     .addOptionDef(
66                             optionName,
67                             new File(dependency).getName(),
68                             dependency,
69                             loadConfiguration.getConfigDef().getName(),
70                             Configuration.BUILD_PROVIDER_TYPE_NAME);
71         }
72     }
73 }
74