Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify doFindLatestInstalledBuildTools #900

Merged
merged 4 commits into from
Jan 17, 2020
Merged
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
50 changes: 26 additions & 24 deletions framework/cordova.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,42 @@ String doGetProjectTarget() {
return doEnsureValueExists('project.properties', props, 'target')
}

Version[] getAvailableBuildTools() {
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
buildToolsDir.list()
.collect { new Version(it) } // Invalid inputs will be handled as 0.0.0
.findAll { it.isHigherThan('0.0.0') }
.sort { a, b -> a.isHigherThan(b) ? -1 : 1 }
}

Boolean isVersionValid(version) {
return !(new Version(version)).isEqual('0.0.0')
}

String doFindLatestInstalledBuildTools(String minBuildToolsVersionString) {
def availableBuildToolsVersions
def buildToolsDirContents
try {
availableBuildToolsVersions = getAvailableBuildTools()
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
buildToolsDirContents = buildToolsDir.list()
} catch (e) {
println "An exception occurred while trying to find the Android build tools."
throw e
}
if (availableBuildToolsVersions.length > 0) {
def highestBuildToolsVersion = availableBuildToolsVersions[0]
if (highestBuildToolsVersion.isLowerThan(minBuildToolsVersionString)) {
throw new RuntimeException(
"No usable Android build tools found. Highest installed version is " +
highestBuildToolsVersion.getOriginalString() + "; minimum version required is " +
minBuildToolsVersionString + ".")
}
highestBuildToolsVersion.getOriginalString()
} else {
throw new RuntimeException(
"No installed build tools found. Install the Android build tools version " +
minBuildToolsVersionString + " or higher.")

def highestBuildToolsVersion = buildToolsDirContents
.collect { new Version(it) }
// Invalid inputs will be handled as 0.0.0
.findAll { it.isHigherThan('0.0.0') }
.max()

if (highestBuildToolsVersion == null) {
throw new RuntimeException("""
No installed build tools found. Install the Android build tools
version ${minBuildToolsVersionString} or higher.
""".replaceAll(/\s+/, ' ').trim())
}

if (highestBuildToolsVersion.isLowerThan(minBuildToolsVersionString)) {
throw new RuntimeException("""
No usable Android build tools found. Highest installed version is
${highestBuildToolsVersion.getOriginalString()}; minimum version
required is ${minBuildToolsVersionString}.
""".replaceAll(/\s+/, ' ').trim())
}

highestBuildToolsVersion.getOriginalString()
}

String getAndroidSdkDir() {
Expand Down Expand Up @@ -194,6 +196,6 @@ buildscript {
}

dependencies {
classpath 'com.g00fy2:versioncompare:1.3.1@jar'
classpath 'com.g00fy2:versioncompare:1.3.4@jar'
}
}