Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2013 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.targetprep;
     17 
     18 import com.android.tradefed.build.IBuildInfo;
     19 import com.android.tradefed.config.Option;
     20 import com.android.tradefed.config.OptionClass;
     21 import com.android.tradefed.device.DeviceNotAvailableException;
     22 import com.android.tradefed.device.ITestDevice;
     23 
     24 import java.util.HashMap;
     25 import java.util.Map;
     26 
     27 /** A {@link ITargetPreparer} that adds arbitrary attributes to the {@link IBuildInfo}. */
     28 @OptionClass(alias = "buildinfo-preparer")
     29 public class BuildInfoAttributePreparer extends BaseTargetPreparer {
     30 
     31     @Option(name = "build-attribute", description = "build attributes to add")
     32     private Map<String, String> mBuildAttributes = new HashMap<String, String>();
     33 
     34     /**
     35      * {@inheritDoc}
     36      */
     37     @Override
     38     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
     39             BuildError, DeviceNotAvailableException {
     40         for (Map.Entry<String, String> attr : mBuildAttributes.entrySet()) {
     41             String key = attr.getKey();
     42             String value = attr.getValue();
     43             buildInfo.addBuildAttribute(key, value);
     44         }
     45     }
     46 }
     47