cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: CB-8891 Add a gradle helper for retrieving config.xml preference values
Date Wed, 22 Apr 2015 13:51:50 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master ee14a6779 -> 9ff786d02


CB-8891 Add a gradle helper for retrieving config.xml preference values


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

Branch: refs/heads/master
Commit: 9ff786d021fcca8e3eb3fd17d65609d5dc5225cf
Parents: ee14a67
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Apr 22 09:44:28 2015 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Apr 22 09:51:16 2015 -0400

----------------------------------------------------------------------
 framework/cordova.gradle | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/9ff786d0/framework/cordova.gradle
----------------------------------------------------------------------
diff --git a/framework/cordova.gradle b/framework/cordova.gradle
index 5ce93f8..8248f98 100644
--- a/framework/cordova.gradle
+++ b/framework/cordova.gradle
@@ -152,6 +152,26 @@ def doPromptForPassword(msg) {
     }
 }
 
+def doGetConfigXml() {
+    def xml = file("res/xml/config.xml").getText()
+    // Disable namespace awareness since Cordova doesn't use them properly
+    return new XmlParser(false, false).parseText(xml)
+}
+
+def doGetConfigPreference(name, defaultValue) {
+    name = name.toLowerCase()
+    def root = doGetConfigXml()
+
+    def ret = defaultValue
+    root.preference.each { it ->
+        def attrName = it.attribute("name")
+        if (attrName && attrName.toLowerCase() == name) {
+            ret = it.attribute("value")
+        }
+    }
+    return ret
+}
+
 // Properties exported here are visible to all plugins.
 ext {
     // These helpers are shared, but are not guaranteed to be stable / unchanged.
@@ -161,5 +181,10 @@ ext {
     privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }
     privateHelpers.promptForPassword = { msg -> doPromptForPassword(msg) }
     privateHelpers.ensureValueExists = { filePath, props, key -> doEnsureValueExists(filePath,
props, key) }
+
+    // These helpers can be used by plugins / projects and will not change.
+    cdvHelpers = {}
+    cdvHelpers.getConfigXml = { doGetConfigXml() }
+    cdvHelpers.getConfigPreference = { name, defaultValue -> doGetConfigPreference(name,
defaultValue) }
 }
 


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


Mime
View raw message