mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
refactor: simplify doFindLatestInstalledBuildTools (#900)
* chore: update com.g00fy2:versioncompare to 1.3.4 * refactor: flatten error handling in doFindLatestInstalledBuildTools * refactor: inline & simplify getAvailableBuildTools * refactor: use string interpolation for error messages
This commit is contained in:
parent
60e022fedd
commit
66ad2c948e
@ -40,40 +40,42 @@ String doGetProjectTarget() {
|
|||||||
return doEnsureValueExists('project.properties', props, 'target')
|
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) {
|
Boolean isVersionValid(version) {
|
||||||
return !(new Version(version)).isEqual('0.0.0')
|
return !(new Version(version)).isEqual('0.0.0')
|
||||||
}
|
}
|
||||||
|
|
||||||
String doFindLatestInstalledBuildTools(String minBuildToolsVersionString) {
|
String doFindLatestInstalledBuildTools(String minBuildToolsVersionString) {
|
||||||
def availableBuildToolsVersions
|
def buildToolsDirContents
|
||||||
try {
|
try {
|
||||||
availableBuildToolsVersions = getAvailableBuildTools()
|
def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
|
||||||
|
buildToolsDirContents = buildToolsDir.list()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
println "An exception occurred while trying to find the Android build tools."
|
println "An exception occurred while trying to find the Android build tools."
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
if (availableBuildToolsVersions.length > 0) {
|
|
||||||
def highestBuildToolsVersion = availableBuildToolsVersions[0]
|
def highestBuildToolsVersion = buildToolsDirContents
|
||||||
if (highestBuildToolsVersion.isLowerThan(minBuildToolsVersionString)) {
|
.collect { new Version(it) }
|
||||||
throw new RuntimeException(
|
// Invalid inputs will be handled as 0.0.0
|
||||||
"No usable Android build tools found. Highest installed version is " +
|
.findAll { it.isHigherThan('0.0.0') }
|
||||||
highestBuildToolsVersion.getOriginalString() + "; minimum version required is " +
|
.max()
|
||||||
minBuildToolsVersionString + ".")
|
|
||||||
}
|
if (highestBuildToolsVersion == null) {
|
||||||
highestBuildToolsVersion.getOriginalString()
|
throw new RuntimeException("""
|
||||||
} else {
|
No installed build tools found. Install the Android build tools
|
||||||
throw new RuntimeException(
|
version ${minBuildToolsVersionString} or higher.
|
||||||
"No installed build tools found. Install the Android build tools version " +
|
""".replaceAll(/\s+/, ' ').trim())
|
||||||
minBuildToolsVersionString + " or higher.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
String getAndroidSdkDir() {
|
||||||
@ -194,6 +196,6 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.g00fy2:versioncompare:1.3.1@jar'
|
classpath 'com.g00fy2:versioncompare:1.3.4@jar'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user