Skip to content

Commit

Permalink
Allow plugin to work with SDK which belongs to another user (#26)
Browse files Browse the repository at this point in the history
Author: @neworld
  • Loading branch information
neworld authored and quittle committed Oct 25, 2019
1 parent da4a6ff commit 80e3405
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
});
Expand Down

0 comments on commit 80e3405

Please sign in to comment.