diff options
author | jdesprez <jdesprez@google.com> | 2017-09-07 16:38:29 -0700 |
---|---|---|
committer | jdesprez <jdesprez@google.com> | 2017-09-08 16:16:42 -0700 |
commit | a2c7ef37a4eae38b175df8939380f29781289910 (patch) | |
tree | e1cb362e21dfcac3f073af3c8b106afcbadfa944 | |
parent | 0f93a550de4cf9433086dae4a76b1525ba54d05d (diff) | |
download | tradefederation-a2c7ef37a4eae38b175df8939380f29781289910.tar.gz |
Create an explicitle step for serializing the context
In order to be able to customize it, allow a specific
serialize context method.
Test: unit tests, see other CL
Bug: 62720644
Change-Id: I2e50c48e145fdf8db18fb5fd43d8e3f4fb86ecbc
-rw-r--r-- | src/com/android/tradefed/sandbox/TradefedSandbox.java | 13 | ||||
-rw-r--r-- | src/com/android/tradefed/util/ZipUtil2.java | 14 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/com/android/tradefed/sandbox/TradefedSandbox.java b/src/com/android/tradefed/sandbox/TradefedSandbox.java index 7fa1f6293..7f1f8c442 100644 --- a/src/com/android/tradefed/sandbox/TradefedSandbox.java +++ b/src/com/android/tradefed/sandbox/TradefedSandbox.java @@ -136,7 +136,7 @@ public class TradefedSandbox implements ISandbox { // Prepare the context try { - mSerializedContext = SerializationUtil.serialize(context); + mSerializedContext = prepareContext(context); } catch (IOException e) { return e; } @@ -194,4 +194,15 @@ public class TradefedSandbox implements ISandbox { IRunUtil createRunUtil() { return new RunUtil(); } + + /** + * Prepare and serialize the {@link IInvocationContext}. + * + * @param context the {@link IInvocationContext} to be prepared. + * @return the serialized {@link IInvocationContext}. + * @throws IOException + */ + protected File prepareContext(IInvocationContext context) throws IOException { + return SerializationUtil.serialize(context); + } } diff --git a/src/com/android/tradefed/util/ZipUtil2.java b/src/com/android/tradefed/util/ZipUtil2.java index 17046e949..aa9256d48 100644 --- a/src/com/android/tradefed/util/ZipUtil2.java +++ b/src/com/android/tradefed/util/ZipUtil2.java @@ -72,6 +72,20 @@ public class ZipUtil2 { } /** + * Utility method to extract a zip file into a given directory. The zip file being presented as + * a {@link File}. + * + * @param zipFile a {@link File} pointing to a zip file. + * @param destDir the local dir to extract file to + * @throws IOException if failed to extract file + */ + public static void extractZip(File zipFile, File destDir) throws IOException { + try (ZipFile zip = new ZipFile(zipFile)) { + extractZip(zip, destDir); + } + } + + /** * Utility method to extract one specific file from zip file into a tmp file * * @param zipFile the {@link ZipFile} to extract |