Repository: cordova-lib
Updated Branches:
refs/heads/master d58df34cb -> 9ce2e6e63
Add a type named "gradleReference" in framework
It's too complex to dependence AAR in plugin, it need build the plugin
to a android project which include AndroidManifest.xml. This patch
reference the *.gradle in plugin to build.gradle in root project. Below is
a demo.
plugin.xml:
<framework src="libs/xwalk_core_library/xwalk.gradle" custom="true"
type="gradleReference"/>
xwalk.gradle:
repositories {
maven {
url
'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
}
}
dependencies {
compile 'org.xwalk:xwalk_core_library_beta:9.38.208.4'
}
The build.gradle will add blow section:
// PLUGIN GRADLE EXTENSIONS START
apply from: 'libs/xwalk_core_library/xwalk.gradle'
// PLUGIN GRADLE EXTENSIONS END
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/02a96d75
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/02a96d75
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/02a96d75
Branch: refs/heads/master
Commit: 02a96d757acc604610eb403cf11f79513ead4ac5
Parents: 30d68ac
Author: fujunwei <[email protected]>
Authored: Fri Oct 24 16:11:59 2014 +0800
Committer: fujunwei <[email protected]>
Committed: Wed Nov 12 13:13:04 2014 +0800
----------------------------------------------------------------------
cordova-lib/src/plugman/platforms/android.js | 15 +++-
cordova-lib/src/plugman/util/android-project.js | 74 ++++++++++++++++++++
2 files changed, 87 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/02a96d75/cordova-lib/src/plugman/platforms/android.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/platforms/android.js
b/cordova-lib/src/plugman/platforms/android.js
index 2c2c6d9..08804bd 100644
--- a/cordova-lib/src/plugman/platforms/android.js
+++ b/cordova-lib/src/plugman/platforms/android.js
@@ -107,7 +107,13 @@ module.exports = {
}
var projectConfig = module.exports.parseProjectFile(project_dir);
- projectConfig.addSubProject(parentDir, subDir);
+ var type = source_el.attrib.type;
+ if (type == 'gradleReference') {
+ //add reference to build.gradle
+ projectConfig.addGradleReference(parentDir, subDir);
+ } else {
+ projectConfig.addSubProject(parentDir, subDir);
+ }
},
uninstall:function(source_el, project_dir, plugin_id) {
var src = source_el.attrib.src;
@@ -130,7 +136,12 @@ module.exports = {
}
var projectConfig = module.exports.parseProjectFile(project_dir);
- projectConfig.removeSubProject(parentDir, subDir);
+ var type = source_el.attrib.type;
+ if (type == 'gradleReference') {
+ projectConfig.removeGradleReference(parentDir, subDir);
+ } else {
+ projectConfig.removeSubProject(parentDir, subDir);
+ }
}
},
parseProjectFile: function(project_dir){
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/02a96d75/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 bedec6b..8d2b932 100644
--- a/cordova-lib/src/plugman/util/android-project.js
+++ b/cordova-lib/src/plugman/util/android-project.js
@@ -56,6 +56,66 @@ function removeLibraryReference(projectProperties,
libraryPath) {
}
}
+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 = {};
@@ -86,6 +146,20 @@ AndroidProject.prototype = {
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);
+ }
+ },
+ 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);
+ }
+ },
write: function(platformVersion) {
if (!this._dirty) return;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]