forked from github/cordova-android
Finishing the linting
This commit is contained in:
parent
e456175a81
commit
a7304b9a19
@ -43,13 +43,14 @@ function getFrameworkDir (projectPath, shared) {
|
|||||||
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyJsAndLibrary(projectPath, shared, projectName, isLegacy) {
|
function copyJsAndLibrary (projectPath, shared, projectName, isLegacy) {
|
||||||
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
|
var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
|
||||||
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
|
var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js');
|
||||||
var app_path = path.join(projectPath, 'app', 'src', 'main');
|
var app_path = path.join(projectPath, 'app', 'src', 'main');
|
||||||
|
|
||||||
if(isLegacy)
|
if (isLegacy) {
|
||||||
app_path = projectPath;
|
app_path = projectPath;
|
||||||
|
}
|
||||||
|
|
||||||
shell.cp('-f', srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
shell.cp('-f', srcCordovaJsPath, path.join(app_path, 'assets', 'www', 'cordova.js'));
|
||||||
|
|
||||||
@ -131,22 +132,22 @@ function writeProjectProperties (projectPath, target_api) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This makes no sense, what if you're building with a different build system?
|
// This makes no sense, what if you're building with a different build system?
|
||||||
function prepBuildFiles(projectPath, builder) {
|
function prepBuildFiles (projectPath, builder) {
|
||||||
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders'));
|
var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders'));
|
||||||
buildModule.getBuilder(builder).prepBuildFiles();
|
buildModule.getBuilder(builder).prepBuildFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyBuildRules(projectPath, isLegacy) {
|
function copyBuildRules (projectPath, isLegacy) {
|
||||||
var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
|
var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
|
||||||
|
|
||||||
if(isLegacy) {
|
if (isLegacy) {
|
||||||
//The project's build.gradle is identical to the earlier build.gradle, so it should still work
|
// The project's build.gradle is identical to the earlier build.gradle, so it should still work
|
||||||
shell.cp('-f', path.join(srcDir, 'legacy', 'build.gradle'), projectPath);
|
shell.cp('-f', path.join(srcDir, 'legacy', 'build.gradle'), projectPath);
|
||||||
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
||||||
} else {
|
} else {
|
||||||
shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath);
|
shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath);
|
||||||
shell.cp('-f', path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app'));
|
shell.cp('-f', path.join(srcDir, 'app', 'build.gradle'), path.join(projectPath, 'app'));
|
||||||
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
shell.cp('-f', path.join(srcDir, 'wrapper.gradle'), projectPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,66 +262,66 @@ exports.create = function (project_path, config, options, events) {
|
|||||||
validateProjectName(project_name);
|
validateProjectName(project_name);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// Log the given values for the project
|
// Log the given values for the project
|
||||||
events.emit('log', 'Creating Cordova project for the Android platform:');
|
events.emit('log', 'Creating Cordova project for the Android platform:');
|
||||||
events.emit('log', '\tPath: ' + project_path);
|
events.emit('log', '\tPath: ' + project_path);
|
||||||
events.emit('log', '\tPackage: ' + package_name);
|
events.emit('log', '\tPackage: ' + package_name);
|
||||||
events.emit('log', '\tName: ' + project_name);
|
events.emit('log', '\tName: ' + project_name);
|
||||||
events.emit('log', '\tActivity: ' + safe_activity_name);
|
events.emit('log', '\tActivity: ' + safe_activity_name);
|
||||||
events.emit('log', '\tAndroid target: ' + target_api);
|
events.emit('log', '\tAndroid target: ' + target_api);
|
||||||
|
|
||||||
events.emit('verbose', 'Copying android template project to ' + project_path);
|
events.emit('verbose', 'Copying android template project to ' + project_path);
|
||||||
|
|
||||||
setShellFatal(true, function() {
|
setShellFatal(true, function () {
|
||||||
var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
|
var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project');
|
||||||
var app_path = path.join(project_path, 'app', 'src', 'main');
|
var app_path = path.join(project_path, 'app', 'src', 'main');
|
||||||
|
|
||||||
// copy project template
|
// copy project template
|
||||||
shell.mkdir('-p', app_path);
|
shell.mkdir('-p', app_path);
|
||||||
shell.cp('-r', path.join(project_template_dir, 'assets'), app_path);
|
shell.cp('-r', path.join(project_template_dir, 'assets'), app_path);
|
||||||
shell.cp('-r', path.join(project_template_dir, 'res'), app_path);
|
shell.cp('-r', path.join(project_template_dir, 'res'), app_path);
|
||||||
shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));
|
||||||
|
|
||||||
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
// Manually create directories that would be empty within the template (since git doesn't track directories).
|
||||||
shell.mkdir(path.join(app_path, 'libs'));
|
shell.mkdir(path.join(app_path, 'libs'));
|
||||||
|
|
||||||
// copy cordova.js, cordova.jar
|
// copy cordova.js, cordova.jar
|
||||||
copyJsAndLibrary(project_path, options.link, safe_activity_name);
|
copyJsAndLibrary(project_path, options.link, safe_activity_name);
|
||||||
|
|
||||||
//Set up ther Android Studio paths
|
// Set up ther Android Studio paths
|
||||||
var java_path = path.join(app_path, 'java');
|
var java_path = path.join(app_path, 'java');
|
||||||
var assets_path = path.join(app_path, 'assets');
|
var assets_path = path.join(app_path, 'assets');
|
||||||
var resource_path = path.join(app_path, 'res');
|
var resource_path = path.join(app_path, 'res');
|
||||||
shell.mkdir('-p', java_path);
|
shell.mkdir('-p', java_path);
|
||||||
shell.mkdir('-p', assets_path);
|
shell.mkdir('-p', assets_path);
|
||||||
shell.mkdir('-p', resource_path);
|
shell.mkdir('-p', resource_path);
|
||||||
|
|
||||||
// interpolate the activity name and package
|
// interpolate the activity name and package
|
||||||
var packagePath = package_name.replace(/\./g, path.sep);
|
var packagePath = package_name.replace(/\./g, path.sep);
|
||||||
var activity_dir = path.join(java_path, packagePath);
|
var activity_dir = path.join(java_path, packagePath);
|
||||||
var activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
var activity_path = path.join(activity_dir, safe_activity_name + '.java');
|
||||||
|
|
||||||
shell.mkdir('-p', activity_dir);
|
shell.mkdir('-p', activity_dir);
|
||||||
shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
|
shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
|
||||||
shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
|
shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
|
||||||
shell.sed('-i', /__NAME__/, project_name, path.join(app_path, 'res', 'values', 'strings.xml'));
|
shell.sed('-i', /__NAME__/, project_name, path.join(app_path, 'res', 'values', 'strings.xml'));
|
||||||
shell.sed('-i', /__ID__/, package_name, activity_path);
|
shell.sed('-i', /__ID__/, package_name, activity_path);
|
||||||
|
|
||||||
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
||||||
manifest.setPackageId(package_name)
|
manifest.setPackageId(package_name)
|
||||||
.setTargetSdkVersion(target_api.split('-')[1])
|
.setTargetSdkVersion(target_api.split('-')[1])
|
||||||
.getActivity().setName(safe_activity_name);
|
.getActivity().setName(safe_activity_name);
|
||||||
|
|
||||||
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
||||||
manifest.write(manifest_path);
|
manifest.write(manifest_path);
|
||||||
|
|
||||||
copyScripts(project_path);
|
copyScripts(project_path);
|
||||||
copyBuildRules(project_path);
|
copyBuildRules(project_path);
|
||||||
});
|
});
|
||||||
// Link it to local android install.
|
// Link it to local android install.
|
||||||
writeProjectProperties(project_path, target_api);
|
writeProjectProperties(project_path, target_api);
|
||||||
prepBuildFiles(project_path, 'studio');
|
prepBuildFiles(project_path, 'studio');
|
||||||
events.emit('log', generateDoneMessage('create', options.link));
|
events.emit('log', generateDoneMessage('create', options.link));
|
||||||
}).thenResolve(project_path);
|
}).thenResolve(project_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
function generateDoneMessage (type, link) {
|
function generateDoneMessage (type, link) {
|
||||||
@ -339,18 +340,18 @@ exports.update = function (projectPath, options, events) {
|
|||||||
return Q()
|
return Q()
|
||||||
.then(function () {
|
.then(function () {
|
||||||
|
|
||||||
var isAndroidStudio = AndroidStudio.isAndroidStudioProject(projectPath);
|
var isAndroidStudio = AndroidStudio.isAndroidStudioProject(projectPath);
|
||||||
var isLegacy = !isAndroidStudio;
|
var isLegacy = !isAndroidStudio;
|
||||||
var manifest = null;
|
var manifest = null;
|
||||||
var builder = 'gradle';
|
var builder = 'gradle';
|
||||||
|
|
||||||
if(isAndroidStudio) {
|
if (isAndroidStudio) {
|
||||||
manifest = new AndroidManifest(path.join(projectPath, 'app', 'main', 'AndroidManifest.xml'));
|
manifest = new AndroidManifest(path.join(projectPath, 'app', 'main', 'AndroidManifest.xml'));
|
||||||
builder = 'studio';
|
builder = 'studio';
|
||||||
} else {
|
} else {
|
||||||
manifest = new AndroidManifest(path.join(projectPath, 'AndroidManifest.xml'));
|
manifest = new AndroidManifest(path.join(projectPath, 'AndroidManifest.xml'));
|
||||||
builder = 'gradle';
|
builder = 'gradle';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(manifest.getMinSdkVersion()) < MIN_SDK_VERSION) {
|
if (Number(manifest.getMinSdkVersion()) < MIN_SDK_VERSION) {
|
||||||
events.emit('verbose', 'Updating minSdkVersion to ' + MIN_SDK_VERSION + ' in AndroidManifest.xml');
|
events.emit('verbose', 'Updating minSdkVersion to ' + MIN_SDK_VERSION + ' in AndroidManifest.xml');
|
||||||
@ -362,13 +363,13 @@ exports.update = function (projectPath, options, events) {
|
|||||||
var projectName = manifest.getActivity().getName();
|
var projectName = manifest.getActivity().getName();
|
||||||
var target_api = check_reqs.get_target();
|
var target_api = check_reqs.get_target();
|
||||||
|
|
||||||
copyJsAndLibrary(projectPath, options.link, projectName, isLegacy);
|
copyJsAndLibrary(projectPath, options.link, projectName, isLegacy);
|
||||||
copyScripts(projectPath);
|
copyScripts(projectPath);
|
||||||
copyBuildRules(projectPath, isLegacy);
|
copyBuildRules(projectPath, isLegacy);
|
||||||
writeProjectProperties(projectPath, target_api);
|
writeProjectProperties(projectPath, target_api);
|
||||||
prepBuildFiles(projectPath, builder);
|
prepBuildFiles(projectPath, builder);
|
||||||
events.emit('log', generateDoneMessage('update', options.link));
|
events.emit('log', generateDoneMessage('update', options.link));
|
||||||
}).thenResolve(projectPath);
|
}).thenResolve(projectPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
// For testing
|
// For testing
|
||||||
|
15
bin/templates/cordova/Api.js
vendored
15
bin/templates/cordova/Api.js
vendored
@ -79,14 +79,14 @@ function Api (platform, platformRootDir, events) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// XXX Override some locations for Android Studio projects
|
// XXX Override some locations for Android Studio projects
|
||||||
if(AndroidStudio.isAndroidStudioProject(self.root) === true) {
|
if (AndroidStudio.isAndroidStudioProject(self.root) === true) {
|
||||||
selfEvents.emit('log', 'Android Studio project detected');
|
selfEvents.emit('log', 'Android Studio project detected');
|
||||||
this.builder='studio';
|
this.builder = 'studio';
|
||||||
this.android_studio = true;
|
this.android_studio = true;
|
||||||
this.locations.configXml = path.join(self.root, 'app/src/main/res/xml/config.xml');
|
this.locations.configXml = path.join(self.root, 'app/src/main/res/xml/config.xml');
|
||||||
this.locations.strings = path.join(self.root, 'app/src/main/res/values/strings.xml');
|
this.locations.strings = path.join(self.root, 'app/src/main/res/values/strings.xml');
|
||||||
this.locations.manifest = path.join(self.root, 'app/src/main/AndroidManifest.xml');
|
this.locations.manifest = path.join(self.root, 'app/src/main/AndroidManifest.xml');
|
||||||
//We could have Java Source, we could have other languages
|
// We could have Java Source, we could have other languages
|
||||||
this.locations.javaSrc = path.join(self.root, 'app/src/main/java/');
|
this.locations.javaSrc = path.join(self.root, 'app/src/main/java/');
|
||||||
this.locations.www = path.join(self.root, 'app/src/main/assets/www');
|
this.locations.www = path.join(self.root, 'app/src/main/assets/www');
|
||||||
this.locations.res = path.join(self.root, 'app/src/main/res');
|
this.locations.res = path.join(self.root, 'app/src/main/res');
|
||||||
@ -248,7 +248,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
|
|||||||
}).then(function () {
|
}).then(function () {
|
||||||
if (plugin.getFrameworks(this.platform).length === 0) return;
|
if (plugin.getFrameworks(this.platform).length === 0) return;
|
||||||
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
||||||
//This should pick the correct builder, not just get gradle
|
// This should pick the correct builder, not just get gradle
|
||||||
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
// CB-11022 Return truthy value to prevent running prepare after
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
@ -335,9 +335,10 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
|
|||||||
*/
|
*/
|
||||||
Api.prototype.build = function (buildOptions) {
|
Api.prototype.build = function (buildOptions) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if(this.android_studio)
|
if (this.android_studio) {
|
||||||
buildOptions.studio = true;
|
buildOptions.studio = true;
|
||||||
return require('./lib/check_reqs').run() .then(function () {
|
}
|
||||||
|
return require('./lib/check_reqs').run().then(function () {
|
||||||
return require('./lib/build').run.call(self, buildOptions);
|
return require('./lib/build').run.call(self, buildOptions);
|
||||||
}).then(function (buildResults) {
|
}).then(function (buildResults) {
|
||||||
// Cast build result to array of build artifacts
|
// Cast build result to array of build artifacts
|
||||||
|
2
bin/templates/cordova/lib/AndroidStudio.js
vendored
2
bin/templates/cordova/lib/AndroidStudio.js
vendored
@ -10,7 +10,7 @@ var path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var CordovaError = require('cordova-common').CordovaError;
|
var CordovaError = require('cordova-common').CordovaError;
|
||||||
|
|
||||||
module.exports.isAndroidStudioProject = function isAndroidStudioProject(root) {
|
module.exports.isAndroidStudioProject = function isAndroidStudioProject (root) {
|
||||||
var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res'];
|
var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res'];
|
||||||
var androidStudioFiles = ['app', 'app/src/main'];
|
var androidStudioFiles = ['app', 'app/src/main'];
|
||||||
|
|
||||||
|
5
bin/templates/cordova/lib/build.js
vendored
5
bin/templates/cordova/lib/build.js
vendored
@ -55,10 +55,11 @@ function parseOpts (options, resolvedTarget, projectRoot) {
|
|||||||
extraArgs: []
|
extraArgs: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.argv.gradle || options.argv.studio)
|
if (options.argv.gradle || options.argv.studio) {
|
||||||
ret.buildMethod = options.argv.studio ? 'studio' : 'gradle';
|
ret.buildMethod = options.argv.studio ? 'studio' : 'gradle';
|
||||||
|
}
|
||||||
|
|
||||||
//This comes from cordova/run
|
// This comes from cordova/run
|
||||||
if (options.studio) ret.buildMethod = 'studio';
|
if (options.studio) ret.buildMethod = 'studio';
|
||||||
if (options.gradle) ret.buildMethod = 'gradle';
|
if (options.gradle) ret.buildMethod = 'gradle';
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ function GenericBuilder (projectDir) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericBuilder.prototype.prepEnv = function() {
|
GenericBuilder.prototype.prepEnv = function () {
|
||||||
return Q();
|
return Q();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,8 +48,7 @@ GenericBuilder.prototype.clean = function () {
|
|||||||
|
|
||||||
GenericBuilder.prototype.findOutputApks = function (build_type, arch) {
|
GenericBuilder.prototype.findOutputApks = function (build_type, arch) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Object.keys(this.binDirs) .reduce(function (result, builderName) {
|
return Object.keys(this.binDirs).reduce(function (result, builderName) {
|
||||||
console.log('builderName:'+ builderName);
|
|
||||||
var binDir = self.binDirs[builderName];
|
var binDir = self.binDirs[builderName];
|
||||||
return result.concat(findOutputApksHelper(binDir, build_type, builderName === 'ant' ? null : arch));
|
return result.concat(findOutputApksHelper(binDir, build_type, builderName === 'ant' ? null : arch));
|
||||||
}, []).sort(apkSorter);
|
}, []).sort(apkSorter);
|
||||||
|
@ -84,7 +84,7 @@ GradleBuilder.prototype.runGradleWrapper = function (gradle_cmd) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
GradleBuilder.prototype.readProjectProperties = function () {
|
GradleBuilder.prototype.readProjectProperties = function () {
|
||||||
function findAllUniq(data, r) {
|
function findAllUniq (data, r) {
|
||||||
var s = {};
|
var s = {};
|
||||||
var m;
|
var m;
|
||||||
while ((m = r.exec(data))) {
|
while ((m = r.exec(data))) {
|
||||||
@ -109,12 +109,11 @@ GradleBuilder.prototype.extractRealProjectNameFromManifest = function () {
|
|||||||
throw new CordovaError('Could not find package name in ' + manifestPath);
|
throw new CordovaError('Could not find package name in ' + manifestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
var packageName=m[1];
|
var packageName = m[1];
|
||||||
var lastDotIndex = packageName.lastIndexOf('.');
|
var lastDotIndex = packageName.lastIndexOf('.');
|
||||||
return packageName.substring(lastDotIndex + 1);
|
return packageName.substring(lastDotIndex + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Makes the project buildable, minus the gradle wrapper.
|
// Makes the project buildable, minus the gradle wrapper.
|
||||||
GradleBuilder.prototype.prepBuildFiles = function () {
|
GradleBuilder.prototype.prepBuildFiles = function () {
|
||||||
// Update the version of build.gradle in each dependent library.
|
// Update the version of build.gradle in each dependent library.
|
||||||
@ -124,7 +123,7 @@ GradleBuilder.prototype.prepBuildFiles = function () {
|
|||||||
|
|
||||||
// Check and copy the gradle file into the subproject.
|
// Check and copy the gradle file into the subproject.
|
||||||
// Called by the loop below this function def.
|
// Called by the loop below this function def.
|
||||||
var checkAndCopy = function(subProject, root) {
|
var checkAndCopy = function (subProject, root) {
|
||||||
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
||||||
// This is the future-proof way of checking if a file exists
|
// This is the future-proof way of checking if a file exists
|
||||||
// This must be synchronous to satisfy a Travis test
|
// This must be synchronous to satisfy a Travis test
|
||||||
@ -143,7 +142,6 @@ GradleBuilder.prototype.prepBuildFiles = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var name = this.extractRealProjectNameFromManifest();
|
var name = this.extractRealProjectNameFromManifest();
|
||||||
// Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
// Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
||||||
var settingsGradlePaths = subProjects.map(function (p) {
|
var settingsGradlePaths = subProjects.map(function (p) {
|
||||||
@ -163,14 +161,13 @@ GradleBuilder.prototype.prepBuildFiles = function () {
|
|||||||
var depsList = '';
|
var depsList = '';
|
||||||
var root = this.root;
|
var root = this.root;
|
||||||
|
|
||||||
|
|
||||||
// Cordova Plugins can be written as library modules that would use Cordova as a
|
// Cordova Plugins can be written as library modules that would use Cordova as a
|
||||||
// dependency. Because we need to make sure that Cordova is compiled only once for
|
// dependency. Because we need to make sure that Cordova is compiled only once for
|
||||||
// dexing, we make sure to exclude CordovaLib from these modules
|
// dexing, we make sure to exclude CordovaLib from these modules
|
||||||
var insertExclude = function(p) {
|
var insertExclude = function (p) {
|
||||||
var gradlePath = path.join(root, p, 'build.gradle');
|
var gradlePath = path.join(root, p, 'build.gradle');
|
||||||
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
||||||
if(projectGradleFile.indexOf('CordovaLib') != -1) {
|
if (projectGradleFile.indexOf('CordovaLib') !== -1) {
|
||||||
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
||||||
} else {
|
} else {
|
||||||
depsList += '\n';
|
depsList += '\n';
|
||||||
@ -186,7 +183,6 @@ GradleBuilder.prototype.prepBuildFiles = function () {
|
|||||||
insertExclude(p);
|
insertExclude(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
|
// For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
|
||||||
var SYSTEM_LIBRARY_MAPPINGS = [
|
var SYSTEM_LIBRARY_MAPPINGS = [
|
||||||
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
||||||
@ -212,8 +208,8 @@ GradleBuilder.prototype.prepBuildFiles = function () {
|
|||||||
depsList += ' compile "' + mavenRef + '"\n';
|
depsList += ' compile "' + mavenRef + '"\n';
|
||||||
});
|
});
|
||||||
|
|
||||||
//This code is dangerous and actually writes gradle declarations directly into the build.gradle
|
// This code is dangerous and actually writes gradle declarations directly into the build.gradle
|
||||||
//Try not to mess with this if possible
|
// Try not to mess with this if possible
|
||||||
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
||||||
var includeList = '';
|
var includeList = '';
|
||||||
propertiesObj.gradleIncludes.forEach(function (includePath) {
|
propertiesObj.gradleIncludes.forEach(function (includePath) {
|
||||||
|
144
bin/templates/cordova/lib/builders/StudioBuilder.js
vendored
144
bin/templates/cordova/lib/builders/StudioBuilder.js
vendored
@ -42,10 +42,10 @@ function StudioBuilder (projectRoot) {
|
|||||||
|
|
||||||
util.inherits(StudioBuilder, GenericBuilder);
|
util.inherits(StudioBuilder, GenericBuilder);
|
||||||
|
|
||||||
StudioBuilder.prototype.getArgs = function(cmd, opts) {
|
StudioBuilder.prototype.getArgs = function (cmd, opts) {
|
||||||
if (cmd == 'release') {
|
if (cmd === 'release') {
|
||||||
cmd = 'cdvBuildRelease';
|
cmd = 'cdvBuildRelease';
|
||||||
} else if (cmd == 'debug') {
|
} else if (cmd === 'debug') {
|
||||||
cmd = 'cdvBuildDebug';
|
cmd = 'cdvBuildDebug';
|
||||||
}
|
}
|
||||||
var args = [cmd, '-b', path.join(this.root, 'build.gradle')];
|
var args = [cmd, '-b', path.join(this.root, 'build.gradle')];
|
||||||
@ -69,20 +69,19 @@ StudioBuilder.prototype.getArgs = function(cmd, opts) {
|
|||||||
* This returns a promise
|
* This returns a promise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
StudioBuilder.prototype.runGradleWrapper = function(gradle_cmd) {
|
StudioBuilder.prototype.runGradleWrapper = function (gradle_cmd) {
|
||||||
var gradlePath = path.join(this.root, 'gradlew');
|
var gradlePath = path.join(this.root, 'gradlew');
|
||||||
var wrapperGradle = path.join(this.root, 'wrapper.gradle');
|
var wrapperGradle = path.join(this.root, 'wrapper.gradle');
|
||||||
if(fs.existsSync(gradlePath)) {
|
if (fs.existsSync(gradlePath)) {
|
||||||
//Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
|
// Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
|
||||||
} else {
|
} else {
|
||||||
return spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'});
|
return spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
StudioBuilder.prototype.readProjectProperties = function () {
|
StudioBuilder.prototype.readProjectProperties = function () {
|
||||||
|
|
||||||
function findAllUniq(data, r) {
|
function findAllUniq (data, r) {
|
||||||
var s = {};
|
var s = {};
|
||||||
var m;
|
var m;
|
||||||
while ((m = r.exec(data))) {
|
while ((m = r.exec(data))) {
|
||||||
@ -107,46 +106,44 @@ StudioBuilder.prototype.extractRealProjectNameFromManifest = function () {
|
|||||||
throw new CordovaError('Could not find package name in ' + manifestPath);
|
throw new CordovaError('Could not find package name in ' + manifestPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
var packageName=m[1];
|
var packageName = m[1];
|
||||||
var lastDotIndex = packageName.lastIndexOf('.');
|
var lastDotIndex = packageName.lastIndexOf('.');
|
||||||
return packageName.substring(lastDotIndex + 1);
|
return packageName.substring(lastDotIndex + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Makes the project buildable, minus the gradle wrapper.
|
// Makes the project buildable, minus the gradle wrapper.
|
||||||
StudioBuilder.prototype.prepBuildFiles = function() {
|
StudioBuilder.prototype.prepBuildFiles = function () {
|
||||||
// Update the version of build.gradle in each dependent library.
|
// Update the version of build.gradle in each dependent library.
|
||||||
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
|
var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
|
||||||
var propertiesObj = this.readProjectProperties();
|
var propertiesObj = this.readProjectProperties();
|
||||||
var subProjects = propertiesObj.libs;
|
var subProjects = propertiesObj.libs;
|
||||||
var checkAndCopy = function(subProject, root) {
|
var checkAndCopy = function (subProject, root) {
|
||||||
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
var subProjectGradle = path.join(root, subProject, 'build.gradle');
|
||||||
// This is the future-proof way of checking if a file exists
|
// This is the future-proof way of checking if a file exists
|
||||||
// This must be synchronous to satisfy a Travis test
|
// This must be synchronous to satisfy a Travis test
|
||||||
try {
|
try {
|
||||||
fs.accessSync(subProjectGradle, fs.F_OK);
|
fs.accessSync(subProjectGradle, fs.F_OK);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
shell.cp('-f', pluginBuildGradle, subProjectGradle);
|
shell.cp('-f', pluginBuildGradle, subProjectGradle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (var i = 0; i < subProjects.length; ++i) {
|
for (var i = 0; i < subProjects.length; ++i) {
|
||||||
if (subProjects[i] !== 'CordovaLib') {
|
if (subProjects[i] !== 'CordovaLib') {
|
||||||
checkAndCopy(subProjects[i], this.root);
|
checkAndCopy(subProjects[i], this.root);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var name = this.extractRealProjectNameFromManifest();
|
var name = this.extractRealProjectNameFromManifest();
|
||||||
//Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
// Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
|
||||||
var settingsGradlePaths = subProjects.map(function(p){
|
var settingsGradlePaths = subProjects.map(function (p) {
|
||||||
var realDir=p.replace(/[/\\]/g, ':');
|
var realDir = p.replace(/[/\\]/g, ':');
|
||||||
var libName=realDir.replace(name+'-','');
|
var libName = realDir.replace(name + '-', '');
|
||||||
var str='include ":'+libName+'"\n';
|
var str = 'include ":' + libName + '"\n';
|
||||||
if(realDir.indexOf(name+'-')!==-1)
|
if (realDir.indexOf(name + '-') !== -1) {
|
||||||
str+='project(":'+libName+'").projectDir = new File("'+p+'")\n';
|
str += 'project(":' + libName + '").projectDir = new File("' + p + '")\n';
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(this.root, 'settings.gradle'),
|
fs.writeFileSync(path.join(this.root, 'settings.gradle'),
|
||||||
'// GENERATED FILE - DO NOT EDIT\n' +
|
'// GENERATED FILE - DO NOT EDIT\n' +
|
||||||
'include ":"\n' + settingsGradlePaths.join(''));
|
'include ":"\n' + settingsGradlePaths.join(''));
|
||||||
@ -155,19 +152,18 @@ StudioBuilder.prototype.prepBuildFiles = function() {
|
|||||||
var buildGradle = fs.readFileSync(path.join(this.root, 'build.gradle'), 'utf8');
|
var buildGradle = fs.readFileSync(path.join(this.root, 'build.gradle'), 'utf8');
|
||||||
var depsList = '';
|
var depsList = '';
|
||||||
var root = this.root;
|
var root = this.root;
|
||||||
var insertExclude = function(p) {
|
var insertExclude = function (p) {
|
||||||
var gradlePath = path.join(root, p, 'build.gradle');
|
var gradlePath = path.join(root, p, 'build.gradle');
|
||||||
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
|
||||||
if(projectGradleFile.indexOf('CordovaLib') != -1) {
|
if (projectGradleFile.indexOf('CordovaLib') !== -1) {
|
||||||
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
depsList += '{\n exclude module:("CordovaLib")\n }\n';
|
||||||
}
|
} else {
|
||||||
else {
|
depsList += '\n';
|
||||||
depsList +='\n';
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
subProjects.forEach(function(p) {
|
subProjects.forEach(function (p) {
|
||||||
console.log('Subproject Path: ' + p);
|
console.log('Subproject Path: ' + p);
|
||||||
var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
|
var libName = p.replace(/[/\\]/g, ':').replace(name + '-', '');
|
||||||
depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
|
depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
|
||||||
insertExclude(p);
|
insertExclude(p);
|
||||||
depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
|
depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
|
||||||
@ -178,7 +174,7 @@ StudioBuilder.prototype.prepBuildFiles = function() {
|
|||||||
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
[/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
|
||||||
[/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']
|
[/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']
|
||||||
];
|
];
|
||||||
propertiesObj.systemLibs.forEach(function(p) {
|
propertiesObj.systemLibs.forEach(function (p) {
|
||||||
var mavenRef;
|
var mavenRef;
|
||||||
// It's already in gradle form if it has two ':'s
|
// It's already in gradle form if it has two ':'s
|
||||||
if (/:.*:/.exec(p)) {
|
if (/:.*:/.exec(p)) {
|
||||||
@ -199,52 +195,50 @@ StudioBuilder.prototype.prepBuildFiles = function() {
|
|||||||
});
|
});
|
||||||
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
|
||||||
var includeList = '';
|
var includeList = '';
|
||||||
propertiesObj.gradleIncludes.forEach(function(includePath) {
|
propertiesObj.gradleIncludes.forEach(function (includePath) {
|
||||||
includeList += 'apply from: "' + includePath + '"\n';
|
includeList += 'apply from: "' + includePath + '"\n';
|
||||||
});
|
});
|
||||||
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + includeList + '$2');
|
buildGradle = buildGradle.replace(/(PLUGIN GRADLE EXTENSIONS START)[\s\S]*(\/\/ PLUGIN GRADLE EXTENSIONS END)/, '$1\n' + includeList + '$2');
|
||||||
fs.writeFileSync(path.join(this.root, 'build.gradle'), buildGradle);
|
fs.writeFileSync(path.join(this.root, 'build.gradle'), buildGradle);
|
||||||
};
|
};
|
||||||
|
|
||||||
StudioBuilder.prototype.prepEnv = function(opts) {
|
StudioBuilder.prototype.prepEnv = function (opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return check_reqs.check_gradle()
|
return check_reqs.check_gradle()
|
||||||
.then(function(gradlePath) {
|
.then(function (gradlePath) {
|
||||||
return self.runGradleWrapper(gradlePath);
|
return self.runGradleWrapper(gradlePath);
|
||||||
}).then(function() {
|
}).then(function () {
|
||||||
return self.prepBuildFiles();
|
return self.prepBuildFiles();
|
||||||
}).then(function() {
|
}).then(function () {
|
||||||
// If the gradle distribution URL is set, make sure it points to version we want.
|
// If the gradle distribution URL is set, make sure it points to version we want.
|
||||||
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
||||||
// For some reason, using ^ and $ don't work. This does the job, though.
|
// For some reason, using ^ and $ don't work. This does the job, though.
|
||||||
var distributionUrlRegex = /distributionUrl.*zip/;
|
var distributionUrlRegex = /distributionUrl.*zip/;
|
||||||
/*jshint -W069 */
|
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip';
|
||||||
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip';
|
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
||||||
/*jshint +W069 */
|
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
||||||
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
|
||||||
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
|
||||||
shell.sed('-i', distributionUrlRegex, 'distributionUrl='+distributionUrl, gradleWrapperPropertiesPath);
|
|
||||||
|
|
||||||
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
||||||
var propertiesFilePath = path.join(self.root, propertiesFile);
|
var propertiesFilePath = path.join(self.root, propertiesFile);
|
||||||
if (opts.packageInfo) {
|
if (opts.packageInfo) {
|
||||||
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
||||||
} else if (isAutoGenerated(propertiesFilePath)) {
|
} else if (isAutoGenerated(propertiesFilePath)) {
|
||||||
shell.rm('-f', propertiesFilePath);
|
shell.rm('-f', propertiesFilePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Builds the project with gradle.
|
* Builds the project with gradle.
|
||||||
* Returns a promise.
|
* Returns a promise.
|
||||||
*/
|
*/
|
||||||
StudioBuilder.prototype.build = function(opts) {
|
StudioBuilder.prototype.build = function (opts) {
|
||||||
var wrapper = path.join(this.root, 'gradlew');
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts);
|
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
||||||
|
|
||||||
return spawn(wrapper, args, {stdio: 'pipe'})
|
return spawn(wrapper, args, {stdio: 'pipe'})
|
||||||
.progress(function (stdio){
|
.progress(function (stdio) {
|
||||||
if (stdio.stderr) {
|
if (stdio.stderr) {
|
||||||
/*
|
/*
|
||||||
* Workaround for the issue with Java printing some unwanted information to
|
* Workaround for the issue with Java printing some unwanted information to
|
||||||
@ -263,7 +257,7 @@ StudioBuilder.prototype.build = function(opts) {
|
|||||||
}
|
}
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
||||||
return check_reqs.check_android_target(error).then(function() {
|
return check_reqs.check_android_target(error).then(function () {
|
||||||
// If due to some odd reason - check_android_target succeeds
|
// If due to some odd reason - check_android_target succeeds
|
||||||
// we should still fail here.
|
// we should still fail here.
|
||||||
return Q.reject(error);
|
return Q.reject(error);
|
||||||
@ -273,19 +267,19 @@ StudioBuilder.prototype.build = function(opts) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
StudioBuilder.prototype.clean = function(opts) {
|
StudioBuilder.prototype.clean = function (opts) {
|
||||||
var builder = this;
|
var builder = this;
|
||||||
var wrapper = path.join(this.root, 'gradlew');
|
var wrapper = path.join(this.root, 'gradlew');
|
||||||
var args = builder.getArgs('clean', opts);
|
var args = builder.getArgs('clean', opts);
|
||||||
return Q().then(function() {
|
return Q().then(function () {
|
||||||
return spawn(wrapper, args, {stdio: 'inherit'});
|
return spawn(wrapper, args, {stdio: 'inherit'});
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
shell.rm('-rf', path.join(builder.root, 'out'));
|
shell.rm('-rf', path.join(builder.root, 'out'));
|
||||||
|
|
||||||
['debug', 'release'].forEach(function(config) {
|
['debug', 'release'].forEach(function (config) {
|
||||||
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
||||||
if(isAutoGenerated(propertiesFilePath)){
|
if (isAutoGenerated(propertiesFilePath)) {
|
||||||
shell.rm('-f', propertiesFilePath);
|
shell.rm('-f', propertiesFilePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -294,6 +288,6 @@ StudioBuilder.prototype.clean = function(opts) {
|
|||||||
|
|
||||||
module.exports = StudioBuilder;
|
module.exports = StudioBuilder;
|
||||||
|
|
||||||
function isAutoGenerated(file) {
|
function isAutoGenerated (file) {
|
||||||
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
|
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
|
||||||
}
|
}
|
||||||
|
4
bin/templates/cordova/lib/prepare.js
vendored
4
bin/templates/cordova/lib/prepare.js
vendored
@ -191,10 +191,10 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
|||||||
.setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
|
.setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
|
||||||
.write();
|
.write();
|
||||||
|
|
||||||
//Java file paths shouldn't be hard coded
|
// Java file paths shouldn't be hard coded
|
||||||
var javaPattern = path.join(locations.javaSrc, orig_pkg.replace(/\./g, '/'), '*.java');
|
var javaPattern = path.join(locations.javaSrc, orig_pkg.replace(/\./g, '/'), '*.java');
|
||||||
|
|
||||||
var java_files = shell.ls(javaPattern).filter(function(f) {
|
var java_files = shell.ls(javaPattern).filter(function (f) {
|
||||||
return shell.grep(/extends\s+CordovaActivity/g, f);
|
return shell.grep(/extends\s+CordovaActivity/g, f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user