cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject cordova-lib git commit: CB-8373 android: Add gradle references to project.properties rather than build.gradle
Date Wed, 28 Jan 2015 21:26:48 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 89795f21f -> c6255be77


CB-8373 android: Add gradle references to project.properties rather than build.gradle


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

Branch: refs/heads/master
Commit: c6255be7753a19bf8ab34be9a692b520ee8d9eb2
Parents: 89795f2
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Jan 28 16:20:47 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Jan 28 16:20:47 2015 -0500

----------------------------------------------------------------------
 cordova-lib/src/plugman/util/android-project.js | 103 ++++---------------
 1 file changed, 21 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c6255be7/cordova-lib/src/plugman/util/android-project.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/android-project.js b/cordova-lib/src/plugman/util/android-project.js
index 68604f4..a8c056a 100644
--- a/cordova-lib/src/plugman/util/android-project.js
+++ b/cordova-lib/src/plugman/util/android-project.js
@@ -29,90 +29,30 @@ var fs = require('fs'),
 var semver = require('semver');
 
 
-function addLibraryReference(projectProperties, libraryPath) {
+function addToPropertyList(projectProperties, key, value) {
     var i = 1;
-    while (projectProperties.get('android.library.reference.' + i))
+    while (projectProperties.get(key + '.' + i))
         i++;
 
-    projectProperties.set('android.library.reference.' + i, libraryPath);
+    projectProperties.set(key + '.' + i, value);
 }
 
-function removeLibraryReference(projectProperties, libraryPath) {
+function removeFromPropertyList(projectProperties, key, value) {
     var i = 1;
-    var currentLib;
-    while (currentLib = projectProperties.get('android.library.reference.' + i)) {
-        if (currentLib === libraryPath) {
-            while (currentLib = projectProperties.get('android.library.reference.' + (i +
1))) {
-                projectProperties.set('android.library.reference.' + i, currentLib);
+    var currentValue;
+    while (currentValue = projectProperties.get(key + '.' + i)) {
+        if (currentValue === value) {
+            while (currentValue = projectProperties.get(key + '.' + (i + 1))) {
+                projectProperties.set(key + '.' + i, currentValue);
                 i++;
             }
-            projectProperties.set('android.library.reference.' + i);
+            projectProperties.set(key + '.' + i);
             break;
         }
         i++;
     }
 }
 
-function updateBuildGradleFile(librariesFile, updateFn) {
-    try {
-        var libraries = fs.readFileSync(librariesFile, {encoding: 'utf8'}) + '';
-        var lines = libraries.split('\n');
-        var openLine, closeLine;
-        for (var i = 0; i < lines.length; ++i) {
-            var line = lines[i];
-            if (line.indexOf('// PLUGIN GRADLE EXTENSIONS START') > -1) {
-                openLine = i;
-            }
-            if ((typeof openLine != 'undefined') && line.indexOf('// PLUGIN GRADLE
EXTENSIONS END') > -1) {
-                closeLine = i;
-                break;
-            }
-        }
-        if ((typeof closeLine == 'undefined') && (typeof openLine == 'undefined'))
{
-            openLine = closeLine = lines.length -1;
-            lines.splice(openLine, 0, '// PLUGIN GRADLE EXTENSIONS START');
-            closeLine += 1;
-            lines.splice(closeLine, 0, '// PLUGIN GRADLE EXTENSIONS END');
-        }
-        updateFn(lines, openLine, closeLine);
-        fs.writeFileSync(librariesFile, lines.join('\n'), {encoding: 'utf8'});
-    } catch (e) {
-        if (e.code != 'ENOENT') {
-            throw e;
-        }
-    }
-}
-
-function addReferenceToGradle(librariesFile, gradlePath) {
-    updateBuildGradleFile(librariesFile, function(lines, openLine, closeLine) {
-        var exists = false;
-        for (var i = openLine; i < closeLine; ++i) {
-            if (lines[i].indexOf('apply from: \'' + gradlePath + '\'') > -1) {
-                exists = true;
-            }
-        }
-        if (!exists) {
-            lines.splice(closeLine, 0, 'apply from: \'' + gradlePath + '\'');
-        }
-    });
-}
-
-function removeReferenceFromGradle(librariesFile, gradlePath) {
-    updateBuildGradleFile(librariesFile, function(lines, openLine, closeLine) {
-        var foundLine;
-        var exists = false;
-        for (var i = 0; i < lines.length; ++i) {
-            if (lines[i].indexOf('apply from: \'' + gradlePath + '\'') > -1) {
-                exists = true;
-                foundLine = i;
-            }
-        }
-        if (exists) {
-            lines.splice(foundLine, 1);
-        }
-    });
-}
-
 function AndroidProject() {
     this._propertiesEditors = {};
     this._subProjectDirs = {};
@@ -126,35 +66,34 @@ AndroidProject.prototype = {
         var parentProjectFile = path.resolve(parentDir, 'project.properties');
         var subProjectFile = path.resolve(subDir, 'project.properties');
         var parentProperties = this._getPropertiesFile(parentProjectFile);
+        // TODO: Setting the target needs to happen only for pre-3.7.0 projects
         if (fs.existsSync(subProjectFile)) {
             var subProperties = this._getPropertiesFile(subProjectFile);
             subProperties.set('target', parentProperties.get('target'));
             this._subProjectDirs[subDir] = true;
         }
-        addLibraryReference(parentProperties, module.exports.getRelativeLibraryPath(parentDir,
subDir));
+        addToPropertyList(parentProperties, 'android.library.reference', module.exports.getRelativeLibraryPath(parentDir,
subDir));
 
         this._dirty = true;
     },
     removeSubProject: function(parentDir, subDir) {
         var parentProjectFile = path.resolve(parentDir, 'project.properties');
         var parentProperties = this._getPropertiesFile(parentProjectFile);
-        removeLibraryReference(parentProperties, module.exports.getRelativeLibraryPath(parentDir,
subDir));
+        removeFromPropertyList(parentProperties, 'android.library.reference', module.exports.getRelativeLibraryPath(parentDir,
subDir));
         delete this._subProjectDirs[subDir];
         this._dirty = true;
     },
     addGradleReference: function(parentDir, subDir) {
-        var gradleExtrasFile = path.resolve(parentDir, 'build.gradle');
-        var gradleReference = module.exports.getRelativeLibraryPath(parentDir, subDir);
-        if (fs.existsSync(gradleExtrasFile)) {
-            addReferenceToGradle(gradleExtrasFile, gradleReference);
-        }
+        var parentProjectFile = path.resolve(parentDir, 'project.properties');
+        var parentProperties = this._getPropertiesFile(parentProjectFile);
+        addToPropertyList(parentProperties, 'cordova.gradle.include', module.exports.getRelativeLibraryPath(parentDir,
subDir));
+        this._dirty = true;
     },
     removeGradleReference: function(parentDir, subDir) {
-        var gradleExtrasFile = path.resolve(parentDir, 'build.gradle');
-        var gradleReference = module.exports.getRelativeLibraryPath(parentDir, subDir);
-        if (fs.existsSync(gradleExtrasFile)) {
-            removeReferenceFromGradle(gradleExtrasFile, gradleReference);
-        }
+        var parentProjectFile = path.resolve(parentDir, 'project.properties');
+        var parentProperties = this._getPropertiesFile(parentProjectFile);
+        removeFromPropertyList(parentProperties, 'cordova.gradle.include', module.exports.getRelativeLibraryPath(parentDir,
subDir));
+        this._dirty = true;
     },
     write: function(platformVersion) {
         if (!this._dirty) return;


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


Mime
View raw message