IBuildProvider接口中定义了三个方法

  1. /*
  2. * Copyright (C) 2010 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. /**
  19. * Responsible for providing info regarding the build under test.
  20. */
  21. public interface IBuildProvider {
  22.  
  23. /**
  24. * Retrieve the data for build under test.
  25. *
  26. * @return the {@link IBuildInfo} for build under test or <code>null</code> if no build is
  27. * available for testing
  28. * @throws BuildRetrievalError if build info failed to be retrieved due to an unexpected error
  29. */
  30. public IBuildInfo getBuild() throws BuildRetrievalError;
  31.  
  32. /**
  33. * Mark the given build as untested.
  34. * <p/>
  35. * Called in cases where TradeFederation has failed to complete testing on the build due to an
  36. * environment problem.
  37. *
  38. * @param info the {@link IBuildInfo} to reset
  39. */
  40. public void buildNotTested(IBuildInfo info);
  41.  
  42. /**
  43. * Clean up any temporary build files.
  44. */
  45. public void cleanUp(IBuildInfo info);
  46. }

该类主要是为了提供IBuildInfo信息的。所以目光转到IBuildInfo接口中:

  1. /*
  2. * Copyright (C) 2010 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.device.ITestDevice;
  19.  
  20. import java.io.File;
  21. import java.util.Collection;
  22. import java.util.Map;
  23.  
  24. /**
  25. * Holds information about the build under test.
  26. */
  27. public interface IBuildInfo {
  28.  
  29. /**
  30. * Default value when build ID is unknown.
  31. */
  32. public final static String UNKNOWN_BUILD_ID = "-1";
  33.  
  34. /**
  35. * Returns the unique identifier of build under test. Should never be null. Defaults to
  36. * {@link #UNKNOWN_BUILD_ID}.
  37. */
  38. public String getBuildId();
  39.  
  40. /**
  41. * Return a unique name for the tests being run.
  42. */
  43. public String getTestTag();
  44.  
  45. /**
  46. * Return complete name for the build being tested.
  47. * <p/>
  48. * A common implementation is to construct the build target name from a combination of
  49. * the build flavor and branch name. [ie (branch name)-(build flavor)]
  50. */
  51. public String getBuildTargetName();
  52.  
  53. /**
  54. * Optional method to return the type of build being tested.
  55. * <p/>
  56. * A common implementation for Android platform builds is to return
  57. * (build product)-(build os)-(build variant).
  58. * ie generic-linux-userdebug
  59. *
  60. * @return the build flavor or <code>null</code> if unset/not applicable
  61. */
  62. public String getBuildFlavor();
  63.  
  64. /**
  65. * @return the {@link ITestDevice} serial that this build was executed on. Returns <code>null
  66. * </code> if no device is associated with this build.
  67. */
  68. public String getDeviceSerial();
  69.  
  70. /**
  71. * Set the build flavor.
  72. *
  73. * @param buildFlavor
  74. */
  75. public void setBuildFlavor(String buildFlavor);
  76.  
  77. /**
  78. * Optional method to return the source control branch that the build being tested was
  79. * produced from.
  80. *
  81. * @return the build branch or <code>null</code> if unset/not applicable
  82. */
  83. public String getBuildBranch();
  84.  
  85. /**
  86. * Set the build branch
  87. *
  88. * @param branch the branch name
  89. */
  90. public void setBuildBranch(String branch);
  91.  
  92. /**
  93. * Set the {@link ITestDevice} serial associated with this build.
  94. *
  95. * @param serial the serial number of the {@link ITestDevice} that this build was executed with.
  96. */
  97. public void setDeviceSerial(String serial);
  98.  
  99. /**
  100. * Get a set of name-value pairs of additional attributes describing the build.
  101. *
  102. * @return a {@link Map} of build attributes. Will not be <code>null</code>, but may be empty.
  103. */
  104. public Map<String, String> getBuildAttributes();
  105.  
  106. /**
  107. * Add a build attribute
  108. *
  109. * @param attributeName the unique attribute name
  110. * @param attributeValue the attribute value
  111. */
  112. public void addBuildAttribute(String attributeName, String attributeValue);
  113.  
  114. /**
  115. * Helper method to retrieve a file with given name.
  116. * @param name
  117. * @return the image file or <code>null</code> if not found
  118. */
  119. public File getFile(String name);
  120.  
  121. /**
  122. * Returns all {@link VersionedFile}s stored in this {@link BuildInfo}.
  123. */
  124. public Collection<VersionedFile> getFiles();
  125.  
  126. /**
  127. * Helper method to retrieve a file version with given name.
  128. * @param name
  129. * @return the image version or <code>null</code> if not found
  130. */
  131. public String getVersion(String name);
  132.  
  133. /**
  134. * Stores an file with given name in this build info.
  135. *
  136. * @param name the unique name of the file
  137. * @param file the local {@link File}
  138. * @param version the file version
  139. */
  140. public void setFile(String name, File file, String version);
  141.  
  142. /**
  143. * Clean up any temporary build files
  144. */
  145. public void cleanUp();
  146.  
  147. /**
  148. * Clones the {@link IBuildInfo} object.
  149. */
  150. public IBuildInfo clone();
  151. }

