From 80e340536551a955f6bb28d0386925a76180ddcb Mon Sep 17 00:00:00 2001 From: Andrius Semionovas Date: Fri, 25 Oct 2019 22:28:38 +0300 Subject: [PATCH] Allow plugin to work with SDK which belongs to another user (#26) Author: @neworld --- .../androidemulator/AndroidEmulatorPlugin.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/android-emulator-plugin/src/main/java/com/quittle/androidemulator/AndroidEmulatorPlugin.java b/android-emulator-plugin/src/main/java/com/quittle/androidemulator/AndroidEmulatorPlugin.java index 6ba2646..1280db0 100644 --- a/android-emulator-plugin/src/main/java/com/quittle/androidemulator/AndroidEmulatorPlugin.java +++ b/android-emulator-plugin/src/main/java/com/quittle/androidemulator/AndroidEmulatorPlugin.java @@ -65,18 +65,30 @@ private static void setUpAndroidTests(final Project project) { }); } + /** + * Ensures given file is executable, and if not, tries promote file to be executable + * + * @return true, if file is executable + */ + private static boolean ensureFileIsExecutable(final File file) { + // First check if file is executable. In most environments sdk binaries are already executable. + // In some environments your process is not an owner of the file and can't change permission. + // For example docker or CI + return file.canExecute() || file.setExecutable(true); + } + private static void createEnsurePermissionsTask(final Project project, final EmulatorConfiguration emulatorConfiguration) { project.getTasks().create(ENSURE_ANDROID_EMULATOR_PERMISSIONS_TASK_NAME, task -> { task.doFirst(t -> { - if (!emulatorConfiguration.getSdkManager().setExecutable(true)) { + if (!ensureFileIsExecutable(emulatorConfiguration.getSdkManager())) { throw new RuntimeException("Unable to make SDK Manager executable"); } - if (!emulatorConfiguration.getAvdManager().setExecutable(true)) { + if (!ensureFileIsExecutable(emulatorConfiguration.getAvdManager())) { throw new RuntimeException("Unable to make Android Virtual Device manager executable"); } - if (!emulatorConfiguration.getAdb().setExecutable(true)) { + if (!ensureFileIsExecutable(emulatorConfiguration.getAdb())) { throw new RuntimeException(("Unable to make ADB executable")); } });