cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject android commit: CB-7512: Read android target from project.properties if possible
Date Wed, 10 Sep 2014 15:40:13 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master c8bbdb23d -> 0e78dc35d


CB-7512: Read android target from project.properties if possible


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/0e78dc35
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/0e78dc35
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/0e78dc35

Branch: refs/heads/master
Commit: 0e78dc35d8aaec855aca9228bf5dca1b0795cac6
Parents: c8bbdb2
Author: Ian Clelland <iclelland@chromium.org>
Authored: Wed Sep 10 11:39:29 2014 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Wed Sep 10 11:39:29 2014 -0400

----------------------------------------------------------------------
 bin/templates/project/cordova.gradle | 42 +++++++------------------------
 1 file changed, 9 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0e78dc35/bin/templates/project/cordova.gradle
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova.gradle b/bin/templates/project/cordova.gradle
index 40529d3..f552a47 100644
--- a/bin/templates/project/cordova.gradle
+++ b/bin/templates/project/cordova.gradle
@@ -17,40 +17,16 @@
        under the License.
 */
 
-int[] getAvailableSdks() {
-    def availableSdks = new ByteArrayOutputStream()
-    exec {
-        commandLine 'android', 'list', 'target', '--compact'
-        standardOutput = availableSdks
-    }
-    availableSdks
-        .toString()
-        .tokenize('\n')
-        .findAll { it ==~ /android-(\d+).*/ }
-        .collect { (it =~ /android-(\d+).*/)[0][1].toInteger() }
-        .sort( { a, b -> b <=> a } )
-}
+import java.util.regex.Pattern
 
-int highestSdkAvailable(int minSdkVersion) {
-    def availableSdks
-    try {
-        availableSdks = getAvailableSdks()
-    } catch (e) {
-        println "An exception occurred while trying to find the Android SDK."
-        throw e
-    }
-    if (availableSdks.length > 0) {
-        def highestSdk = availableSdks[0]
-        if (highestSdk < minSdkVersion) {
-            throw new RuntimeException(
-                "No usable Android SDK found. Highest installed version is " +
-                highestSdk + "; minimum version required is " + minSdkVersion + ".")
-        }
-        highestSdk
+String getProjectTarget(String defaultTarget) {
+    def manifestFile = file("project.properties")
+    def pattern = Pattern.compile("target\\s*=\\s*(.*)")
+    def matcher = pattern.matcher(manifestFile.getText())
+    if (matcher.find()) {
+        matcher.group(1)
     } else {
-        throw new RuntimeException(
-            "No installed SDKs found. Please install the Android SDK version " +
-            minSdkVersion + " or higher.")
+        defaultTarget
     }
 }
 
@@ -142,6 +118,6 @@ String getAndroidSdkDir() {
     androidSdkDir
 }
 
-cordovaSdkVersion =  highestSdkAvailable(19)
+cordovaSdkVersion =  getProjectTarget("android-19")
 cordovaBuildToolsVersion = latestBuildToolsAvailable("19.0.0")
 


Mime
View raw message