该接口中定义了一些方法都是跟属性相关的。事实上如今BuildInfo中。

  1. /*
  2. * Copyright (C) 2010 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.log.LogUtil.CLog;
  19. import com.android.tradefed.util.FileUtil;
  20. import com.android.tradefed.util.MultiMap;
  21. import com.android.tradefed.util.UniqueMultiMap;
  22. import com.google.common.base.Objects;
  23.  
  24. import java.io.File;
  25. import java.io.IOException;
  26. import java.util.Collection;
  27. import java.util.Hashtable;
  28. import java.util.Map;
  29.  
  30. /**
  31. * Generic implementation of a {@link IBuildInfo}.
  32. */
  33. public class BuildInfo implements IBuildInfo {
  34. private String mBuildId = "0";
  35. private String mTestTag = "stub";
  36. private String mBuildTargetName = "stub";
  37. private final UniqueMultiMap<String, String> mBuildAttributes =
  38. new UniqueMultiMap<String, String>();
  39. private Map<String, VersionedFile> mVersionedFileMap;
  40. private String mBuildFlavor = null;
  41. private String mBuildBranch = null;
  42. private String mDeviceSerial = null;
  43.  
  44. /**
  45. * Creates a {@link BuildInfo} using default attribute values.
  46. */
  47. public BuildInfo() {
  48. mVersionedFileMap = new Hashtable<String, VersionedFile>();
  49. }
  50.  
  51. /**
  52. * Creates a {@link BuildInfo}
  53. *
  54. * @param buildId the build id
  55. * @param testTag the test tag name
  56. * @param buildTargetName the build target name
  57. */
  58. public BuildInfo(String buildId, String testTag, String buildTargetName) {
  59. mBuildId = buildId;
  60. mTestTag = testTag;
  61. mBuildTargetName = buildTargetName;
  62. mVersionedFileMap = new Hashtable<String, VersionedFile>();
  63. }
  64.  
  65. /**
  66. * Creates a {@link BuildInfo}, populated with attributes given in another build.
  67. *
  68. * @param buildToCopy
  69. */
  70. BuildInfo(BuildInfo buildToCopy) {
  71. this(buildToCopy.getBuildId(), buildToCopy.getTestTag(), buildToCopy.getBuildTargetName());
  72. addAllBuildAttributes(buildToCopy);
  73. try {
  74. addAllFiles(buildToCopy);
  75. } catch (IOException e) {
  76. throw new RuntimeException(e);
  77. }
  78. }
  79.  
  80. /**
  81. * {@inheritDoc}
  82. */
  83. @Override
  84. public String getBuildId() {
  85. return mBuildId;
  86. }
  87.  
  88. /**
  89. * {@inheritDoc}
  90. */
  91. @Override
  92. public String getTestTag() {
  93. return mTestTag;
  94. }
  95.  
  96. /**
  97. * {@inheritDoc}
  98. */
  99. @Override
  100. public String getDeviceSerial() {
  101. return mDeviceSerial;
  102. }
  103.  
  104. /**
  105. * {@inheritDoc}
  106. */
  107. @Override
  108. public Map<String, String> getBuildAttributes() {
  109. return mBuildAttributes.getUniqueMap();
  110. }
  111.  
  112. /**
  113. * {@inheritDoc}
  114. */
  115. @Override
  116. public String getBuildTargetName() {
  117. return mBuildTargetName;
  118. }
  119.  
  120. /**
  121. * {@inheritDoc}
  122. */
  123. @Override
  124. public void addBuildAttribute(String attributeName, String attributeValue) {
  125. mBuildAttributes.put(attributeName, attributeValue);
  126. }
  127.  
  128. /**
  129. * Helper method to copy build attributes, branch, and flavor from other build.
  130. */
  131. protected void addAllBuildAttributes(BuildInfo build) {
  132. mBuildAttributes.putAll(build.getAttributesMultiMap());
  133. setBuildFlavor(build.getBuildFlavor());
  134. setBuildBranch(build.getBuildBranch());
  135. }
  136.  
  137. protected MultiMap<String, String> getAttributesMultiMap() {
  138. return mBuildAttributes;
  139. }
  140.  
  141. /**
  142. * Helper method to copy all files from the other build.
  143. * <p>
  144. * Creates new hardlinks to the files so that each build will have a unique file path to the
  145. * file.
  146. * </p>
  147. *
  148. * @throws IOException if an exception is thrown when creating the hardlinks.
  149. */
  150. protected void addAllFiles(BuildInfo build) throws IOException {
  151. for (Map.Entry<String, VersionedFile> fileEntry : build.getVersionedFileMap().entrySet()) {
  152. File origFile = fileEntry.getValue().getFile();
  153. File copyFile;
  154. if (origFile.isDirectory()) {
  155. copyFile = FileUtil.createTempDir(fileEntry.getKey());
  156. FileUtil.recursiveHardlink(origFile, copyFile);
  157. } else {
  158. // Only using createTempFile to create a unique dest filename
  159. copyFile = FileUtil.createTempFile(fileEntry.getKey(),
  160. FileUtil.getExtension(origFile.getName()));
  161. copyFile.delete();
  162. FileUtil.hardlinkFile(origFile, copyFile);
  163. }
  164. setFile(fileEntry.getKey(), copyFile, fileEntry.getValue().getVersion());
  165. }
  166. }
  167.  
  168. protected Map<String, VersionedFile> getVersionedFileMap() {
  169. return mVersionedFileMap;
  170. }
  171.  
  172. /**
  173. * {@inheritDoc}
  174. */
  175. @Override
  176. public File getFile(String name) {
  177. VersionedFile fileRecord = mVersionedFileMap.get(name);
  178. if (fileRecord != null) {
  179. return fileRecord.getFile();
  180. }
  181. return null;
  182. }
  183.  
  184. /**
  185. * {@inheritDoc}
  186. */
  187. @Override
  188. public Collection<VersionedFile> getFiles() {
  189. return mVersionedFileMap.values();
  190. }
  191.  
  192. /**
  193. * {@inheritDoc}
  194. */
  195. @Override
  196. public String getVersion(String name) {
  197. VersionedFile fileRecord = mVersionedFileMap.get(name);
  198. if (fileRecord != null) {
  199. return fileRecord.getVersion();
  200. }
  201. return null;
  202. }
  203.  
  204. /**
  205. * {@inheritDoc}
  206. */
  207. @Override
  208. public void setFile(String name, File file, String version) {
  209. if (mVersionedFileMap.containsKey(name)) {
  210. CLog.e("Device build already contains a file for %s in thread %s", name,
  211. Thread.currentThread().getName());
  212. return;
  213. }
  214. mVersionedFileMap.put(name, new VersionedFile(file, version));
  215. }
  216.  
  217. /**
  218. * {@inheritDoc}
  219. */
  220. @Override
  221. public void cleanUp() {
  222. for (VersionedFile fileRecord : mVersionedFileMap.values()) {
  223. FileUtil.recursiveDelete(fileRecord.getFile());
  224. }
  225. mVersionedFileMap.clear();
  226. }
  227.  
  228. /**
  229. * {@inheritDoc}
  230. */
  231. @Override
  232. public IBuildInfo clone() {
  233. BuildInfo copy = new BuildInfo(mBuildId, mTestTag, mBuildTargetName);
  234. copy.addAllBuildAttributes(this);
  235. try {
  236. copy.addAllFiles(this);
  237. } catch (IOException e) {
  238. throw new RuntimeException(e);
  239. }
  240. copy.setBuildBranch(mBuildBranch);
  241. copy.setBuildFlavor(mBuildFlavor);
  242.  
  243. return copy;
  244. }
  245.  
  246. /**
  247. * {@inheritDoc}
  248. */
  249. @Override
  250. public String getBuildFlavor() {
  251. return mBuildFlavor;
  252. }
  253.  
  254. /**
  255. * {@inheritDoc}
  256. */
  257. @Override
  258. public void setBuildFlavor(String buildFlavor) {
  259. mBuildFlavor = buildFlavor;
  260. }
  261.  
  262. /**
  263. * {@inheritDoc}
  264. */
  265. @Override
  266. public String getBuildBranch() {
  267. return mBuildBranch;
  268. }
  269.  
  270. /**
  271. * {@inheritDoc}
  272. */
  273. @Override
  274. public void setBuildBranch(String branch) {
  275. mBuildBranch = branch;
  276. }
  277.  
  278. /**
  279. * {@inheritDoc}
  280. */
  281. @Override
  282. public void setDeviceSerial(String serial) {
  283. mDeviceSerial = serial;
  284. }
  285.  
  286. /**
  287. * {@inheritDoc}
  288. */
  289. @Override
  290. public int hashCode() {
  291. return Objects.hashCode(mBuildAttributes, mBuildBranch, mBuildFlavor, mBuildId,
  292. mBuildTargetName, mTestTag, mDeviceSerial);
  293. }
  294.  
  295. /**
  296. * {@inheritDoc}
  297. */
  298. @Override
  299. public boolean equals(Object obj) {
  300. if (this == obj) {
  301. return true;
  302. }
  303. if (obj == null) {
  304. return false;
  305. }
  306. if (getClass() != obj.getClass()) {
  307. return false;
  308. }
  309. BuildInfo other = (BuildInfo) obj;
  310. return Objects.equal(mBuildAttributes, other.mBuildAttributes) &&
  311. Objects.equal(mBuildBranch, other.mBuildBranch) &&
  312. Objects.equal(mBuildFlavor, other.mBuildFlavor) &&
  313. Objects.equal(mBuildId, other.mBuildId) &&
  314. Objects.equal(mBuildTargetName, other.mBuildTargetName) &&
  315. Objects.equal(mTestTag, other.mTestTag) &&
  316. Objects.equal(mDeviceSerial, other.mDeviceSerial);
  317. }
  318. }

