Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package com.jakewharton.sdkmanager;
class SdkManagerExtension {
String emulatorVersion
String emulatorArchitecture
String sdkBaseUrl
int sdkConnTimeout
int sdkReadTimeout
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jakewharton.sdkmanager.internal

import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging

Expand All @@ -8,15 +9,18 @@ import static com.android.SdkConstants.androidCmdName

interface AndroidCommand {
int update(String filter);

String list(String filter);

static final class Real implements AndroidCommand {
final Logger log = Logging.getLogger Real
final File androidExecutable
final System system
final Project project

Real(File sdk, System system) {
Real(Project project, File sdk, System system) {
this.system = system
this.project = project
def toolsDir = new File(sdk, FD_TOOLS)
androidExecutable = new File(toolsDir, androidCmdName())
}
Expand All @@ -26,9 +30,10 @@ interface AndroidCommand {
// -t == filter
def options = ['-a', '-t', filter]
def cmd = generateCommand('update', options)
def process = new ProcessBuilder(cmd)
def processBuilder = new ProcessBuilder(cmd)
.redirectErrorStream(true)
.start()
setupSdkManEnv(processBuilder.environment())
def process = processBuilder.start()

// Press 'y' and then enter on the license prompt.
def output = new OutputStreamWriter(process.out)
Expand All @@ -49,9 +54,10 @@ interface AndroidCommand {
// -a == all
// -e == extended
def cmd = generateCommand('list', ['-a', '-e'])
def process = new ProcessBuilder(cmd)
def processBuilder = new ProcessBuilder(cmd)
.redirectErrorStream(true)
.start()
setupSdkManEnv(processBuilder.environment())
def process = processBuilder.start()

// Pipe the command output to our log.
def input = new InputStreamReader(process.in)
Expand All @@ -74,6 +80,21 @@ interface AndroidCommand {
return result
}

def setupSdkManEnv(map) {
def sdkBaseUrl = project.sdkManager.sdkBaseUrl;
if (sdkBaseUrl != null) {
map.put("SDK_TEST_BASE_URL", sdkBaseUrl as String);
}
def sdkConnTimeout = project.sdkManager.sdkConnTimeout
if (sdkConnTimeout != null) {
map.put("ANDROID_SDKMAN_CONN_TIMEOUT", sdkConnTimeout as String);
}
def sdkReadTimeout = project.sdkManager.sdkReadTimeout
if (sdkReadTimeout != null) {
map.put("ANDROID_SDKMAN_READ_TIMEOUT", sdkReadTimeout as String);
}
}

def generateCommand(String command, options) {
// -u == no UI
def result = [androidExecutable.absolutePath, command, 'sdk', '-u'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import static com.android.SdkConstants.FD_SYSTEM_IMAGES

class PackageResolver {
static void resolve(Project project, File sdk) {
new PackageResolver(project, sdk, new AndroidCommand.Real(sdk, new System.Real())).resolve()
new PackageResolver(project, sdk, new AndroidCommand.Real(project, sdk, new System.Real())).resolve()
}

static boolean folderExists(File folder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.jakewharton.sdkmanager.internal

import com.jakewharton.sdkmanager.SdkManagerExtension
import com.jakewharton.sdkmanager.util.FakeSystem
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -16,9 +19,11 @@ class AndroidCommandTest {
FakeSystem system = new FakeSystem()
AndroidCommand.Real command
String exe
Project project

@Before void setUp() {
command = new AndroidCommand.Real(sdk.root, system)
project = ProjectBuilder.builder().build();
command = new AndroidCommand.Real(project, sdk.root, system)
exe = new File(new File(sdk.root, FD_TOOLS), androidCmdName()).absolutePath
}

Expand Down Expand Up @@ -47,4 +52,18 @@ class AndroidCommandTest {
def command = command.generateCommand('update', ['-a'])
assertThat(command).containsExactly(exe, 'update', 'sdk', '-u', '-a')
}

@Test public void setupSdkManEnv() {
project.extensions.create("sdkManager", SdkManagerExtension)
project.sdkManager {
sdkBaseUrl 'http://example.com/android/repository/'
sdkConnTimeout 2000
sdkReadTimeout 2000
}
def map = new HashMap<String, String>();
command.setupSdkManEnv(map)
assertThat(map.get("SDK_TEST_BASE_URL")).isEqualTo("http://example.com/android/repository/")
assertThat(map.get("ANDROID_SDKMAN_CONN_TIMEOUT")).isEqualTo(2000 as String)
assertThat(map.get("ANDROID_SDKMAN_READ_TIMEOUT")).isEqualTo(2000 as String)
}
}