This repository was archived by the owner on Apr 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Refactor to allow overriding SDK version and url #69
Open
stormbeta
wants to merge
2
commits into
JakeWharton:master
Choose a base branch
from
stormbeta:sdk-override-pr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,47 +5,29 @@ import org.gradle.api.logging.Logger | |
| import org.gradle.api.logging.Logging | ||
| import org.rauschig.jarchivelib.ArchiverFactory | ||
|
|
||
| import static com.android.SdkConstants.PLATFORM_DARWIN | ||
| import static com.android.SdkConstants.PLATFORM_LINUX | ||
| import static com.android.SdkConstants.PLATFORM_WINDOWS | ||
| import static com.android.SdkConstants.currentPlatform | ||
| import static org.rauschig.jarchivelib.ArchiveFormat.TAR | ||
| import static org.rauschig.jarchivelib.ArchiveFormat.ZIP | ||
| import static org.rauschig.jarchivelib.CompressionType.GZIP | ||
|
|
||
| /** Manages platform-specific SDK downloads. */ | ||
| enum SdkDownload { | ||
| WINDOWS('windows','zip'), | ||
| LINUX('linux', 'tgz'), | ||
| DARWIN('macosx', 'zip'); | ||
|
|
||
| static SdkDownload get() { | ||
| switch (currentPlatform()) { | ||
| case PLATFORM_WINDOWS: | ||
| return WINDOWS | ||
| case PLATFORM_LINUX: | ||
| return LINUX | ||
| case PLATFORM_DARWIN: | ||
| return DARWIN | ||
| default: | ||
| throw new IllegalStateException("Unknown platform.") | ||
| } | ||
| } | ||
|
|
||
| final static SDK_VERSION_MAJOR = 24; | ||
|
|
||
| class SdkDownload implements Downloader { | ||
| final String baseUrl | ||
| final String sdkMajorVersion | ||
| final Logger log = Logging.getLogger SdkDownload | ||
| final String suffix | ||
| final String ext | ||
| final SdkPlatform platform | ||
|
|
||
| private String getExt() { return platform.ext } | ||
| private String getSuffix() { return platform.suffix } | ||
|
|
||
| SdkDownload(String suffix, String ext) { | ||
| this.suffix = suffix | ||
| this.ext = ext | ||
| SdkDownload(platform = SdkPlatform.get(), baseUrl = SdkResolver.DEFAULT_SDK_URL, sdkVersion = SdkResolver.DEFAULT_SDK_VERSION) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line too long. Should wrap at 100 |
||
| this.platform = platform | ||
| this.baseUrl = baseUrl | ||
| this.sdkMajorVersion = sdkVersion | ||
| } | ||
|
|
||
| /** Download the SDK to {@code temp} and extract to {@code dest}. */ | ||
| void download(File dest) { | ||
| def url = "http://dl.google.com/android/android-sdk_r$SDK_VERSION_MAJOR-$suffix.$ext" | ||
| def url = "${baseUrl}/android-sdk_r${sdkMajorVersion}-${suffix}.${ext}" | ||
| log.debug "Downloading SDK from $url." | ||
|
|
||
| File temp = new File(dest.getParentFile(), 'android-sdk.temp') | ||
|
|
||
35 changes: 35 additions & 0 deletions
35
src/main/groovy/com/jakewharton/sdkmanager/internal/SdkPlatform.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.jakewharton.sdkmanager.internal | ||
|
|
||
| import static com.android.SdkConstants.PLATFORM_DARWIN | ||
| import static com.android.SdkConstants.PLATFORM_LINUX | ||
| import static com.android.SdkConstants.PLATFORM_UNKNOWN | ||
| import static com.android.SdkConstants.PLATFORM_WINDOWS | ||
| import static com.android.SdkConstants.currentPlatform | ||
|
|
||
| enum SdkPlatform { | ||
| WINDOWS('windows','zip'), | ||
| LINUX('linux', 'tgz'), | ||
| DARWIN('macosx', 'zip'); | ||
|
|
||
| static SdkPlatform get() { | ||
| switch (currentPlatform()) { | ||
| case PLATFORM_WINDOWS: | ||
| return WINDOWS | ||
| case PLATFORM_LINUX: | ||
| return LINUX | ||
| case PLATFORM_DARWIN: | ||
| return DARWIN | ||
| default: | ||
| throw new IllegalStateException("Unknown platform.") | ||
| } | ||
| } | ||
|
|
||
| final String suffix | ||
| final String ext | ||
|
|
||
| SdkPlatform(String suffix, String ext) { | ||
| this.suffix = suffix | ||
| this.ext = ext | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,15 @@ import static com.android.SdkConstants.currentPlatform | |
| class SdkResolver { | ||
| static File resolve(Project project) { | ||
| boolean isWindows = currentPlatform() == PLATFORM_WINDOWS | ||
| return new SdkResolver(project, new System.Real(), new Downloader.Real(), isWindows).resolve() | ||
| def baseUrl = project.hasProperty('sdkBaseUrl') ? project.property('sdkBaseUrl') : DEFAULT_SDK_URL | ||
| def sdkVersion = project.hasProperty('sdkVersion') ? project.property('sdkVersion') : DEFAULT_SDK_VERSION | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have two mechanisms for the same thing? |
||
| Downloader realDownloader = new SdkDownload(SdkPlatform.get(), baseUrl, sdkVersion) | ||
| return new SdkResolver(project, new System.Real(), realDownloader, isWindows).resolve() | ||
| } | ||
|
|
||
| static final String DEFAULT_SDK_URL = 'https://dl.google.com/android' | ||
| static final String DEFAULT_SDK_VERSION = '24.0.2' | ||
|
|
||
| final Logger log = Logging.getLogger SdkResolver | ||
| final Project project | ||
| final System system | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert