Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

Always update Platform Tools and SDK Tools. #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 @@ -8,6 +8,7 @@ import static com.android.SdkConstants.androidCmdName

interface AndroidCommand {
int update(String filter);
int update(String filter, boolean all);

static final class Real implements AndroidCommand {
final Logger log = Logging.getLogger Real
Expand All @@ -20,8 +21,8 @@ interface AndroidCommand {
androidExecutable = new File(toolsDir, androidCmdName())
}

@Override int update(String filter) {
def cmd = generateCommand(filter)
@Override int update(String filter, boolean all=true) {
def cmd = generateCommand(filter, all)
def process = new ProcessBuilder(cmd)
.redirectErrorStream(true)
.start()
Expand All @@ -41,10 +42,14 @@ interface AndroidCommand {
return process.waitFor()
}

def generateCommand(String filter) {
// -a == all
def generateCommand(String filter, boolean all) {
// -u == no UI
def result = [androidExecutable.absolutePath, 'update', 'sdk', '-a', '-u'];
def result = [androidExecutable.absolutePath, 'update', 'sdk', '-u'];

// -a == all
if (all) {
result += ['-a']
}

// --proxy-host == hostname of a proxy server
// --proxy-port == port of a proxy server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class PackageResolver {
}

def resolve() {
resolveBuildTools()
resolvePlatformTools()
resolveBuildTools()
resolveCompileVersion()
resolveSupportLibraryRepository()
resolvePlayServiceRepository()
Expand All @@ -81,16 +81,11 @@ class PackageResolver {
}

def resolvePlatformTools() {
if (folderExists(platformToolsDir)) {
log.debug 'Platform tools found!'
return
}

log.lifecycle "Platform tools missing. Downloading..."
log.lifecycle "Ensuring Platform and SDK tools are up-to-date..."

def code = androidCommand.update "platform-tools"
def code = androidCommand.update("platform-tools,tools", false)
if (code != 0) {
throw new StopExecutionException("Platform tools download failed with code $code.")
throw new StopExecutionException("Platform and SDK tools download failed with code $code.")
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,33 @@ class AndroidCommandTest {
}

@Test public void simple() {
def command = command.generateCommand('foo')
assertThat(command).containsExactly(exe, 'update', 'sdk', '-a', '-u', '-t', 'foo')
def command = command.generateCommand('foo', true)
assertThat(command).containsExactly(exe, 'update', 'sdk', '-u', '-a', '-t', 'foo')
}

@Test public void notAll() throws Exception {
def command = command.generateCommand('foo', false)
assertThat(command).containsExactly(exe, 'update', 'sdk', '-u', '-t', 'foo')
}

@Test public void proxy() {
system.properties.put 'http.proxyHost', 'example.com'
system.properties.put 'http.proxyPort', '1234'
def command = command.generateCommand('foo')
def command = command.generateCommand('foo', true)
assertThat(command).
containsExactly(exe, 'update', 'sdk', '-a', '-u', '--proxy-host', 'example.com',
containsExactly(exe, 'update', 'sdk', '-u', '-a', '--proxy-host', 'example.com',
'--proxy-port', '1234', '-t', 'foo')
}

@Test public void proxyHostRequiresPort() {
system.properties.put 'http.proxyHost', 'example.com'
def command = command.generateCommand('foo')
assertThat(command).containsExactly(exe, 'update', 'sdk', '-a', '-u', '-t', 'foo')
def command = command.generateCommand('foo', true)
assertThat(command).containsExactly(exe, 'update', 'sdk', '-u', '-a', '-t', 'foo')
}

@Test public void proxyPortRequiresHost() {
system.properties.put 'http.proxyPort', '1234'
def command = command.generateCommand('foo')
assertThat(command).containsExactly(exe, 'update', 'sdk', '-a', '-u', '-t', 'foo')
def command = command.generateCommand('foo', true)
assertThat(command).containsExactly(exe, 'update', 'sdk', '-u', '-a', '-t', 'foo')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,11 @@ class PackageResolverTest {
assertThat(androidCommand).containsExactly('update build-tools-19.0.3')
}

@FixtureName("up-to-date-platform-tools")
@Test public void upToDatePlatformToolsRecognized() {
project.apply plugin: 'android'
packageResolver.resolvePlatformTools()
assertThat(androidCommand).isEmpty()
}

@FixtureName("missing-platform-tools")
@FixtureName("update-platform-tools")
@Test public void missingPlatformToolsAreDownloaded() {
project.apply plugin: 'android'
packageResolver.resolvePlatformTools()
assertThat(androidCommand).containsExactly('update platform-tools')
assertThat(androidCommand).containsExactly('update platform-tools,tools')
}

@FixtureName("up-to-date-compilation-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.jakewharton.sdkmanager.internal.AndroidCommand
final class RecordingAndroidCommand extends ArrayList<String> implements AndroidCommand {
int nextReturnCode = 0

@Override int update(String filter) {
@Override int update(String filter, boolean all=true) {
add("update $filter" as String)
return nextReturnCode
}
Expand Down