提供的属性有build的id号,build的目标名称。測试标签。根文件夹,build的分支,測试类型。

关机要理解build是什么意思,我还不是太了解build这个意义,临时先用build来取代吧,等我了解了。再做解释。

在原生的cts中。使用的是CtsBuildProvider。非常easy的就是把cts的根文件夹属性设置上,然后是buildId。測试目标。build命令设置好就返回了。可是你假设要加入你自己的实现类,肯定不是简单的这么一点代码。比方你要做的測试时測试你的系统,那么这里面提供的东西就多了。首先你的系统存放的地址,分支号,要build的版本等等都要在这里面获取并存到buildinfo对象中返回给TestInvocation中。

  1. /*
  2. * Copyright (C) 2010 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.cts.tradefed.build;
  17.  
  18. import com.android.tradefed.build.FolderBuildInfo;
  19. import com.android.tradefed.build.IBuildInfo;
  20. import com.android.tradefed.build.IBuildProvider;
  21. import com.android.tradefed.build.IFolderBuildInfo;
  22. import com.android.tradefed.config.Option;
  23.  
  24. import java.io.File;
  25.  
  26. /**
  27. * A simple {@link IBuildProvider} that uses a pre-existing CTS install.
  28. */
  29. public class CtsBuildProvider implements IBuildProvider {
  30.  
  31. @Option(name="cts-install-path", description="the path to the cts installation to use")
  32. private String mCtsRootDirPath = System.getProperty("CTS_ROOT");
  33.  
  34. public static final String CTS_BUILD_VERSION = "4.4_r1.95";
  35.  
  36. /**
  37. * {@inheritDoc}
  38. */
  39. @Override
  40. public IBuildInfo getBuild() {
  41. if (mCtsRootDirPath == null) {
  42. throw new IllegalArgumentException("Missing --cts-install-path");
  43. }
  44. IFolderBuildInfo ctsBuild = new FolderBuildInfo(CTS_BUILD_VERSION, "cts", "cts");
  45. ctsBuild.setRootDir(new File(mCtsRootDirPath));
  46. return ctsBuild;
  47. }
  48.  
  49. /**
  50. * {@inheritDoc}
  51. */
  52. @Override
  53. public void buildNotTested(IBuildInfo info) {
  54. // ignore
  55. }
  56.  
  57. /**
  58. * {@inheritDoc}
  59. */
  60. @Override
  61. public void cleanUp(IBuildInfo info) {
  62. // ignore
  63. }
  64. }

