diff options
author | Guang Zhu <guangzhu@google.com> | 2015-05-13 19:31:58 -0700 |
---|---|---|
committer | Guang Zhu <guangzhu@google.com> | 2015-05-13 19:50:50 -0700 |
commit | cb3d1cd1cc0c852bb3a07cd5fc7ecd2e54871750 (patch) | |
tree | 5ff547d0a5d6354ac15f908fa587150c5a560a76 /src/com/android/tradefed/targetprep | |
parent | a76ad1a3de77d6ce6c587de2fef2c80d1fd04214 (diff) | |
download | tradefederation-cb3d1cd1cc0c852bb3a07cd5fc7ecd2e54871750.tar.gz |
add parameter to select alt dir behavior
They can be used as either override or fallback for the
regularly configured locations.
Change-Id: I9ea820a88ee371c0ed4cd21e21c5dfdadda28aa6
Diffstat (limited to 'src/com/android/tradefed/targetprep')
3 files changed, 86 insertions, 6 deletions
diff --git a/src/com/android/tradefed/targetprep/AltDirBehavior.java b/src/com/android/tradefed/targetprep/AltDirBehavior.java new file mode 100644 index 000000000..f5e5cadcb --- /dev/null +++ b/src/com/android/tradefed/targetprep/AltDirBehavior.java @@ -0,0 +1,36 @@ +/* + * 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; + +/** + * An enum to define alternative directory behaviors for various test artifact installers/pushers + * <p> + * @see {@link TestAppInstallSetup}, {@link TestFilePushSetup} + */ +public enum AltDirBehavior { + /** + * The alternative directories should be used as a fallback to look up the build artifacts. That + * is, if build artifacts cannot be found at the regularly configured location. + */ + FALLBACK, + + /** + * The alternative directories should be used as an override to look up the build artifacts. + * That is, alternative directories should be searched first for build artifacts. + */ + OVERRIDE, +} diff --git a/src/com/android/tradefed/targetprep/TestAppInstallSetup.java b/src/com/android/tradefed/targetprep/TestAppInstallSetup.java index ad3bc5df0..0c9cc6cf4 100644 --- a/src/com/android/tradefed/targetprep/TestAppInstallSetup.java +++ b/src/com/android/tradefed/targetprep/TestAppInstallSetup.java @@ -76,6 +76,10 @@ public class TestAppInstallSetup implements ITargetCleaner, IAbiReceiver { + "first.") private List<File> mAltDirs = new ArrayList<>(); + @Option(name = "alt-dir-behavior", description = "The order of alternate directory to be used " + + "when searching for apks to install") + private AltDirBehavior mAltDirBehavior = AltDirBehavior.FALLBACK; + private IAbi mAbi = null; private List<String> mPackagesInstalled = new ArrayList<>(); @@ -110,15 +114,26 @@ public class TestAppInstallSetup implements ITargetCleaner, IAbiReceiver { // Files in out dir will bein in uses data/app/apk_name dirs.add(FileUtil.getFileForPath(dir, "data", "app", apkBase)); } + // reverse the order so ones provided via command line last can be searched first + Collections.reverse(dirs); - // Add test dirs last so they will be first when list is reversed + List<File> expandedTestDirs = new ArrayList<>(); if (buildInfo instanceof IDeviceBuildInfo) { File testsDir = ((IDeviceBuildInfo)buildInfo).getTestsDir(); if (testsDir != null && testsDir.exists()) { - dirs.add(FileUtil.getFileForPath(testsDir, "DATA", "app")); - dirs.add(FileUtil.getFileForPath(testsDir, "DATA", "app", apkBase)); + expandedTestDirs.add(FileUtil.getFileForPath(testsDir, "DATA", "app")); + expandedTestDirs.add(FileUtil.getFileForPath(testsDir, "DATA", "app", apkBase)); } } + if (mAltDirBehavior == AltDirBehavior.FALLBACK) { + // alt dirs are appended after build artifact dirs + expandedTestDirs.addAll(dirs); + dirs = expandedTestDirs; + } else if (mAltDirBehavior == AltDirBehavior.OVERRIDE) { + dirs.addAll(expandedTestDirs); + } else { + throw new TargetSetupError("Missing handler for alt-dir-behavior: " + mAltDirBehavior); + } if (dirs.isEmpty()) { throw new TargetSetupError( "Provided buildInfo does not contain a valid tests directory and no " + diff --git a/src/com/android/tradefed/targetprep/TestFilePushSetup.java b/src/com/android/tradefed/targetprep/TestFilePushSetup.java index 2a6f67334..cbf59ed9c 100644 --- a/src/com/android/tradefed/targetprep/TestFilePushSetup.java +++ b/src/com/android/tradefed/targetprep/TestFilePushSetup.java @@ -60,6 +60,10 @@ public class TestFilePushSetup implements ITargetPreparer { + "repeated. Look for apks in last alt-dir first.") private List<File> mAltDirs = new ArrayList<>(); + @Option(name = "alt-dir-behavior", description = "The order of alternate directory to be used " + + "when searching for files to push") + private AltDirBehavior mAltDirBehavior = AltDirBehavior.FALLBACK; + /** * Adds a file to the list of items to push * @@ -85,21 +89,31 @@ public class TestFilePushSetup implements ITargetPreparer { dirs.add(dir); dirs.add(FileUtil.getFileForPath(dir, "DATA")); } + // reverse the order so ones provided via command line last can be searched first + Collections.reverse(dirs); - // Add test dirs last so they will be first when list is reversed + List<File> expandedTestDirs = new ArrayList<>(); if (buildInfo instanceof IDeviceBuildInfo) { File testsDir = ((IDeviceBuildInfo)buildInfo).getTestsDir(); if (testsDir != null && testsDir.exists()) { - dirs.add(FileUtil.getFileForPath(testsDir, "DATA")); + expandedTestDirs.add(FileUtil.getFileForPath(testsDir, "DATA")); } } + if (mAltDirBehavior == AltDirBehavior.FALLBACK) { + // alt dirs are appended after build artifact dirs + expandedTestDirs.addAll(dirs); + dirs = expandedTestDirs; + } else if (mAltDirBehavior == AltDirBehavior.OVERRIDE) { + dirs.addAll(expandedTestDirs); + } else { + throw new TargetSetupError("Missing handler for alt-dir-behavior: " + mAltDirBehavior); + } if (dirs.isEmpty()) { throw new TargetSetupError( "Provided buildInfo does not contain a valid tests directory and no " + "alternative directories were provided"); } - Collections.reverse(dirs); for (File dir : dirs) { File testAppFile = new File(dir, fileName); if (testAppFile.exists()) { @@ -151,6 +165,21 @@ public class TestFilePushSetup implements ITargetPreparer { } } + /** + * Set an alternate directory. + */ + public void setAltDir(File altDir) { + mAltDirs.add(altDir); + } + + /** + * Set the alternative directory search beahvior + * @param behavior + */ + public void setAltDirBehavior(AltDirBehavior behavior) { + mAltDirBehavior = behavior; + } + static String getDevicePathFromUserData(String path) { return ArrayUtil.join(FileListingService.FILE_SEPARATOR, "", FileListingService.DIRECTORY_DATA, path); |