You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/10/02 20:17:45 UTC

[11/29] git commit: CB-7512: Read android target from project.properties if possible

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


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/97218ce0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/97218ce0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/97218ce0

Branch: refs/heads/master
Commit: 97218ce037a2092d104f3abc87df234192356956
Parents: fe85b0b
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Sep 10 11:39:29 2014 -0400
Committer: Prabhjot Singh <pr...@amazon.com>
Committed: Wed Sep 17 14:31:44 2014 +0530

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


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/97218ce0/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")
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org