Cts框架解析(8)-IBuildProvider的更多相关文章

  1. Cts框架解析(2)-cts调试环境的搭建

    上一篇文章中说了怎样在windows搭建cts以及执行cts进行測试.这篇文章来讲讲怎样在eclipse中配置源代码,进行debug调试. 下载 cts源代码地址:https://android.go ...

  2. Cts框架解析(7)-任务运行的调度室

    TestInvocation /** * {@inheritDoc} */ @Override public void invoke(ITestDevice device, IConfiguratio ...

  3. Cts框架解析(6)-任务的运行

    前两篇讲了任务的加入和9大项配置,这篇讲任务的运行. 任务的运行 任务的运行在CommandScheduler的run方法中,所以删除全部的断点,在run方法中打上断点,重新启动启动debug: 先看 ...

  4. Cts框架解析(1)-windows下cts配置

    环境搭建 下载 cts工具的下载地址:http://source.android.com/compatibility/downloads.html windows选择Android4.4 R3 Com ...

  5. Cts框架解析(12)-ITargetPreparer

    測试开启前的设备系统准备工作. 接口 /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Ap ...

  6. Cts框架解析(15)-任务运行完

    case运行完成后.会回到CtsTest的run方法中: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXRmb290YmFsbA==/font/5a6L ...

  7. [转载]iOS 10 UserNotifications 框架解析

    活久见的重构 - iOS 10 UserNotifications 框架解析 TL;DR iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotifica ...

  8. ABP使用及框架解析系列 - [Unit of Work part.1-概念及使用]

    前言 ABP ABP是“ASP.NET Boilerplate Project”的简称. ABP的官方网站:http://www.aspnetboilerplate.com ABP在Github上的开 ...

  9. ABP使用及框架解析系列 - [Unit of Work part.2-框架实现]

    前言 ABP ABP是“ASP.NET Boilerplate Project”的简称. ABP的官方网站:http://www.aspnetboilerplate.com ABP在Github上的开 ...

随机推荐

  1. RMAN的show,list,crosscheck,delete命令

    1.SHOW命令:      显示rman配置: RMAN> show all; 2.REPORT命令: 2.1.RMAN> report schema 报告目标数据库的物理结构; 2.2 ...

  2. gulp入门学习实例

    好久都没有更新博客了,每天繁忙的工作,下班之后都不想开设备了.前段时间有幸学习了一下gulp这款构建工具,现在和大家分享一下. 为什么使用Gulp Gulp基于Node.js的前端构建工具,通过Gul ...

  3. Windows消息机制(转)1

    Windows的应用程序一般包含窗口(Window),它主要为用户提供一种可视化的交互方式,窗口是总是在某个线程(Thread)内创建的.Windows系统通过消息机制来管理交互,消息(Message ...

  4. 在Fedora20上安装Oracle 12c

    本文将引导大家在Fedora20的环境下成功安装Oracle12c. 安装前的准备 编辑/etc/hosts文件,添加本机名称 编辑/etc/selinux/config文件 编辑/etc/redha ...

  5. hdu5338 ZZX and Permutations(贪心、线段树)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud ZZX and Permutations Time Limit: 6000/300 ...

  6. hdfs-over-ftp安装与配置

    hdfs-over-ftp是一个开源,简单易用的实现了对HDFS系统的下载和上传功能的小工具.可以作为管理工具来使用,快捷方便. 1 安装jdk(1.6以上版本)并配置环境变量分别执行java -ve ...

  7. Struts+Spring+Hibernate进阶开端(一)

    入行就听说SSH,起初还以为是一个东西,具体内容就更加不详细了,总觉得高端大气上档次,经过学习之后才发现,不仅仅是高大上,更是低调奢华有内涵,经过一段时间的研究和学习SSH框架的基本原理与思想,总算接 ...

  8. eclipse 添加jar包的方式

    参考资料地址:http://blog.csdn.net/mazhaojuan/article/details/21403717

  9. Kendo Web UI Grid里时间格式转换

    我和大家分享一下我的kendo的学习心得.如果不好的地方多多包含或者给我留言请看图 kendo里时间格式如图Oder Date列里的格式.但是我们想把时间转换成中国人习惯的格式.如Shipped Da ...

  10. js中constructor的作用

    在学习过程中对js的constructor的作用产生了疑问.下面是学习的资料进行梳理 function Person(area){ this.type = 'person'; this.area = ...