Cts框架解析(8)-IBuildProvider(四)

2015-01-27 22:35:41 · 作者: · 浏览: 138
BuildInfo} * * @param buildId the build id * @param testTag the test tag name * @param buildTargetName the build target name */ public BuildInfo(String buildId, String testTag, String buildTargetName) { mBuildId = buildId; mTestTag = testTag; mBuildTargetName = buildTargetName; mVersionedFileMap = new Hashtable (); } /** * Creates a {@link BuildInfo}, populated with attributes given in another build. * * @param buildToCopy */ BuildInfo(BuildInfo buildToCopy) { this(buildToCopy.getBuildId(), buildToCopy.getTestTag(), buildToCopy.getBuildTargetName()); addAllBuildAttributes(buildToCopy); try { addAllFiles(buildToCopy); } catch (IOException e) { throw new RuntimeException(e); } } /** * {@inheritDoc} */ @Override public String getBuildId() { return mBuildId; } /** * {@inheritDoc} */ @Override public String getTestTag() { return mTestTag; } /** * {@inheritDoc} */ @Override public String getDeviceSerial() { return mDeviceSerial; } /** * {@inheritDoc} */ @Override public Map getBuildAttributes() { return mBuildAttributes.getUniqueMap(); } /** * {@inheritDoc} */ @Override public String getBuildTargetName() { return mBuildTargetName; } /** * {@inheritDoc} */ @Override public void addBuildAttribute(String attributeName, String attributeva lue) { mBuildAttributes.put(attributeName, attributeva lue); } /** * Helper method to copy build attributes, branch, and flavor from other build. */ protected void addAllBuildAttributes(BuildInfo build) { mBuildAttributes.putAll(build.getAttributesMultiMap()); setBuildFlavor(build.getBuildFlavor()); setBuildBranch(build.getBuildBranch()); } protected MultiMap getAttributesMultiMap() { return mBuildAttributes; } /** * Helper method to copy all files from the other build. *

* Creates new hardlinks to the files so that each build will have a unique file path to the * file. *

* * @throws IOException if an exception is thrown when creating the hardlinks. */ protected void addAllFiles(BuildInfo build) throws IOException { for (Map.Entry fileEntry : build.getVersionedFileMap().entrySet()) { File origFile = fileEntry.getValue().getFile(); File copyFile; if (origFile.isDirectory()) { copyFile = FileUtil.createTempDir(fileEntry.getKey()); FileUtil.recursiveHardlink(origFile, copyFile); } else { // Only using createTempFile to create a unique dest filename copyFile = FileUtil.createTempFile(fileEntry.getKey(), FileUtil.getExtension(origFile.getName())); copyFile.delete(); FileUtil.hardlinkFile(origFile, copyFile); } setFile(fileEntry.getKey(), copyFile, fileEntry.getValue().getVersion()); } } protected Map getVersionedFileMap() { return mVersionedFileMap; } /** * {@inheritDoc} */ @Override public File getFile(String name) { VersionedFile fileRecord = mVersionedFileMap.get(name); if (fileRecord != null) { return fileRecord.getFile(); } return null; } /** * {@inheritDoc} */ @Override public Collection getFiles() { return mVersionedFileMap.values(); } /** * {@inheritDoc} */ @Override public String getVersion(String name) { VersionedFile fileRecord = mVersionedFileMap.get(name); if (fileRecord != null) { return fileRecord.getVersion(); } return null; } /** * {@inheritDoc} */ @Override public void setFile(String name, File file, String version) { if (mVersionedFileMap.containsKey(name)) { CLog.e("Device build already contains a file for %s in thread %s", name, Thread.currentThread().getName()); return; } mVersio