aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tradefed/targetprep
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2015-05-12 17:01:44 -0700
committerGuang Zhu <guangzhu@google.com>2015-05-12 17:29:35 -0700
commita76ad1a3de77d6ce6c587de2fef2c80d1fd04214 (patch)
tree8e387e8ef2feae0d9048b78c9f6439d543a1f2f5 /src/com/android/tradefed/targetprep
parent84f361c01460f535ea72920e779c563e303f1697 (diff)
downloadtradefederation-a76ad1a3de77d6ce6c587de2fef2c80d1fd04214.tar.gz
Add a preparer to write build info to local file
Change-Id: I5efc1c9c2171bf5e0f30ddd433f9544e9d79b911
Diffstat (limited to 'src/com/android/tradefed/targetprep')
-rw-r--r--src/com/android/tradefed/targetprep/BuildInfoRecorder.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/com/android/tradefed/targetprep/BuildInfoRecorder.java b/src/com/android/tradefed/targetprep/BuildInfoRecorder.java
new file mode 100644
index 000000000..0d52cd87d
--- /dev/null
+++ b/src/com/android/tradefed/targetprep/BuildInfoRecorder.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tradefed.targetprep;
+
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.config.Option;
+import com.android.tradefed.config.OptionClass;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.log.LogUtil.CLog;
+import com.android.tradefed.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * An {@link ITargetPreparer} that writes build info meta data into a specified file.
+ * <p>
+ * The file is written in simple key-value pair format; each line of the file has:<br>
+ * <code>key=value</code><br>
+ * where <code>key</code> is a meta data field from {@link IBuildInfo}
+ * <p>
+ * Currently, only build id is written.
+ */
+@OptionClass(alias = "build-info-recorder")
+public class BuildInfoRecorder implements ITargetPreparer {
+
+ @Option(name = "build-info-file", description = "when specified, build info will be written "
+ + "into the file specified. Any existing file will be overwritten.")
+ private File mBuildInfoFile = null;
+
+ /*
+ * {@inheritDoc}
+ */
+ @Override
+ public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
+ BuildError, DeviceNotAvailableException {
+ if (mBuildInfoFile != null) {
+ try {
+ FileUtil.writeToFile(String.format("%s=%s\n", "build_id", buildInfo.getBuildId()),
+ mBuildInfoFile);
+ } catch (IOException ioe) {
+ CLog.e("Exception while writing build info into %s",
+ mBuildInfoFile.getAbsolutePath());
+ CLog.e(ioe);
+ }
+ }
+ }
+
+}