summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/cordova/lib
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/android/cordova/lib')
-rw-r--r--StoneIsland/platforms/android/cordova/lib/Adb.js105
-rw-r--r--StoneIsland/platforms/android/cordova/lib/AndroidManifest.js161
-rw-r--r--StoneIsland/platforms/android/cordova/lib/AndroidProject.js210
-rw-r--r--StoneIsland/platforms/android/cordova/lib/AndroidStudio.js42
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/android_sdk.js106
-rw-r--r--StoneIsland/platforms/android/cordova/lib/build.js301
-rw-r--r--StoneIsland/platforms/android/cordova/lib/builders/AntBuilder.js156
-rw-r--r--StoneIsland/platforms/android/cordova/lib/builders/GenericBuilder.js147
-rw-r--r--StoneIsland/platforms/android/cordova/lib/builders/GradleBuilder.js279
-rw-r--r--StoneIsland/platforms/android/cordova/lib/builders/builders.js47
-rw-r--r--StoneIsland/platforms/android/cordova/lib/check_reqs.js432
-rw-r--r--StoneIsland/platforms/android/cordova/lib/device.js120
-rw-r--r--StoneIsland/platforms/android/cordova/lib/emulator.js532
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/install-device42
-rw-r--r--StoneIsland/platforms/android/cordova/lib/install-device.bat26
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/install-emulator38
-rw-r--r--StoneIsland/platforms/android/cordova/lib/install-emulator.bat26
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/list-devices34
-rw-r--r--StoneIsland/platforms/android/cordova/lib/list-devices.bat26
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/list-emulator-images34
-rw-r--r--StoneIsland/platforms/android/cordova/lib/list-emulator-images.bat26
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/list-started-emulators34
-rw-r--r--StoneIsland/platforms/android/cordova/lib/list-started-emulators.bat26
-rw-r--r--StoneIsland/platforms/android/cordova/lib/log.js56
-rw-r--r--StoneIsland/platforms/android/cordova/lib/plugin-build.gradle70
-rw-r--r--StoneIsland/platforms/android/cordova/lib/pluginHandlers.js308
-rw-r--r--StoneIsland/platforms/android/cordova/lib/prepare.js471
-rw-r--r--StoneIsland/platforms/android/cordova/lib/retry.js68
-rw-r--r--StoneIsland/platforms/android/cordova/lib/run.js141
-rwxr-xr-xStoneIsland/platforms/android/cordova/lib/start-emulator39
-rw-r--r--StoneIsland/platforms/android/cordova/lib/start-emulator.bat26
31 files changed, 0 insertions, 4129 deletions
diff --git a/StoneIsland/platforms/android/cordova/lib/Adb.js b/StoneIsland/platforms/android/cordova/lib/Adb.js
deleted file mode 100644
index 84ae707e..00000000
--- a/StoneIsland/platforms/android/cordova/lib/Adb.js
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q');
-var os = require('os');
-var events = require('cordova-common').events;
-var spawn = require('cordova-common').superspawn.spawn;
-var CordovaError = require('cordova-common').CordovaError;
-
-var Adb = {};
-
-function isDevice(line) {
- return line.match(/\w+\tdevice/) && !line.match(/emulator/);
-}
-
-function isEmulator(line) {
- return line.match(/device/) && line.match(/emulator/);
-}
-
-/**
- * Lists available/connected devices and emulators
- *
- * @param {Object} opts Various options
- * @param {Boolean} opts.emulators Specifies whether this method returns
- * emulators only
- *
- * @return {Promise<String[]>} list of available/connected
- * devices/emulators
- */
-Adb.devices = function (opts) {
- return spawn('adb', ['devices'], {cwd: os.tmpdir()})
- .then(function(output) {
- return output.split('\n').filter(function (line) {
- // Filter out either real devices or emulators, depending on options
- return (line && opts && opts.emulators) ? isEmulator(line) : isDevice(line);
- }).map(function (line) {
- return line.replace(/\tdevice/, '').replace('\r', '');
- });
- });
-};
-
-Adb.install = function (target, packagePath, opts) {
- events.emit('verbose', 'Installing apk ' + packagePath + ' on target ' + target + '...');
- var args = ['-s', target, 'install'];
- if (opts && opts.replace) args.push('-r');
- return spawn('adb', args.concat(packagePath), {cwd: os.tmpdir()})
- .then(function(output) {
- // 'adb install' seems to always returns no error, even if installation fails
- // so we catching output to detect installation failure
- if (output.match(/Failure/)) {
- if (output.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
- output += '\n\n' + 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
- ' or sign and deploy the unsigned apk manually using Android tools.';
- } else if (output.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
- output += '\n\n' + 'You\'re trying to install apk with a lower versionCode that is already installed.' +
- '\nEither uninstall an app or increment the versionCode.';
- }
-
- return Q.reject(new CordovaError('Failed to install apk to device: ' + output));
- }
- });
-};
-
-Adb.uninstall = function (target, packageId) {
- events.emit('verbose', 'Uninstalling package ' + packageId + ' from target ' + target + '...');
- return spawn('adb', ['-s', target, 'uninstall', packageId], {cwd: os.tmpdir()});
-};
-
-Adb.shell = function (target, shellCommand) {
- events.emit('verbose', 'Running adb shell command "' + shellCommand + '" on target ' + target + '...');
- var args = ['-s', target, 'shell'];
- shellCommand = shellCommand.split(/\s+/);
- return spawn('adb', args.concat(shellCommand), {cwd: os.tmpdir()})
- .catch(function (output) {
- return Q.reject(new CordovaError('Failed to execute shell command "' +
- shellCommand + '"" on device: ' + output));
- });
-};
-
-Adb.start = function (target, activityName) {
- events.emit('verbose', 'Starting application "' + activityName + '" on target ' + target + '...');
- return Adb.shell(target, 'am start -W -a android.intent.action.MAIN -n' + activityName)
- .catch(function (output) {
- return Q.reject(new CordovaError('Failed to start application "' +
- activityName + '"" on device: ' + output));
- });
-};
-
-module.exports = Adb;
diff --git a/StoneIsland/platforms/android/cordova/lib/AndroidManifest.js b/StoneIsland/platforms/android/cordova/lib/AndroidManifest.js
deleted file mode 100644
index 8248f593..00000000
--- a/StoneIsland/platforms/android/cordova/lib/AndroidManifest.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var fs = require('fs');
-var et = require('elementtree');
-var xml= require('cordova-common').xmlHelpers;
-
-var DEFAULT_ORIENTATION = 'default';
-
-/** Wraps an AndroidManifest file */
-function AndroidManifest(path) {
- this.path = path;
- this.doc = xml.parseElementtreeSync(path);
- if (this.doc.getroot().tag !== 'manifest') {
- throw new Error('AndroidManifest at ' + path + ' has incorrect root node name (expected "manifest")');
- }
-}
-
-AndroidManifest.prototype.getVersionName = function() {
- return this.doc.getroot().attrib['android:versionName'];
-};
-
-AndroidManifest.prototype.setVersionName = function(versionName) {
- this.doc.getroot().attrib['android:versionName'] = versionName;
- return this;
-};
-
-AndroidManifest.prototype.getVersionCode = function() {
- return this.doc.getroot().attrib['android:versionCode'];
-};
-
-AndroidManifest.prototype.setVersionCode = function(versionCode) {
- this.doc.getroot().attrib['android:versionCode'] = versionCode;
- return this;
-};
-
-AndroidManifest.prototype.getPackageId = function() {
- /*jshint -W069 */
- return this.doc.getroot().attrib['package'];
- /*jshint +W069 */
-};
-
-AndroidManifest.prototype.setPackageId = function(pkgId) {
- /*jshint -W069 */
- this.doc.getroot().attrib['package'] = pkgId;
- /*jshint +W069 */
- return this;
-};
-
-AndroidManifest.prototype.getActivity = function() {
- var activity = this.doc.getroot().find('./application/activity');
- return {
- getName: function () {
- return activity.attrib['android:name'];
- },
- setName: function (name) {
- if (!name) {
- delete activity.attrib['android:name'];
- } else {
- activity.attrib['android:name'] = name;
- }
- return this;
- },
- getOrientation: function () {
- return activity.attrib['android:screenOrientation'];
- },
- setOrientation: function (orientation) {
- if (!orientation || orientation.toLowerCase() === DEFAULT_ORIENTATION) {
- delete activity.attrib['android:screenOrientation'];
- } else {
- activity.attrib['android:screenOrientation'] = orientation;
- }
- return this;
- },
- getLaunchMode: function () {
- return activity.attrib['android:launchMode'];
- },
- setLaunchMode: function (launchMode) {
- if (!launchMode) {
- delete activity.attrib['android:launchMode'];
- } else {
- activity.attrib['android:launchMode'] = launchMode;
- }
- return this;
- }
- };
-};
-
-['minSdkVersion', 'maxSdkVersion', 'targetSdkVersion']
-.forEach(function(sdkPrefName) {
- // Copy variable reference to avoid closure issues
- var prefName = sdkPrefName;
-
- AndroidManifest.prototype['get' + capitalize(prefName)] = function() {
- var usesSdk = this.doc.getroot().find('./uses-sdk');
- return usesSdk && usesSdk.attrib['android:' + prefName];
- };
-
- AndroidManifest.prototype['set' + capitalize(prefName)] = function(prefValue) {
- var usesSdk = this.doc.getroot().find('./uses-sdk');
-
- if (!usesSdk && prefValue) { // if there is no required uses-sdk element, we should create it first
- usesSdk = new et.Element('uses-sdk');
- this.doc.getroot().append(usesSdk);
- }
-
- if (prefValue) {
- usesSdk.attrib['android:' + prefName] = prefValue;
- }
-
- return this;
- };
-});
-
-AndroidManifest.prototype.getDebuggable = function() {
- return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
-};
-
-AndroidManifest.prototype.setDebuggable = function(value) {
- var application = this.doc.getroot().find('./application');
- if (value) {
- application.attrib['android:debuggable'] = 'true';
- } else {
- // The default value is "false", so we can remove attribute at all.
- delete application.attrib['android:debuggable'];
- }
- return this;
-};
-
-/**
- * Writes manifest to disk syncronously. If filename is specified, then manifest
- * will be written to that file
- *
- * @param {String} [destPath] File to write manifest to. If omitted,
- * manifest will be written to file it has been read from.
- */
-AndroidManifest.prototype.write = function(destPath) {
- fs.writeFileSync(destPath || this.path, this.doc.write({indent: 4}), 'utf-8');
-};
-
-module.exports = AndroidManifest;
-
-function capitalize (str) {
- return str.charAt(0).toUpperCase() + str.slice(1);
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/AndroidProject.js b/StoneIsland/platforms/android/cordova/lib/AndroidProject.js
deleted file mode 100644
index fa1c6129..00000000
--- a/StoneIsland/platforms/android/cordova/lib/AndroidProject.js
+++ /dev/null
@@ -1,210 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var fs = require('fs');
-var path = require('path');
-var properties_parser = require('properties-parser');
-var AndroidManifest = require('./AndroidManifest');
-var AndroidStudio = require('./AndroidStudio');
-var pluginHandlers = require('./pluginHandlers');
-
-var projectFileCache = {};
-
-function addToPropertyList(projectProperties, key, value) {
- var i = 1;
- while (projectProperties.get(key + '.' + i))
- i++;
-
- projectProperties.set(key + '.' + i, value);
- projectProperties.dirty = true;
-}
-
-function removeFromPropertyList(projectProperties, key, value) {
- var i = 1;
- 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(key + '.' + i);
- break;
- }
- i++;
- }
- projectProperties.dirty = true;
-}
-
-function getRelativeLibraryPath (parentDir, subDir) {
- var libraryPath = path.relative(parentDir, subDir);
- return (path.sep == '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;
-}
-
-function AndroidProject(projectDir) {
- this._propertiesEditors = {};
- this._subProjectDirs = {};
- this._dirty = false;
- this.projectDir = projectDir;
- this.platformWww = path.join(this.projectDir, 'platform_www');
- this.www = path.join(this.projectDir, 'assets/www');
- if(AndroidStudio.isAndroidStudioProject(projectDir) === true) {
- this.www = path.join(this.projectDir, 'app/src/main/assets/www');
- }
-}
-
-AndroidProject.getProjectFile = function (projectDir) {
- if (!projectFileCache[projectDir]) {
- projectFileCache[projectDir] = new AndroidProject(projectDir);
- }
-
- return projectFileCache[projectDir];
-};
-
-AndroidProject.purgeCache = function (projectDir) {
- if (projectDir) {
- delete projectFileCache[projectDir];
- } else {
- projectFileCache = {};
- }
-};
-
-/**
- * Reads the package name out of the Android Manifest file
- *
- * @param {String} projectDir The absolute path to the directory containing the project
- *
- * @return {String} The name of the package
- */
-AndroidProject.prototype.getPackageName = function() {
- var manifestPath = path.join(this.projectDir, 'AndroidManifest.xml');
- if(AndroidStudio.isAndroidStudioProject(this.projectDir) === true) {
- manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
- }
- return new AndroidManifest(manifestPath).getPackageId();
-};
-
-AndroidProject.prototype.getCustomSubprojectRelativeDir = function(plugin_id, src) {
- // All custom subprojects are prefixed with the last portion of the package id.
- // This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.
- var packageName = this.getPackageName();
- var lastDotIndex = packageName.lastIndexOf('.');
- var prefix = packageName.substring(lastDotIndex + 1);
- var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));
- return subRelativeDir;
-};
-
-AndroidProject.prototype.addSubProject = function(parentDir, subDir) {
- 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'));
- subProperties.dirty = true;
- this._subProjectDirs[subDir] = true;
- }
- addToPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));
-
- this._dirty = true;
-};
-
-AndroidProject.prototype.removeSubProject = function(parentDir, subDir) {
- var parentProjectFile = path.resolve(parentDir, 'project.properties');
- var parentProperties = this._getPropertiesFile(parentProjectFile);
- removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));
- delete this._subProjectDirs[subDir];
- this._dirty = true;
-};
-
-AndroidProject.prototype.addGradleReference = function(parentDir, subDir) {
- var parentProjectFile = path.resolve(parentDir, 'project.properties');
- var parentProperties = this._getPropertiesFile(parentProjectFile);
- addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
- this._dirty = true;
-};
-
-AndroidProject.prototype.removeGradleReference = function(parentDir, subDir) {
- var parentProjectFile = path.resolve(parentDir, 'project.properties');
- var parentProperties = this._getPropertiesFile(parentProjectFile);
- removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
- this._dirty = true;
-};
-
-AndroidProject.prototype.addSystemLibrary = function(parentDir, value) {
- var parentProjectFile = path.resolve(parentDir, 'project.properties');
- var parentProperties = this._getPropertiesFile(parentProjectFile);
- addToPropertyList(parentProperties, 'cordova.system.library', value);
- this._dirty = true;
-};
-
-AndroidProject.prototype.removeSystemLibrary = function(parentDir, value) {
- var parentProjectFile = path.resolve(parentDir, 'project.properties');
- var parentProperties = this._getPropertiesFile(parentProjectFile);
- removeFromPropertyList(parentProperties, 'cordova.system.library', value);
- this._dirty = true;
-};
-
-AndroidProject.prototype.write = function() {
- if (!this._dirty) {
- return;
- }
- this._dirty = false;
-
- for (var filename in this._propertiesEditors) {
- var editor = this._propertiesEditors[filename];
- if (editor.dirty) {
- fs.writeFileSync(filename, editor.toString());
- editor.dirty = false;
- }
- }
-};
-
-AndroidProject.prototype._getPropertiesFile = function (filename) {
- if (!this._propertiesEditors[filename]) {
- if (fs.existsSync(filename)) {
- this._propertiesEditors[filename] = properties_parser.createEditor(filename);
- } else {
- this._propertiesEditors[filename] = properties_parser.createEditor();
- }
- }
-
- return this._propertiesEditors[filename];
-};
-
-AndroidProject.prototype.getInstaller = function (type) {
- return pluginHandlers.getInstaller(type);
-};
-
-AndroidProject.prototype.getUninstaller = function (type) {
- return pluginHandlers.getUninstaller(type);
-};
-
-/*
- * This checks if an Android project is clean or has old build artifacts
- */
-
-AndroidProject.prototype.isClean = function() {
- var build_path = path.join(this.projectDir, 'build');
- //If the build directory doesn't exist, it's clean
- return !(fs.existsSync(build_path));
-};
-
-module.exports = AndroidProject;
diff --git a/StoneIsland/platforms/android/cordova/lib/AndroidStudio.js b/StoneIsland/platforms/android/cordova/lib/AndroidStudio.js
deleted file mode 100644
index 335b334b..00000000
--- a/StoneIsland/platforms/android/cordova/lib/AndroidStudio.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This is a simple routine that checks if project is an Android Studio Project
- *
- * @param {String} root Root folder of the project
- */
-
-/*jshint esnext: false */
-
-var path = require('path');
-var fs = require('fs');
-var CordovaError = require('cordova-common').CordovaError;
-
-module.exports.isAndroidStudioProject = function isAndroidStudioProject(root) {
- var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res', 'project.properties', 'platform_www'];
- var androidStudioFiles = ['app', 'gradle', 'app/src/main/res'];
-
- // assume it is an AS project and not an Eclipse project
- var isEclipse = false;
- var isAS = true;
-
- if(!fs.existsSync(root)) {
- throw new CordovaError('AndroidStudio.js:inAndroidStudioProject root does not exist: ' + root);
- }
-
- // if any of the following exists, then we are not an ASProj
- eclipseFiles.forEach(function(file) {
- if(fs.existsSync(path.join(root, file))) {
- isEclipse = true;
- }
- });
-
- // if it is NOT an eclipse project, check that all required files exist
- if(!isEclipse) {
- androidStudioFiles.forEach(function(file){
- if(!fs.existsSync(path.join(root, file))) {
- console.log('missing file :: ' + file);
- isAS = false;
- }
- });
- }
- return (!isEclipse && isAS);
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/android_sdk.js b/StoneIsland/platforms/android/cordova/lib/android_sdk.js
deleted file mode 100755
index a1a806a6..00000000
--- a/StoneIsland/platforms/android/cordova/lib/android_sdk.js
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q'),
- superspawn = require('cordova-common').superspawn;
-
-var suffix_number_regex = /(\d+)$/;
-// Used for sorting Android targets, example strings to sort:
-// android-19
-// android-L
-// Google Inc.:Google APIs:20
-// Google Inc.:Glass Development Kit Preview:20
-// The idea is to sort based on largest "suffix" number - meaning the bigger
-// the number at the end, the more recent the target, the closer to the
-// start of the array.
-function sort_by_largest_numerical_suffix(a, b) {
- var suffix_a = a.match(suffix_number_regex);
- var suffix_b = b.match(suffix_number_regex);
- if (suffix_a && suffix_b) {
- // If the two targets being compared have suffixes, return less than
- // zero, or greater than zero, based on which suffix is larger.
- return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
- } else {
- // If no suffix numbers were detected, leave the order as-is between
- // elements a and b.
- return 0;
- }
-}
-
-module.exports.print_newest_available_sdk_target = function() {
- return module.exports.list_targets()
- .then(function(targets) {
- targets.sort(sort_by_largest_numerical_suffix);
- console.log(targets[0]);
- });
-};
-
-module.exports.version_string_to_api_level = {
- '4.0': 14,
- '4.0.3': 15,
- '4.1': 16,
- '4.2': 17,
- '4.3': 18,
- '4.4': 19,
- '4.4W': 20,
- '5.0': 21,
- '5.1': 22,
- '6.0': 23,
- '7.0': 24,
- '7.1.1': 25
-};
-
-function parse_targets(output) {
- var target_out = output.split('\n');
- var targets = [];
- for (var i = target_out.length - 1; i >= 0; i--) {
- if(target_out[i].match(/id:/)) { // if "id:" is in the line...
- targets.push(target_out[i].match(/"(.+)"/)[1]); //.. match whatever is in quotes.
- }
- }
- return targets;
-}
-
-module.exports.list_targets_with_android = function() {
- return superspawn.spawn('android', ['list', 'target'])
- .then(parse_targets);
-};
-
-module.exports.list_targets_with_avdmanager = function() {
- return superspawn.spawn('avdmanager', ['list', 'target'])
- .then(parse_targets);
-};
-
-module.exports.list_targets = function() {
- return module.exports.list_targets_with_avdmanager()
- .catch(function(err) {
- // If there's an error, like avdmanager could not be found, we can try
- // as a last resort, to run `android`, in case this is a super old
- // SDK installation.
- if (err && (err.code == 'ENOENT' || (err.stderr && err.stderr.match(/not recognized/)))) {
- return module.exports.list_targets_with_android();
- } else throw err;
- })
- .then(function(targets) {
- if (targets.length === 0) {
- return Q.reject(new Error('No android targets (SDKs) installed!'));
- }
- return targets;
- });
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/build.js b/StoneIsland/platforms/android/cordova/lib/build.js
deleted file mode 100644
index bd613da2..00000000
--- a/StoneIsland/platforms/android/cordova/lib/build.js
+++ /dev/null
@@ -1,301 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q'),
- path = require('path'),
- fs = require('fs'),
- nopt = require('nopt');
-
-var Adb = require('./Adb');
-
-var builders = require('./builders/builders');
-var events = require('cordova-common').events;
-var spawn = require('cordova-common').superspawn.spawn;
-var CordovaError = require('cordova-common').CordovaError;
-
-function parseOpts(options, resolvedTarget, projectRoot) {
- options = options || {};
- options.argv = nopt({
- gradle: Boolean,
- ant: Boolean,
- prepenv: Boolean,
- versionCode: String,
- minSdkVersion: String,
- gradleArg: [String, Array],
- keystore: path,
- alias: String,
- storePassword: String,
- password: String,
- keystoreType: String
- }, {}, options.argv, 0);
-
- var ret = {
- buildType: options.release ? 'release' : 'debug',
- buildMethod: process.env.ANDROID_BUILD || 'gradle',
- prepEnv: options.argv.prepenv,
- arch: resolvedTarget && resolvedTarget.arch,
- extraArgs: []
- };
-
- if (options.argv.ant || options.argv.gradle)
- ret.buildMethod = options.argv.ant ? 'ant' : 'gradle';
-
- if (options.nobuild) ret.buildMethod = 'none';
-
- if (options.argv.versionCode)
- ret.extraArgs.push('-PcdvVersionCode=' + options.argv.versionCode);
-
- if (options.argv.minSdkVersion)
- ret.extraArgs.push('-PcdvMinSdkVersion=' + options.argv.minSdkVersion);
-
- if (options.argv.gradleArg) {
- ret.extraArgs = ret.extraArgs.concat(options.argv.gradleArg);
- }
-
- var packageArgs = {};
-
- if (options.argv.keystore)
- packageArgs.keystore = path.relative(projectRoot, path.resolve(options.argv.keystore));
-
- ['alias','storePassword','password','keystoreType'].forEach(function (flagName) {
- if (options.argv[flagName])
- packageArgs[flagName] = options.argv[flagName];
- });
-
- var buildConfig = options.buildConfig;
-
- // If some values are not specified as command line arguments - use build config to supplement them.
- // Command line arguemnts have precedence over build config.
- if (buildConfig) {
- if (!fs.existsSync(buildConfig)) {
- throw new Error('Specified build config file does not exist: ' + buildConfig);
- }
- events.emit('log', 'Reading build config file: '+ path.resolve(buildConfig));
- var buildjson = fs.readFileSync(buildConfig, 'utf8');
- var config = JSON.parse(buildjson.replace(/^\ufeff/, '')); // Remove BOM
- if (config.android && config.android[ret.buildType]) {
- var androidInfo = config.android[ret.buildType];
- if(androidInfo.keystore && !packageArgs.keystore) {
- if(androidInfo.keystore.substr(0,1) === '~') {
- androidInfo.keystore = process.env.HOME + androidInfo.keystore.substr(1);
- }
- packageArgs.keystore = path.resolve(path.dirname(buildConfig), androidInfo.keystore);
- events.emit('log', 'Reading the keystore from: ' + packageArgs.keystore);
- }
-
- ['alias', 'storePassword', 'password','keystoreType'].forEach(function (key){
- packageArgs[key] = packageArgs[key] || androidInfo[key];
- });
- }
- }
-
- if (packageArgs.keystore && packageArgs.alias) {
- ret.packageInfo = new PackageInfo(packageArgs.keystore, packageArgs.alias, packageArgs.storePassword,
- packageArgs.password, packageArgs.keystoreType);
- }
-
- if(!ret.packageInfo) {
- if(Object.keys(packageArgs).length > 0) {
- events.emit('warn', '\'keystore\' and \'alias\' need to be specified to generate a signed archive.');
- }
- }
-
- return ret;
-}
-
-/*
- * Builds the project with the specifed options
- * Returns a promise.
- */
-module.exports.runClean = function(options) {
- var opts = parseOpts(options, null, this.root);
- var builder = builders.getBuilder(opts.buildMethod);
- return builder.prepEnv(opts)
- .then(function() {
- return builder.clean(opts);
- });
-};
-
-/**
- * Builds the project with the specifed options.
- *
- * @param {BuildOptions} options A set of options. See PlatformApi.build
- * method documentation for reference.
- * @param {Object} optResolvedTarget A deployment target. Used to pass
- * target architecture from upstream 'run' call. TODO: remove this option in
- * favor of setting buildOptions.archs field.
- *
- * @return {Promise<Object>} Promise, resolved with built packages
- * information.
- */
-module.exports.run = function(options, optResolvedTarget) {
- var opts = parseOpts(options, optResolvedTarget, this.root);
- var builder = builders.getBuilder(opts.buildMethod);
- return builder.prepEnv(opts)
- .then(function() {
- if (opts.prepEnv) {
- events.emit('verbose', 'Build file successfully prepared.');
- return;
- }
- return builder.build(opts)
- .then(function() {
- var apkPaths = builder.findOutputApks(opts.buildType, opts.arch);
- events.emit('log', 'Built the following apk(s): \n\t' + apkPaths.join('\n\t'));
- return {
- apkPaths: apkPaths,
- buildType: opts.buildType,
- buildMethod: opts.buildMethod
- };
- });
- });
-};
-
-/*
- * Detects the architecture of a device/emulator
- * Returns "arm" or "x86".
- */
-module.exports.detectArchitecture = function(target) {
- function helper() {
- return Adb.shell(target, 'cat /proc/cpuinfo')
- .then(function(output) {
- return /intel/i.exec(output) ? 'x86' : 'arm';
- });
- }
- // It sometimes happens (at least on OS X), that this command will hang forever.
- // To fix it, either unplug & replug device, or restart adb server.
- return helper()
- .timeout(1000, new CordovaError('Device communication timed out. Try unplugging & replugging the device.'))
- .then(null, function(err) {
- if (/timed out/.exec('' + err)) {
- // adb kill-server doesn't seem to do the trick.
- // Could probably find a x-platform version of killall, but I'm not actually
- // sure that this scenario even happens on non-OSX machines.
- events.emit('verbose', 'adb timed out while detecting device/emulator architecture. Killing adb and trying again.');
- return spawn('killall', ['adb'])
- .then(function() {
- return helper()
- .then(null, function() {
- // The double kill is sadly often necessary, at least on mac.
- events.emit('warn', 'adb timed out a second time while detecting device/emulator architecture. Killing adb and trying again.');
- return spawn('killall', ['adb'])
- .then(function() {
- return helper()
- .then(null, function() {
- return Q.reject(new CordovaError('adb timed out a third time while detecting device/emulator architecture. Try unplugging & replugging the device.'));
- });
- });
- });
- }, function() {
- // For non-killall OS's.
- return Q.reject(err);
- });
- }
- throw err;
- });
-};
-
-module.exports.findBestApkForArchitecture = function(buildResults, arch) {
- var paths = buildResults.apkPaths.filter(function(p) {
- var apkName = path.basename(p);
- if (buildResults.buildType == 'debug') {
- return /-debug/.exec(apkName);
- }
- return !/-debug/.exec(apkName);
- });
- var archPattern = new RegExp('-' + arch);
- var hasArchPattern = /-x86|-arm/;
- for (var i = 0; i < paths.length; ++i) {
- var apkName = path.basename(paths[i]);
- if (hasArchPattern.exec(apkName)) {
- if (archPattern.exec(apkName)) {
- return paths[i];
- }
- } else {
- return paths[i];
- }
- }
- throw new Error('Could not find apk architecture: ' + arch + ' build-type: ' + buildResults.buildType);
-};
-
-function PackageInfo(keystore, alias, storePassword, password, keystoreType) {
- this.keystore = {
- 'name': 'key.store',
- 'value': keystore
- };
- this.alias = {
- 'name': 'key.alias',
- 'value': alias
- };
- if (storePassword) {
- this.storePassword = {
- 'name': 'key.store.password',
- 'value': storePassword
- };
- }
- if (password) {
- this.password = {
- 'name': 'key.alias.password',
- 'value': password
- };
- }
- if (keystoreType) {
- this.keystoreType = {
- 'name': 'key.store.type',
- 'value': keystoreType
- };
- }
-}
-
-PackageInfo.prototype = {
- toProperties: function() {
- var self = this;
- var result = '';
- Object.keys(self).forEach(function(key) {
- result += self[key].name;
- result += '=';
- result += self[key].value.replace(/\\/g, '\\\\');
- result += '\n';
- });
- return result;
- }
-};
-
-module.exports.help = function() {
- console.log('Usage: ' + path.relative(process.cwd(), path.join('../build')) + ' [flags] [Signed APK flags]');
- console.log('Flags:');
- console.log(' \'--debug\': will build project in debug mode (default)');
- console.log(' \'--release\': will build project for release');
- console.log(' \'--ant\': will build project with ant');
- console.log(' \'--gradle\': will build project with gradle (default)');
- console.log(' \'--nobuild\': will skip build process (useful when using run command)');
- console.log(' \'--prepenv\': don\'t build, but copy in build scripts where necessary');
- console.log(' \'--versionCode=#\': Override versionCode for this build. Useful for uploading multiple APKs. Requires --gradle.');
- console.log(' \'--minSdkVersion=#\': Override minSdkVersion for this build. Useful for uploading multiple APKs. Requires --gradle.');
- console.log(' \'--gradleArg=<gradle command line arg>\': Extra args to pass to the gradle command. Use one flag per arg. Ex. --gradleArg=-PcdvBuildMultipleApks=true');
- console.log('');
- console.log('Signed APK flags (overwrites debug/release-signing.proprties) :');
- console.log(' \'--keystore=<path to keystore>\': Key store used to build a signed archive. (Required)');
- console.log(' \'--alias=\': Alias for the key store. (Required)');
- console.log(' \'--storePassword=\': Password for the key store. (Optional - prompted)');
- console.log(' \'--password=\': Password for the key. (Optional - prompted)');
- console.log(' \'--keystoreType\': Type of the keystore. (Optional)');
- process.exit(0);
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/builders/AntBuilder.js b/StoneIsland/platforms/android/cordova/lib/builders/AntBuilder.js
deleted file mode 100644
index 4e0f71ab..00000000
--- a/StoneIsland/platforms/android/cordova/lib/builders/AntBuilder.js
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q');
-var fs = require('fs');
-var path = require('path');
-var util = require('util');
-var shell = require('shelljs');
-var spawn = require('cordova-common').superspawn.spawn;
-var CordovaError = require('cordova-common').CordovaError;
-var check_reqs = require('../check_reqs');
-
-var SIGNING_PROPERTIES = '-signing.properties';
-var MARKER = 'YOUR CHANGES WILL BE ERASED!';
-var TEMPLATE =
- '# This file is automatically generated.\n' +
- '# Do not modify this file -- ' + MARKER + '\n';
-
-var GenericBuilder = require('./GenericBuilder');
-
-function AntBuilder (projectRoot) {
- GenericBuilder.call(this, projectRoot);
-
- this.binDirs = {ant: this.binDirs.ant};
-}
-
-util.inherits(AntBuilder, GenericBuilder);
-
-AntBuilder.prototype.getArgs = function(cmd, opts) {
- var args = [cmd, '-f', path.join(this.root, 'build.xml')];
- // custom_rules.xml is required for incremental builds.
- if (hasCustomRules(this.root)) {
- args.push('-Dout.dir=ant-build', '-Dgen.absolute.dir=ant-gen');
- }
- if(opts.packageInfo) {
- args.push('-propertyfile=' + path.join(this.root, opts.buildType + SIGNING_PROPERTIES));
- }
- return args;
-};
-
-AntBuilder.prototype.prepEnv = function(opts) {
- var self = this;
- return check_reqs.check_ant()
- .then(function() {
- // Copy in build.xml on each build so that:
- // A) we don't require the Android SDK at project creation time, and
- // B) we always use the SDK's latest version of it.
- /*jshint -W069 */
- var sdkDir = process.env['ANDROID_HOME'];
- /*jshint +W069 */
- var buildTemplate = fs.readFileSync(path.join(sdkDir, 'tools', 'lib', 'build.template'), 'utf8');
- function writeBuildXml(projectPath) {
- var newData = buildTemplate.replace('PROJECT_NAME', self.extractRealProjectNameFromManifest());
- fs.writeFileSync(path.join(projectPath, 'build.xml'), newData);
- if (!fs.existsSync(path.join(projectPath, 'local.properties'))) {
- fs.writeFileSync(path.join(projectPath, 'local.properties'), TEMPLATE);
- }
- }
- writeBuildXml(self.root);
- var propertiesObj = self.readProjectProperties();
- var subProjects = propertiesObj.libs;
- for (var i = 0; i < subProjects.length; ++i) {
- writeBuildXml(path.join(self.root, subProjects[i]));
- }
- if (propertiesObj.systemLibs.length > 0) {
- throw new CordovaError('Project contains at least one plugin that requires a system library. This is not supported with ANT. Use gradle instead.');
- }
-
- var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
- var propertiesFilePath = path.join(self.root, propertiesFile);
- if (opts.packageInfo) {
- fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
- } else if(isAutoGenerated(propertiesFilePath)) {
- shell.rm('-f', propertiesFilePath);
- }
- });
-};
-
-/*
- * Builds the project with ant.
- * Returns a promise.
- */
-AntBuilder.prototype.build = function(opts) {
- // Without our custom_rules.xml, we need to clean before building.
- var ret = Q();
- if (!hasCustomRules(this.root)) {
- // clean will call check_ant() for us.
- ret = this.clean(opts);
- }
-
- var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts);
- return check_reqs.check_ant()
- .then(function() {
- return spawn('ant', args, {stdio: 'pipe'});
- }).progress(function (stdio){
- if (stdio.stderr) {
- process.stderr.write(stdio.stderr);
- } else {
- process.stdout.write(stdio.stdout);
- }
- }).catch(function (error) {
- if (error.toString().indexOf('Unable to resolve project target') >= 0) {
- return check_reqs.check_android_target(error).then(function() {
- // If due to some odd reason - check_android_target succeeds
- // we should still fail here.
- return Q.reject(error);
- });
- }
- return Q.reject(error);
- });
-};
-
-AntBuilder.prototype.clean = function(opts) {
- var args = this.getArgs('clean', opts);
- var self = this;
- return check_reqs.check_ant()
- .then(function() {
- return spawn('ant', args, {stdio: 'inherit'});
- })
- .then(function () {
- shell.rm('-rf', path.join(self.root, 'out'));
-
- ['debug', 'release'].forEach(function(config) {
- var propertiesFilePath = path.join(self.root, config + SIGNING_PROPERTIES);
- if(isAutoGenerated(propertiesFilePath)){
- shell.rm('-f', propertiesFilePath);
- }
- });
- });
-};
-
-module.exports = AntBuilder;
-
-function hasCustomRules(projectRoot) {
- return fs.existsSync(path.join(projectRoot, 'custom_rules.xml'));
-}
-
-function isAutoGenerated(file) {
- return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/builders/GenericBuilder.js b/StoneIsland/platforms/android/cordova/lib/builders/GenericBuilder.js
deleted file mode 100644
index 362da431..00000000
--- a/StoneIsland/platforms/android/cordova/lib/builders/GenericBuilder.js
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q');
-var fs = require('fs');
-var path = require('path');
-var shell = require('shelljs');
-var events = require('cordova-common').events;
-var CordovaError = require('cordova-common').CordovaError;
-
-function GenericBuilder (projectDir) {
- this.root = projectDir || path.resolve(__dirname, '../../..');
- this.binDirs = {
- ant: path.join(this.root, hasCustomRules(this.root) ? 'ant-build' : 'bin'),
- gradle: path.join(this.root, 'build', 'outputs', 'apk')
- };
-}
-
-function hasCustomRules(projectRoot) {
- return fs.existsSync(path.join(projectRoot, 'custom_rules.xml'));
-}
-
-GenericBuilder.prototype.prepEnv = function() {
- return Q();
-};
-
-GenericBuilder.prototype.build = function() {
- events.emit('log', 'Skipping build...');
- return Q(null);
-};
-
-GenericBuilder.prototype.clean = function() {
- return Q();
-};
-
-GenericBuilder.prototype.findOutputApks = function(build_type, arch) {
- var self = this;
- return Object.keys(this.binDirs)
- .reduce(function (result, builderName) {
- var binDir = self.binDirs[builderName];
- return result.concat(findOutputApksHelper(binDir, build_type, builderName === 'ant' ? null : arch));
- }, [])
- .sort(apkSorter);
-};
-
-GenericBuilder.prototype.readProjectProperties = function () {
- function findAllUniq(data, r) {
- var s = {};
- var m;
- while ((m = r.exec(data))) {
- s[m[1]] = 1;
- }
- return Object.keys(s);
- }
-
- var data = fs.readFileSync(path.join(this.root, 'project.properties'), 'utf8');
- return {
- libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
- gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
- systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg)
- };
-};
-
-GenericBuilder.prototype.extractRealProjectNameFromManifest = function () {
- var manifestPath = path.join(this.root, 'AndroidManifest.xml');
- var manifestData = fs.readFileSync(manifestPath, 'utf8');
- var m = /<manifest[\s\S]*?package\s*=\s*"(.*?)"/i.exec(manifestData);
- if (!m) {
- throw new CordovaError('Could not find package name in ' + manifestPath);
- }
-
- var packageName=m[1];
- var lastDotIndex = packageName.lastIndexOf('.');
- return packageName.substring(lastDotIndex + 1);
-};
-
-module.exports = GenericBuilder;
-
-function apkSorter(fileA, fileB) {
- // De-prioritize unsigned builds
- var unsignedRE = /-unsigned/;
- if (unsignedRE.exec(fileA)) {
- return 1;
- } else if (unsignedRE.exec(fileB)) {
- return -1;
- }
-
- var timeDiff = fs.statSync(fileA).mtime - fs.statSync(fileB).mtime;
- return timeDiff === 0 ? fileA.length - fileB.length : timeDiff;
-}
-
-function findOutputApksHelper(dir, build_type, arch) {
- var shellSilent = shell.config.silent;
- shell.config.silent = true;
-
- var ret = shell.ls(path.join(dir, '*.apk'))
- .filter(function(candidate) {
- var apkName = path.basename(candidate);
- // Need to choose between release and debug .apk.
- if (build_type === 'debug') {
- return /-debug/.exec(apkName) && !/-unaligned|-unsigned/.exec(apkName);
- }
- if (build_type === 'release') {
- return /-release/.exec(apkName) && !/-unaligned/.exec(apkName);
- }
- return true;
- })
- .sort(apkSorter);
-
- shellSilent = shellSilent;
-
- if (ret.length === 0) {
- return ret;
- }
- // Assume arch-specific build if newest apk has -x86 or -arm.
- var archSpecific = !!/-x86|-arm/.exec(path.basename(ret[0]));
- // And show only arch-specific ones (or non-arch-specific)
- ret = ret.filter(function(p) {
- /*jshint -W018 */
- return !!/-x86|-arm/.exec(path.basename(p)) == archSpecific;
- /*jshint +W018 */
- });
-
- if (archSpecific && ret.length > 1 && arch) {
- ret = ret.filter(function(p) {
- return path.basename(p).indexOf('-' + arch) != -1;
- });
- }
-
- return ret;
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/builders/GradleBuilder.js b/StoneIsland/platforms/android/cordova/lib/builders/GradleBuilder.js
deleted file mode 100644
index 5b5ce13d..00000000
--- a/StoneIsland/platforms/android/cordova/lib/builders/GradleBuilder.js
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q');
-var fs = require('fs');
-var util = require('util');
-var path = require('path');
-var shell = require('shelljs');
-var spawn = require('cordova-common').superspawn.spawn;
-var CordovaError = require('cordova-common').CordovaError;
-var check_reqs = require('../check_reqs');
-
-var GenericBuilder = require('./GenericBuilder');
-
-var MARKER = 'YOUR CHANGES WILL BE ERASED!';
-var SIGNING_PROPERTIES = '-signing.properties';
-var TEMPLATE =
- '# This file is automatically generated.\n' +
- '# Do not modify this file -- ' + MARKER + '\n';
-
-function GradleBuilder (projectRoot) {
- GenericBuilder.call(this, projectRoot);
-
- this.binDirs = {gradle: this.binDirs.gradle};
-}
-
-util.inherits(GradleBuilder, GenericBuilder);
-
-GradleBuilder.prototype.getArgs = function(cmd, opts) {
- if (cmd == 'release') {
- cmd = 'cdvBuildRelease';
- } else if (cmd == 'debug') {
- cmd = 'cdvBuildDebug';
- }
- var args = [cmd, '-b', path.join(this.root, 'build.gradle')];
- if (opts.arch) {
- args.push('-PcdvBuildArch=' + opts.arch);
- }
-
- // 10 seconds -> 6 seconds
- args.push('-Dorg.gradle.daemon=true');
- // to allow dex in process
- args.push('-Dorg.gradle.jvmargs=-Xmx2048m');
- // allow NDK to be used - required by Gradle 1.5 plugin
- args.push('-Pandroid.useDeprecatedNdk=true');
- args.push.apply(args, opts.extraArgs);
- // Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
- // args.push('-Dorg.gradle.parallel=true');
- return args;
-};
-
-/*
- * This returns a promise
- */
-
-GradleBuilder.prototype.runGradleWrapper = function(gradle_cmd) {
- var gradlePath = path.join(this.root, 'gradlew');
- var wrapperGradle = path.join(this.root, 'wrapper.gradle');
- if(fs.existsSync(gradlePath)) {
- //Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
- } else {
- return spawn(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], {stdio: 'inherit'});
- }
-};
-
-
-// Makes the project buildable, minus the gradle wrapper.
-GradleBuilder.prototype.prepBuildFiles = function() {
- // Update the version of build.gradle in each dependent library.
- var pluginBuildGradle = path.join(this.root, 'cordova', 'lib', 'plugin-build.gradle');
- var propertiesObj = this.readProjectProperties();
- var subProjects = propertiesObj.libs;
- var checkAndCopy = function(subProject, root) {
- var subProjectGradle = path.join(root, subProject, 'build.gradle');
- // This is the future-proof way of checking if a file exists
- // This must be synchronous to satisfy a Travis test
- try {
- fs.accessSync(subProjectGradle, fs.F_OK);
- } catch (e) {
- shell.cp('-f', pluginBuildGradle, subProjectGradle);
- }
- };
- for (var i = 0; i < subProjects.length; ++i) {
- if (subProjects[i] !== 'CordovaLib') {
- checkAndCopy(subProjects[i], this.root);
- }
- }
- var name = this.extractRealProjectNameFromManifest();
- //Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
- var settingsGradlePaths = subProjects.map(function(p){
- var realDir=p.replace(/[/\\]/g, ':');
- var libName=realDir.replace(name+'-','');
- var str='include ":'+libName+'"\n';
- if(realDir.indexOf(name+'-')!==-1)
- str+='project(":'+libName+'").projectDir = new File("'+p+'")\n';
- return str;
- });
-
- // Write the settings.gradle file.
- fs.writeFileSync(path.join(this.root, 'settings.gradle'),
- '// GENERATED FILE - DO NOT EDIT\n' +
- 'include ":"\n' + settingsGradlePaths.join(''));
- // Update dependencies within build.gradle.
- var buildGradle = fs.readFileSync(path.join(this.root, 'build.gradle'), 'utf8');
- var depsList = '';
- var root = this.root;
- var insertExclude = function(p) {
- var gradlePath = path.join(root, p, 'build.gradle');
- var projectGradleFile = fs.readFileSync(gradlePath, 'utf-8');
- if(projectGradleFile.indexOf('CordovaLib') != -1) {
- depsList += '{\n exclude module:("CordovaLib")\n }\n';
- }
- else {
- depsList +='\n';
- }
- };
- subProjects.forEach(function(p) {
- console.log('Subproject Path: ' + p);
- var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
- depsList += ' debugCompile(project(path: "' + libName + '", configuration: "debug"))';
- insertExclude(p);
- depsList += ' releaseCompile(project(path: "' + libName + '", configuration: "release"))';
- insertExclude(p);
- });
- // For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
- var SYSTEM_LIBRARY_MAPPINGS = [
- [/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
- [/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']
- ];
- propertiesObj.systemLibs.forEach(function(p) {
- var mavenRef;
- // It's already in gradle form if it has two ':'s
- if (/:.*:/.exec(p)) {
- mavenRef = p;
- } else {
- for (var i = 0; i < SYSTEM_LIBRARY_MAPPINGS.length; ++i) {
- var pair = SYSTEM_LIBRARY_MAPPINGS[i];
- if (pair[0].exec(p)) {
- mavenRef = p.replace(pair[0], pair[1]);
- break;
- }
- }
- if (!mavenRef) {
- throw new CordovaError('Unsupported system library (does not work with gradle): ' + p);
- }
- }
- depsList += ' compile "' + mavenRef + '"\n';
- });
- buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + ' $2');
- var includeList = '';
- propertiesObj.gradleIncludes.forEach(function(includePath) {
- includeList += 'apply from: "' + includePath + '"\n';
- });
- 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);
-};
-
-GradleBuilder.prototype.prepEnv = function(opts) {
- var self = this;
- return check_reqs.check_gradle()
- .then(function(gradlePath) {
- return self.runGradleWrapper(gradlePath);
- }).then(function() {
- return self.prepBuildFiles();
- }).then(function() {
- // We now copy the gradle out of the framework
- // This is a dirty patch to get the build working
- /*
- var wrapperDir = path.join(self.root, 'CordovaLib');
- if (process.platform == 'win32') {
- shell.rm('-f', path.join(self.root, 'gradlew.bat'));
- shell.cp(path.join(wrapperDir, 'gradlew.bat'), self.root);
- } else {
- shell.rm('-f', path.join(self.root, 'gradlew'));
- shell.cp(path.join(wrapperDir, 'gradlew'), self.root);
- }
- shell.rm('-rf', path.join(self.root, 'gradle', 'wrapper'));
- shell.mkdir('-p', path.join(self.root, 'gradle'));
- shell.cp('-r', path.join(wrapperDir, 'gradle', 'wrapper'), path.join(self.root, 'gradle'));
-*/
- // 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.
- // For some reason, using ^ and $ don't work. This does the job, though.
- 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';
- /*jshint +W069 */
- var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
- shell.chmod('u+w', gradleWrapperPropertiesPath);
- shell.sed('-i', distributionUrlRegex, 'distributionUrl='+distributionUrl, gradleWrapperPropertiesPath);
-
- var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
- var propertiesFilePath = path.join(self.root, propertiesFile);
- if (opts.packageInfo) {
- fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
- } else if (isAutoGenerated(propertiesFilePath)) {
- shell.rm('-f', propertiesFilePath);
- }
- });
-};
-
-/*
- * Builds the project with gradle.
- * Returns a promise.
- */
-GradleBuilder.prototype.build = function(opts) {
- var wrapper = path.join(this.root, 'gradlew');
- var args = this.getArgs(opts.buildType == 'debug' ? 'debug' : 'release', opts);
-
- return spawn(wrapper, args, {stdio: 'pipe'})
- .progress(function (stdio){
- if (stdio.stderr) {
- /*
- * Workaround for the issue with Java printing some unwanted information to
- * stderr instead of stdout.
- * This function suppresses 'Picked up _JAVA_OPTIONS' message from being
- * printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
- * explanation.
- */
- var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
- if (suppressThisLine) {
- return;
- }
- process.stderr.write(stdio.stderr);
- } else {
- process.stdout.write(stdio.stdout);
- }
- }).catch(function (error) {
- if (error.toString().indexOf('failed to find target with hash string') >= 0) {
- return check_reqs.check_android_target(error).then(function() {
- // If due to some odd reason - check_android_target succeeds
- // we should still fail here.
- return Q.reject(error);
- });
- }
- return Q.reject(error);
- });
-};
-
-GradleBuilder.prototype.clean = function(opts) {
- var builder = this;
- var wrapper = path.join(this.root, 'gradlew');
- var args = builder.getArgs('clean', opts);
- return Q().then(function() {
- return spawn(wrapper, args, {stdio: 'inherit'});
- })
- .then(function () {
- shell.rm('-rf', path.join(builder.root, 'out'));
-
- ['debug', 'release'].forEach(function(config) {
- var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
- if(isAutoGenerated(propertiesFilePath)){
- shell.rm('-f', propertiesFilePath);
- }
- });
- });
-};
-
-module.exports = GradleBuilder;
-
-function isAutoGenerated(file) {
- return fs.existsSync(file) && fs.readFileSync(file, 'utf8').indexOf(MARKER) > 0;
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/builders/builders.js b/StoneIsland/platforms/android/cordova/lib/builders/builders.js
deleted file mode 100644
index 4921c49a..00000000
--- a/StoneIsland/platforms/android/cordova/lib/builders/builders.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var CordovaError = require('cordova-common').CordovaError;
-
-var knownBuilders = {
- ant: 'AntBuilder',
- gradle: 'GradleBuilder',
- none: 'GenericBuilder'
-};
-
-/**
- * Helper method that instantiates and returns a builder for specified build
- * type.
- *
- * @param {String} builderType Builder name to construct and return. Must
- * be one of 'ant', 'gradle' or 'none'
- *
- * @return {Builder} A builder instance for specified build type.
- */
-module.exports.getBuilder = function (builderType, projectRoot) {
- if (!knownBuilders[builderType])
- throw new CordovaError('Builder ' + builderType + ' is not supported.');
-
- try {
- var Builder = require('./' + knownBuilders[builderType]);
- return new Builder(projectRoot);
- } catch (err) {
- throw new CordovaError('Failed to instantiate ' + knownBuilders[builderType] + ' builder: ' + err);
- }
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/check_reqs.js b/StoneIsland/platforms/android/cordova/lib/check_reqs.js
deleted file mode 100644
index 1fd397ad..00000000
--- a/StoneIsland/platforms/android/cordova/lib/check_reqs.js
+++ /dev/null
@@ -1,432 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/* jshint sub:true */
-
-var shelljs = require('shelljs'),
- child_process = require('child_process'),
- Q = require('q'),
- path = require('path'),
- fs = require('fs'),
- os = require('os'),
- REPO_ROOT = path.join(__dirname, '..', '..', '..', '..'),
- PROJECT_ROOT = path.join(__dirname, '..', '..');
-var CordovaError = require('cordova-common').CordovaError;
-var superspawn = require('cordova-common').superspawn;
-var android_sdk = require('./android_sdk');
-
-function forgivingWhichSync(cmd) {
- try {
- return fs.realpathSync(shelljs.which(cmd));
- } catch (e) {
- return '';
- }
-}
-
-function tryCommand(cmd, errMsg, catchStderr) {
- var d = Q.defer();
- child_process.exec(cmd, function(err, stdout, stderr) {
- if (err) d.reject(new CordovaError(errMsg));
- // Sometimes it is necessary to return an stderr instead of stdout in case of success, since
- // some commands prints theirs output to stderr instead of stdout. 'javac' is the example
- else d.resolve((catchStderr ? stderr : stdout).trim());
- });
- return d.promise;
-}
-
-module.exports.isWindows = function() {
- return (os.platform() == 'win32');
-};
-
-module.exports.isDarwin = function() {
- return (os.platform() == 'darwin');
-};
-
-// Get valid target from framework/project.properties if run from this repo
-// Otherwise get target from project.properties file within a generated cordova-android project
-module.exports.get_target = function() {
- function extractFromFile(filePath) {
- var target = shelljs.grep(/\btarget=/, filePath);
- if (!target) {
- throw new Error('Could not find android target within: ' + filePath);
- }
- return target.split('=')[1].trim();
- }
- var repo_file = path.join(REPO_ROOT, 'framework', 'project.properties');
- if (fs.existsSync(repo_file)) {
- return extractFromFile(repo_file);
- }
- var project_file = path.join(PROJECT_ROOT, 'project.properties');
- if (fs.existsSync(project_file)) {
- // if no target found, we're probably in a project and project.properties is in PROJECT_ROOT.
- return extractFromFile(project_file);
- }
- throw new Error('Could not find android target in either ' + repo_file + ' nor ' + project_file);
-};
-
-// Returns a promise. Called only by build and clean commands.
-module.exports.check_ant = function() {
- return superspawn.spawn('ant', ['-version'])
- .then(function(output) {
- // Parse Ant version from command output
- return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
- }).catch(function(err) {
- throw new CordovaError('Failed to run `ant -version`. Make sure you have `ant` on your $PATH.');
- });
-};
-
-module.exports.get_gradle_wrapper = function() {
- var androidStudioPath;
- var i = 0;
- var foundStudio = false;
- var program_dir;
- if (module.exports.isDarwin()) {
- program_dir = fs.readdirSync('/Applications');
- while (i < program_dir.length && !foundStudio) {
- if (program_dir[i].startsWith('Android Studio')) {
- //TODO: Check for a specific Android Studio version, make sure it's not Canary
- androidStudioPath = path.join('/Applications', program_dir[i], 'Contents', 'gradle');
- foundStudio = true;
- } else { ++i; }
- }
- } else if (module.exports.isWindows()) {
- var androidPath = path.join(process.env['ProgramFiles'], 'Android') + '/';
- if (fs.existsSync(androidPath)) {
- program_dir = fs.readdirSync(androidPath);
- while (i < program_dir.length && !foundStudio) {
- if (program_dir[i].startsWith('Android Studio')) {
- foundStudio = true;
- androidStudioPath = path.join(process.env['ProgramFiles'], 'Android', program_dir[i], 'gradle');
- } else { ++i; }
- }
- }
- }
-
- if (androidStudioPath !== null && fs.existsSync(androidStudioPath)) {
- var dirs = fs.readdirSync(androidStudioPath);
- if(dirs[0].split('-')[0] == 'gradle') {
- return path.join(androidStudioPath, dirs[0], 'bin', 'gradle');
- }
- } else {
- //OK, let's try to check for Gradle!
- return forgivingWhichSync('gradle');
- }
-};
-
-// Returns a promise. Called only by build and clean commands.
-module.exports.check_gradle = function() {
- var sdkDir = process.env['ANDROID_HOME'];
- var d = Q.defer();
- if (!sdkDir)
- return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' +
- 'Might need to install Android SDK or set up \'ANDROID_HOME\' env variable.'));
-
- var gradlePath = module.exports.get_gradle_wrapper();
- if (gradlePath.length !== 0)
- d.resolve(gradlePath);
- else
- d.reject(new CordovaError('Could not find an installed version of Gradle either in Android Studio,\n' +
- 'or on your system to install the gradle wrapper. Please include gradle \n' +
- 'in your path, or install Android Studio'));
- return d.promise;
-};
-
-// Returns a promise.
-module.exports.check_java = function() {
- var javacPath = forgivingWhichSync('javac');
- var hasJavaHome = !!process.env['JAVA_HOME'];
- return Q().then(function() {
- if (hasJavaHome) {
- // Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
- if (!javacPath) {
- process.env['PATH'] += path.delimiter + path.join(process.env['JAVA_HOME'], 'bin');
- }
- } else {
- if (javacPath) {
- // OS X has a command for finding JAVA_HOME.
- var find_java = '/usr/libexec/java_home';
- var default_java_error_msg = 'Failed to find \'JAVA_HOME\' environment variable. Try setting setting it manually.';
- if (fs.existsSync(find_java)) {
- return superspawn.spawn(find_java)
- .then(function(stdout) {
- process.env['JAVA_HOME'] = stdout.trim();
- }).catch(function(err) {
- throw new CordovaError(default_java_error_msg);
- });
- } else {
- // See if we can derive it from javac's location.
- // fs.realpathSync is require on Ubuntu, which symplinks from /usr/bin -> JDK
- var maybeJavaHome = path.dirname(path.dirname(javacPath));
- if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {
- process.env['JAVA_HOME'] = maybeJavaHome;
- } else {
- throw new CordovaError(default_java_error_msg);
- }
- }
- } else if (module.exports.isWindows()) {
- // Try to auto-detect java in the default install paths.
- var oldSilent = shelljs.config.silent;
- shelljs.config.silent = true;
- var firstJdkDir =
- shelljs.ls(process.env['ProgramFiles'] + '\\java\\jdk*')[0] ||
- shelljs.ls('C:\\Program Files\\java\\jdk*')[0] ||
- shelljs.ls('C:\\Program Files (x86)\\java\\jdk*')[0];
- shelljs.config.silent = oldSilent;
- if (firstJdkDir) {
- // shelljs always uses / in paths.
- firstJdkDir = firstJdkDir.replace(/\//g, path.sep);
- if (!javacPath) {
- process.env['PATH'] += path.delimiter + path.join(firstJdkDir, 'bin');
- }
- process.env['JAVA_HOME'] = firstJdkDir;
- }
- }
- }
- }).then(function() {
- var msg =
- 'Failed to run "javac -version", make sure that you have a JDK installed.\n' +
- 'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n';
- if (process.env['JAVA_HOME']) {
- msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n';
- }
- // We use tryCommand with catchStderr = true, because
- // javac writes version info to stderr instead of stdout
- return tryCommand('javac -version', msg, true)
- .then(function (output) {
- //Let's check for at least Java 8, and keep it future proof so we can support Java 10
- var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output);
- return match && match[1];
- });
- });
-};
-
-// Returns a promise.
-module.exports.check_android = function() {
- return Q().then(function() {
- var androidCmdPath = forgivingWhichSync('android');
- var adbInPath = forgivingWhichSync('adb');
- var avdmanagerInPath = forgivingWhichSync('avdmanager');
- var hasAndroidHome = !!process.env['ANDROID_HOME'] && fs.existsSync(process.env['ANDROID_HOME']);
- function maybeSetAndroidHome(value) {
- if (!hasAndroidHome && fs.existsSync(value)) {
- hasAndroidHome = true;
- process.env['ANDROID_HOME'] = value;
- }
- }
- // First ensure ANDROID_HOME is set
- // If we have no hints (nothing in PATH), try a few default locations
- if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath) {
- if (module.exports.isWindows()) {
- // Android Studio 1.0 installer
- maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'sdk'));
- maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'sdk'));
- // Android Studio pre-1.0 installer
- maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-studio', 'sdk'));
- maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-studio', 'sdk'));
- // Stand-alone installer
- maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-sdk'));
- maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-sdk'));
- } else if (module.exports.isDarwin()) {
- // Android Studio 1.0 installer
- maybeSetAndroidHome(path.join(process.env['HOME'], 'Library', 'Android', 'sdk'));
- // Android Studio pre-1.0 installer
- maybeSetAndroidHome('/Applications/Android Studio.app/sdk');
- // Stand-alone zip file that user might think to put under /Applications
- maybeSetAndroidHome('/Applications/android-sdk-macosx');
- maybeSetAndroidHome('/Applications/android-sdk');
- }
- if (process.env['HOME']) {
- // Stand-alone zip file that user might think to put under their home directory
- maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk-macosx'));
- maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk'));
- }
- }
- if (!hasAndroidHome) {
- // If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to infer from the tooling PATH.
- var parentDir, grandParentDir;
- if (androidCmdPath) {
- parentDir = path.dirname(androidCmdPath);
- grandParentDir = path.dirname(parentDir);
- if (path.basename(parentDir) == 'tools' || fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
- maybeSetAndroidHome(grandParentDir);
- } else {
- throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' +
- 'Detected \'android\' command at ' + parentDir + ' but no \'tools\' directory found near.\n' +
- 'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools directory.');
- }
- }
- if (adbInPath) {
- parentDir = path.dirname(adbInPath);
- grandParentDir = path.dirname(parentDir);
- if (path.basename(parentDir) == 'platform-tools') {
- maybeSetAndroidHome(grandParentDir);
- } else {
- throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' +
- 'Detected \'adb\' command at ' + parentDir + ' but no \'platform-tools\' directory found near.\n' +
- 'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'platform-tools directory.');
- }
- }
- if (avdmanagerInPath) {
- parentDir = path.dirname(avdmanagerInPath);
- grandParentDir = path.dirname(parentDir);
- if (path.basename(parentDir) == 'bin' && path.basename(grandParentDir) == 'tools') {
- maybeSetAndroidHome(path.dirname(grandParentDir));
- } else {
- throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' +
- 'Detected \'avdmanager\' command at ' + parentDir + ' but no \'tools' + path.sep + 'bin\' directory found near.\n' +
- 'Try reinstall Android SDK or update your PATH to include valid path to SDK' + path.sep + 'tools' + path.sep + 'bin directory.');
- }
- }
- }
- if (!process.env['ANDROID_HOME']) {
- throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' +
- 'Failed to find \'android\' command in your \'PATH\'. Try update your \'PATH\' to include path to valid SDK directory.');
- }
- if (!fs.existsSync(process.env['ANDROID_HOME'])) {
- throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent path: ' + process.env['ANDROID_HOME'] +
- '\nTry update it manually to point to valid SDK directory.');
- }
- // Next let's make sure relevant parts of the SDK tooling is in our PATH
- if (hasAndroidHome && !androidCmdPath) {
- process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools');
- }
- if (hasAndroidHome && !adbInPath) {
- process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'platform-tools');
- }
- if (hasAndroidHome && !avdmanagerInPath) {
- process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools', 'bin');
- }
- return hasAndroidHome;
- });
-};
-
-// TODO: is this actually needed?
-module.exports.getAbsoluteAndroidCmd = function () {
- var cmd = forgivingWhichSync('android');
- if (cmd.length === 0) {
- cmd = forgivingWhichSync('sdkmanager');
- }
- if (module.exports.isWindows()) {
- return '"' + cmd + '"';
- }
- return cmd.replace(/(\s)/g, '\\$1');
-};
-
-module.exports.check_android_target = function(originalError) {
- // valid_target can look like:
- // android-19
- // android-L
- // Google Inc.:Google APIs:20
- // Google Inc.:Glass Development Kit Preview:20
- var desired_api_level = module.exports.get_target();
- return android_sdk.list_targets()
- .then(function(targets) {
- if (targets.indexOf(desired_api_level) >= 0) {
- return targets;
- }
- var androidCmd = module.exports.getAbsoluteAndroidCmd();
- var msg = 'Please install Android target / API level: "' + desired_api_level + '".\n\n' +
- 'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
- 'You will require:\n' +
- '1. "SDK Platform" for API level ' + desired_api_level + '\n' +
- '2. "Android SDK Platform-tools (latest)\n' +
- '3. "Android SDK Build-tools" (latest)';
- if (originalError) {
- msg = originalError + '\n' + msg;
- }
- throw new CordovaError(msg);
- });
-};
-
-// Returns a promise.
-module.exports.run = function() {
- return Q.all([this.check_java(), this.check_android()])
- .then(function(values) {
- console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']);
- console.log('JAVA_HOME=' + process.env['JAVA_HOME']);
-
- if (!values[0]) {
- throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
- }
-
- if (!values[1]) {
- throw new CordovaError('Requirements check failed for Android SDK');
- }
- });
-};
-
-
-/**
- * Object thar represents one of requirements for current platform.
- * @param {String} id The unique identifier for this requirements.
- * @param {String} name The name of requirements. Human-readable field.
- * @param {String} version The version of requirement installed. In some cases could be an array of strings
- * (for example, check_android_target returns an array of android targets installed)
- * @param {Boolean} installed Indicates whether the requirement is installed or not
- */
-var Requirement = function (id, name, version, installed) {
- this.id = id;
- this.name = name;
- this.installed = installed || false;
- this.metadata = {
- version: version,
- };
-};
-
-/**
- * Methods that runs all checks one by one and returns a result of checks
- * as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs method
- *
- * @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
- */
-module.exports.check_all = function() {
-
- var requirements = [
- new Requirement('java', 'Java JDK'),
- new Requirement('androidSdk', 'Android SDK'),
- new Requirement('androidTarget', 'Android target'),
- new Requirement('gradle', 'Gradle')
- ];
-
- var checkFns = [
- this.check_java,
- this.check_android,
- this.check_android_target,
- this.check_gradle
- ];
-
- // Then execute requirement checks one-by-one
- return checkFns.reduce(function (promise, checkFn, idx) {
- // Update each requirement with results
- var requirement = requirements[idx];
- return promise.then(checkFn)
- .then(function (version) {
- requirement.installed = true;
- requirement.metadata.version = version;
- }, function (err) {
- requirement.metadata.reason = err instanceof Error ? err.message : err;
- });
- }, Q())
- .then(function () {
- // When chain is completed, return requirements array to upstream API
- return requirements;
- });
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/device.js b/StoneIsland/platforms/android/cordova/lib/device.js
deleted file mode 100644
index 4b171db6..00000000
--- a/StoneIsland/platforms/android/cordova/lib/device.js
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q'),
- build = require('./build');
-var path = require('path');
-var Adb = require('./Adb');
-var AndroidManifest = require('./AndroidManifest');
-var spawn = require('cordova-common').superspawn.spawn;
-var CordovaError = require('cordova-common').CordovaError;
-var events = require('cordova-common').events;
-
-/**
- * Returns a promise for the list of the device ID's found
- * @param lookHarder When true, try restarting adb if no devices are found.
- */
-module.exports.list = function(lookHarder) {
- return Adb.devices()
- .then(function(list) {
- if (list.length === 0 && lookHarder) {
- // adb kill-server doesn't seem to do the trick.
- // Could probably find a x-platform version of killall, but I'm not actually
- // sure that this scenario even happens on non-OSX machines.
- return spawn('killall', ['adb'])
- .then(function() {
- events.emit('verbose', 'Restarting adb to see if more devices are detected.');
- return Adb.devices();
- }, function() {
- // For non-killall OS's.
- return list;
- });
- }
- return list;
- });
-};
-
-module.exports.resolveTarget = function(target) {
- return this.list(true)
- .then(function(device_list) {
- if (!device_list || !device_list.length) {
- return Q.reject(new CordovaError('Failed to deploy to device, no devices found.'));
- }
- // default device
- target = target || device_list[0];
-
- if (device_list.indexOf(target) < 0) {
- return Q.reject('ERROR: Unable to find target \'' + target + '\'.');
- }
-
- return build.detectArchitecture(target)
- .then(function(arch) {
- return { target: target, arch: arch, isEmulator: false };
- });
- });
-};
-
-/*
- * Installs a previously built application on the device
- * and launches it.
- * Returns a promise.
- */
-module.exports.install = function(target, buildResults) {
- return Q().then(function() {
- if (target && typeof target == 'object') {
- return target;
- }
- return module.exports.resolveTarget(target);
- }).then(function(resolvedTarget) {
- var apk_path = build.findBestApkForArchitecture(buildResults, resolvedTarget.arch);
- var manifest = new AndroidManifest(path.join(__dirname, '../../AndroidManifest.xml'));
- var pkgName = manifest.getPackageId();
- var launchName = pkgName + '/.' + manifest.getActivity().getName();
- events.emit('log', 'Using apk: ' + apk_path);
- events.emit('log', 'Package name: ' + pkgName);
-
- return Adb.install(resolvedTarget.target, apk_path, {replace: true})
- .catch(function (error) {
- // CB-9557 CB-10157 only uninstall and reinstall app if the one that
- // is already installed on device was signed w/different certificate
- if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString()))
- throw error;
-
- events.emit('warn', 'Uninstalling app from device and reinstalling it again because the ' +
- 'installed app already signed with different key');
-
- // This promise is always resolved, even if 'adb uninstall' fails to uninstall app
- // or the app doesn't installed at all, so no error catching needed.
- return Adb.uninstall(resolvedTarget.target, pkgName)
- .then(function() {
- return Adb.install(resolvedTarget.target, apk_path, {replace: true});
- });
- })
- .then(function() {
- //unlock screen
- return Adb.shell(resolvedTarget.target, 'input keyevent 82');
- }).then(function() {
- return Adb.start(resolvedTarget.target, launchName);
- }).then(function() {
- events.emit('log', 'LAUNCH SUCCESS');
- });
- });
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/emulator.js b/StoneIsland/platforms/android/cordova/lib/emulator.js
deleted file mode 100644
index 22209aa0..00000000
--- a/StoneIsland/platforms/android/cordova/lib/emulator.js
+++ /dev/null
@@ -1,532 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/* jshint sub:true */
-
-var retry = require('./retry');
-var build = require('./build');
-var path = require('path');
-var Adb = require('./Adb');
-var AndroidManifest = require('./AndroidManifest');
-var events = require('cordova-common').events;
-var superspawn = require('cordova-common').superspawn;
-var CordovaError = require('cordova-common').CordovaError;
-var shelljs = require('shelljs');
-var android_sdk = require('./android_sdk');
-var check_reqs = require('./check_reqs');
-
-var Q = require('q');
-var os = require('os');
-var fs = require('fs');
-var child_process = require('child_process');
-
-// constants
-var ONE_SECOND = 1000; // in milliseconds
-var ONE_MINUTE = 60 * ONE_SECOND; // in milliseconds
-var INSTALL_COMMAND_TIMEOUT = 5 * ONE_MINUTE; // in milliseconds
-var NUM_INSTALL_RETRIES = 3;
-var CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds
-var EXEC_KILL_SIGNAL = 'SIGKILL';
-
-function forgivingWhichSync(cmd) {
- try {
- return fs.realpathSync(shelljs.which(cmd));
- } catch (e) {
- return '';
- }
-}
-
-module.exports.list_images_using_avdmanager = function () {
- return superspawn.spawn('avdmanager', ['list', 'avd'])
- .then(function(output) {
- var response = output.split('\n');
- var emulator_list = [];
- for (var i = 1; i < response.length; i++) {
- // To return more detailed information use img_obj
- var img_obj = {};
- if (response[i].match(/Name:\s/)) {
- img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
- if (response[i + 1].match(/Device:\s/)) {
- i++;
- img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/Path:\s/)) {
- i++;
- img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/Target:\s/)) {
- i++;
- if (response[i + 1].match(/ABI:\s/)) {
- img_obj['abi'] = response[i + 1].split('ABI: ')[1].replace('\r', '');
- }
- // This next conditional just aims to match the old output of `android list avd`
- // We do so so that we don't have to change the logic when parsing for the
- // best emulator target to spawn (see below in `best_image`)
- // This allows us to transitionally support both `android` and `avdmanager` binaries,
- // depending on what SDK version the user has
- if (response[i + 1].match(/Based\son:\s/)) {
- img_obj['target'] = response[i + 1].split('Based on:')[1];
- if (img_obj['target'].match(/Tag\/ABI:\s/)) {
- img_obj['target'] = img_obj['target'].split('Tag/ABI:')[0].replace('\r', '').trim();
- if (img_obj['target'].indexOf('(') > -1) {
- img_obj['target'] = img_obj['target'].substr(0, img_obj['target'].indexOf('(') - 1).trim();
- }
- }
- var version_string = img_obj['target'].replace(/Android\s+/, '');
-
- var api_level = android_sdk.version_string_to_api_level[version_string];
- if (api_level) {
- img_obj['target'] += ' (API level ' + api_level + ')';
- }
- }
- }
- if (response[i + 1].match(/Skin:\s/)) {
- i++;
- img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
- }
-
- emulator_list.push(img_obj);
- }
- /* To just return a list of names use this
- if (response[i].match(/Name:\s/)) {
- emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
- }*/
-
- }
- return emulator_list;
- });
-};
-
-module.exports.list_images_using_android = function() {
- return superspawn.spawn('android', ['list', 'avd'])
- .then(function(output) {
- var response = output.split('\n');
- var emulator_list = [];
- for (var i = 1; i < response.length; i++) {
- // To return more detailed information use img_obj
- var img_obj = {};
- if (response[i].match(/Name:\s/)) {
- img_obj['name'] = response[i].split('Name: ')[1].replace('\r', '');
- if (response[i + 1].match(/Device:\s/)) {
- i++;
- img_obj['device'] = response[i].split('Device: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/Path:\s/)) {
- i++;
- img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/\(API\slevel\s/) || (response[i + 2] && response[i + 2].match(/\(API\slevel\s/))) {
- i++;
- var secondLine = response[i + 1].match(/\(API\slevel\s/) ? response[i + 1] : '';
- img_obj['target'] = (response[i] + secondLine).split('Target: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/ABI:\s/)) {
- i++;
- img_obj['abi'] = response[i].split('ABI: ')[1].replace('\r', '');
- }
- if (response[i + 1].match(/Skin:\s/)) {
- i++;
- img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', '');
- }
-
- emulator_list.push(img_obj);
- }
- /* To just return a list of names use this
- if (response[i].match(/Name:\s/)) {
- emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
- }*/
-
- }
- return emulator_list;
- });
-};
-
-/**
- * Returns a Promise for a list of emulator images in the form of objects
- * {
- name : <emulator_name>,
- device : <device>,
- path : <path_to_emulator_image>,
- target : <api_target>,
- abi : <cpu>,
- skin : <skin>
- }
- */
-module.exports.list_images = function() {
- if (forgivingWhichSync('avdmanager')) {
- return module.exports.list_images_using_avdmanager();
- } else if (forgivingWhichSync('android')) {
- return module.exports.list_images_using_android();
- } else {
- return Q().then(function() {
- throw new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?');
- });
- }
-};
-
-/**
- * Will return the closest avd to the projects target
- * or undefined if no avds exist.
- * Returns a promise.
- */
-module.exports.best_image = function() {
- return this.list_images()
- .then(function(images) {
- // Just return undefined if there is no images
- if (images.length === 0) return;
-
- var closest = 9999;
- var best = images[0];
- var project_target = check_reqs.get_target().replace('android-', '');
- for (var i in images) {
- var target = images[i].target;
- if(target) {
- var num = target.split('(API level ')[1].replace(')', '');
- if (num == project_target) {
- return images[i];
- } else if (project_target - num < closest && project_target > num) {
- closest = project_target - num;
- best = images[i];
- }
- }
- }
- return best;
- });
-};
-
-// Returns a promise.
-module.exports.list_started = function() {
- return Adb.devices({emulators: true});
-};
-
-// Returns a promise.
-// TODO: we should remove this, there's a more robust method under android_sdk.js
-module.exports.list_targets = function() {
- return superspawn.spawn('android', ['list', 'targets'], {cwd: os.tmpdir()})
- .then(function(output) {
- var target_out = output.split('\n');
- var targets = [];
- for (var i = target_out.length; i >= 0; i--) {
- if(target_out[i].match(/id:/)) {
- targets.push(targets[i].split(' ')[1]);
- }
- }
- return targets;
- });
-};
-
-/*
- * Gets unused port for android emulator, between 5554 and 5584
- * Returns a promise.
- */
-module.exports.get_available_port = function () {
- var self = this;
-
- return self.list_started()
- .then(function (emulators) {
- for (var p = 5584; p >= 5554; p-=2) {
- if (emulators.indexOf('emulator-' + p) === -1) {
- events.emit('verbose', 'Found available port: ' + p);
- return p;
- }
- }
- throw new CordovaError('Could not find an available avd port');
- });
-};
-
-/*
- * Starts an emulator with the given ID,
- * and returns the started ID of that emulator.
- * If no ID is given it will use the first image available,
- * if no image is available it will error out (maybe create one?).
- * If no boot timeout is given or the value is negative it will wait forever for
- * the emulator to boot
- *
- * Returns a promise.
- */
-module.exports.start = function(emulator_ID, boot_timeout) {
- var self = this;
-
- return Q().then(function() {
- if (emulator_ID) return Q(emulator_ID);
-
- return self.best_image()
- .then(function(best) {
- if (best && best.name) {
- events.emit('warn', 'No emulator specified, defaulting to ' + best.name);
- return best.name;
- }
-
- var androidCmd = check_reqs.getAbsoluteAndroidCmd();
- return Q.reject(new CordovaError('No emulator images (avds) found.\n' +
- '1. Download desired System Image by running: ' + androidCmd + ' sdk\n' +
- '2. Create an AVD by running: ' + androidCmd + ' avd\n' +
- 'HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver\n'));
- });
- }).then(function(emulatorId) {
- return self.get_available_port()
- .then(function (port) {
- // Figure out the directory the emulator binary runs in, and set the cwd to that directory.
- // Workaround for https://code.google.com/p/android/issues/detail?id=235461
- var emulator_dir = path.dirname(shelljs.which('emulator'));
- var args = ['-avd', emulatorId, '-port', port];
- // Don't wait for it to finish, since the emulator will probably keep running for a long time.
- child_process
- .spawn('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
- .unref();
-
- // wait for emulator to start
- events.emit('log', 'Waiting for emulator to start...');
- return self.wait_for_emulator(port);
- });
- }).then(function(emulatorId) {
- if (!emulatorId)
- return Q.reject(new CordovaError('Failed to start emulator'));
-
- //wait for emulator to boot up
- process.stdout.write('Waiting for emulator to boot (this may take a while)...');
- return self.wait_for_boot(emulatorId, boot_timeout)
- .then(function(success) {
- if (success) {
- events.emit('log','BOOT COMPLETE');
- //unlock screen
- return Adb.shell(emulatorId, 'input keyevent 82')
- .then(function() {
- //return the new emulator id for the started emulators
- return emulatorId;
- });
- } else {
- // We timed out waiting for the boot to happen
- return null;
- }
- });
- });
-};
-
-/*
- * Waits for an emulator to boot on a given port.
- * Returns this emulator's ID in a promise.
- */
-module.exports.wait_for_emulator = function(port) {
- var self = this;
- return Q().then(function() {
- var emulator_id = 'emulator-' + port;
- return Adb.shell(emulator_id, 'getprop dev.bootcomplete')
- .then(function (output) {
- if (output.indexOf('1') >= 0) {
- return emulator_id;
- }
- return self.wait_for_emulator(port);
- }, function (error) {
- if (error && error.message &&
- (error.message.indexOf('not found') > -1) ||
- error.message.indexOf('device offline') > -1) {
- // emulator not yet started, continue waiting
- return self.wait_for_emulator(port);
- } else {
- // something unexpected has happened
- throw error;
- }
- });
- });
-};
-
-/*
- * Waits for the core android process of the emulator to start. Returns a
- * promise that resolves to a boolean indicating success. Not specifying a
- * time_remaining or passing a negative value will cause it to wait forever
- */
-module.exports.wait_for_boot = function(emulator_id, time_remaining) {
- var self = this;
- return Adb.shell(emulator_id, 'ps')
- .then(function(output) {
- if (output.match(/android\.process\.acore/)) {
- return true;
- } else if (time_remaining === 0) {
- return false;
- } else {
- process.stdout.write('.');
-
- // Check at regular intervals
- return Q.delay(time_remaining < CHECK_BOOTED_INTERVAL ? time_remaining : CHECK_BOOTED_INTERVAL).then(function() {
- var updated_time = time_remaining >= 0 ? Math.max(time_remaining - CHECK_BOOTED_INTERVAL, 0) : time_remaining;
- return self.wait_for_boot(emulator_id, updated_time);
- });
- }
- });
-};
-
-/*
- * Create avd
- * TODO : Enter the stdin input required to complete the creation of an avd.
- * Returns a promise.
- */
-module.exports.create_image = function(name, target) {
- console.log('Creating new avd named ' + name);
- if (target) {
- return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', target])
- .then(null, function(error) {
- console.error('ERROR : Failed to create emulator image : ');
- console.error(' Do you have the latest android targets including ' + target + '?');
- console.error(error);
- });
- } else {
- console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.');
- // TODO: there's a more robust method for finding targets in android_sdk.js
- return superspawn.spawn('android', ['create', 'avd', '--name', name, '--target', this.list_targets()[0]])
- .then(function() {
- // TODO: This seems like another error case, even though it always happens.
- console.error('ERROR : Unable to create an avd emulator, no targets found.');
- console.error('Ensure you have targets available by running the "android" command');
- return Q.reject();
- }, function(error) {
- console.error('ERROR : Failed to create emulator image : ');
- console.error(error);
- });
- }
-};
-
-module.exports.resolveTarget = function(target) {
- return this.list_started()
- .then(function(emulator_list) {
- if (emulator_list.length < 1) {
- return Q.reject('No running Android emulators found, please start an emulator before deploying your project.');
- }
-
- // default emulator
- target = target || emulator_list[0];
- if (emulator_list.indexOf(target) < 0) {
- return Q.reject('Unable to find target \'' + target + '\'. Failed to deploy to emulator.');
- }
-
- return build.detectArchitecture(target)
- .then(function(arch) {
- return {target:target, arch:arch, isEmulator:true};
- });
- });
-};
-
-/*
- * Installs a previously built application on the emulator and launches it.
- * If no target is specified, then it picks one.
- * If no started emulators are found, error out.
- * Returns a promise.
- */
-module.exports.install = function(givenTarget, buildResults) {
-
- var target;
- var manifest = new AndroidManifest(path.join(__dirname, '../../AndroidManifest.xml'));
- var pkgName = manifest.getPackageId();
-
- // resolve the target emulator
- return Q().then(function () {
- if (givenTarget && typeof givenTarget == 'object') {
- return givenTarget;
- } else {
- return module.exports.resolveTarget(givenTarget);
- }
-
- // set the resolved target
- }).then(function (resolvedTarget) {
- target = resolvedTarget;
-
- // install the app
- }).then(function () {
- // This promise is always resolved, even if 'adb uninstall' fails to uninstall app
- // or the app doesn't installed at all, so no error catching needed.
- return Q.when()
- .then(function() {
-
- var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
- var execOptions = {
- cwd: os.tmpdir(),
- timeout: INSTALL_COMMAND_TIMEOUT, // in milliseconds
- killSignal: EXEC_KILL_SIGNAL
- };
-
- events.emit('log', 'Using apk: ' + apk_path);
- events.emit('log', 'Package name: ' + pkgName);
- events.emit('verbose', 'Installing app on emulator...');
-
- // A special function to call adb install in specific environment w/ specific options.
- // Introduced as a part of fix for http://issues.apache.org/jira/browse/CB-9119
- // to workaround sporadic emulator hangs
- function adbInstallWithOptions(target, apk, opts) {
- events.emit('verbose', 'Installing apk ' + apk + ' on ' + target + '...');
-
- var command = 'adb -s ' + target + ' install -r "' + apk + '"';
- return Q.promise(function (resolve, reject) {
- child_process.exec(command, opts, function(err, stdout, stderr) {
- if (err) reject(new CordovaError('Error executing "' + command + '": ' + stderr));
- // adb does not return an error code even if installation fails. Instead it puts a specific
- // message to stdout, so we have to use RegExp matching to detect installation failure.
- else if (/Failure/.test(stdout)) {
- if (stdout.match(/INSTALL_PARSE_FAILED_NO_CERTIFICATES/)) {
- stdout += 'Sign the build using \'-- --keystore\' or \'--buildConfig\'' +
- ' or sign and deploy the unsigned apk manually using Android tools.';
- } else if (stdout.match(/INSTALL_FAILED_VERSION_DOWNGRADE/)) {
- stdout += 'You\'re trying to install apk with a lower versionCode that is already installed.' +
- '\nEither uninstall an app or increment the versionCode.';
- }
-
- reject(new CordovaError('Failed to install apk to emulator: ' + stdout));
- } else resolve(stdout);
- });
- });
- }
-
- function installPromise () {
- return adbInstallWithOptions(target.target, apk_path, execOptions)
- .catch(function (error) {
- // CB-9557 CB-10157 only uninstall and reinstall app if the one that
- // is already installed on device was signed w/different certificate
- if (!/INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES/.test(error.toString()))
- throw error;
-
- events.emit('warn', 'Uninstalling app from device and reinstalling it because the ' +
- 'currently installed app was signed with different key');
-
- // This promise is always resolved, even if 'adb uninstall' fails to uninstall app
- // or the app doesn't installed at all, so no error catching needed.
- return Adb.uninstall(target.target, pkgName)
- .then(function() {
- return adbInstallWithOptions(target.target, apk_path, execOptions);
- });
- });
- }
-
- return retry.retryPromise(NUM_INSTALL_RETRIES, installPromise)
- .then(function (output) {
- events.emit('log', 'INSTALL SUCCESS');
- });
- });
- // unlock screen
- }).then(function () {
-
- events.emit('verbose', 'Unlocking screen...');
- return Adb.shell(target.target, 'input keyevent 82');
- }).then(function () {
- Adb.start(target.target, pkgName + '/.' + manifest.getActivity().getName());
- // report success or failure
- }).then(function (output) {
- events.emit('log', 'LAUNCH SUCCESS');
- });
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/install-device b/StoneIsland/platforms/android/cordova/lib/install-device
deleted file mode 100755
index fc4b7841..00000000
--- a/StoneIsland/platforms/android/cordova/lib/install-device
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var device = require('./device'),
- args = process.argv;
-
-if(args.length > 2) {
- var install_target;
- if (args[2].substring(0, 9) == '--target=') {
- install_target = args[2].substring(9, args[2].length);
- device.install(install_target).done(null, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
- });
- } else {
- console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
- process.exit(2);
- }
-} else {
- device.install().done(null, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
- });
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/install-device.bat b/StoneIsland/platforms/android/cordova/lib/install-device.bat
deleted file mode 100644
index ac7214ac..00000000
--- a/StoneIsland/platforms/android/cordova/lib/install-device.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0install-device"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'install-device' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-) \ No newline at end of file
diff --git a/StoneIsland/platforms/android/cordova/lib/install-emulator b/StoneIsland/platforms/android/cordova/lib/install-emulator
deleted file mode 100755
index aa2a34f6..00000000
--- a/StoneIsland/platforms/android/cordova/lib/install-emulator
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var emulator = require('./emulator'),
- args = process.argv;
-
-var install_target;
-if(args.length > 2) {
- if (args[2].substring(0, 9) == '--target=') {
- install_target = args[2].substring(9, args[2].length);
- } else {
- console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
- process.exit(2);
- }
-}
-
-emulator.install(install_target).done(null, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
-});
diff --git a/StoneIsland/platforms/android/cordova/lib/install-emulator.bat b/StoneIsland/platforms/android/cordova/lib/install-emulator.bat
deleted file mode 100644
index 1ec67790..00000000
--- a/StoneIsland/platforms/android/cordova/lib/install-emulator.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0install-emulator"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'install-emulator' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-) \ No newline at end of file
diff --git a/StoneIsland/platforms/android/cordova/lib/list-devices b/StoneIsland/platforms/android/cordova/lib/list-devices
deleted file mode 100755
index 8e22c7f2..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-devices
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var devices = require('./device');
-
-// Usage support for when args are given
-require('./check_reqs').check_android().then(function() {
- devices.list().done(function(device_list) {
- device_list && device_list.forEach(function(dev) {
- console.log(dev);
- });
- }, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
- });
-});
diff --git a/StoneIsland/platforms/android/cordova/lib/list-devices.bat b/StoneIsland/platforms/android/cordova/lib/list-devices.bat
deleted file mode 100644
index c0bcdd9a..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-devices.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0list-devices"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'list-devices' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-) \ No newline at end of file
diff --git a/StoneIsland/platforms/android/cordova/lib/list-emulator-images b/StoneIsland/platforms/android/cordova/lib/list-emulator-images
deleted file mode 100755
index 25e5c81a..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-emulator-images
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var emulators = require('./emulator');
-
-// Usage support for when args are given
-require('./check_reqs').check_android().then(function() {
- emulators.list_images().done(function(emulator_list) {
- emulator_list && emulator_list.forEach(function(emu) {
- console.log(emu.name);
- });
- }, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
- });
-});
diff --git a/StoneIsland/platforms/android/cordova/lib/list-emulator-images.bat b/StoneIsland/platforms/android/cordova/lib/list-emulator-images.bat
deleted file mode 100644
index 661cbf95..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-emulator-images.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0list-emulator-images"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'list-emulator-images' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-)
diff --git a/StoneIsland/platforms/android/cordova/lib/list-started-emulators b/StoneIsland/platforms/android/cordova/lib/list-started-emulators
deleted file mode 100755
index 43ebda25..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-started-emulators
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var emulators = require('./emulator');
-
-// Usage support for when args are given
-require('./check_reqs').check_android().then(function() {
- emulators.list_started().done(function(emulator_list) {
- emulator_list && emulator_list.forEach(function(emu) {
- console.log(emu);
- });
- }, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
- });
-});
diff --git a/StoneIsland/platforms/android/cordova/lib/list-started-emulators.bat b/StoneIsland/platforms/android/cordova/lib/list-started-emulators.bat
deleted file mode 100644
index a4e88f7d..00000000
--- a/StoneIsland/platforms/android/cordova/lib/list-started-emulators.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0list-started-emulators"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'list-started-emulators' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-) \ No newline at end of file
diff --git a/StoneIsland/platforms/android/cordova/lib/log.js b/StoneIsland/platforms/android/cordova/lib/log.js
deleted file mode 100644
index ebf836d5..00000000
--- a/StoneIsland/platforms/android/cordova/lib/log.js
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var path = require('path'),
- os = require('os'),
- Q = require('q'),
- child_process = require('child_process'),
- ROOT = path.join(__dirname, '..', '..');
-
-/*
- * Starts running logcat in the shell.
- * Returns a promise.
- */
-module.exports.run = function() {
- var d = Q.defer();
- var adb = child_process.spawn('adb', ['logcat'], {cwd: os.tmpdir()});
-
- adb.stdout.on('data', function(data) {
- var lines = data ? data.toString().split('\n') : [];
- var out = lines.filter(function(x) { return x.indexOf('nativeGetEnabledTags') < 0; });
- console.log(out.join('\n'));
- });
-
- adb.stderr.on('data', console.error);
- adb.on('close', function(code) {
- if (code > 0) {
- d.reject('Failed to run logcat command.');
- } else d.resolve();
- });
-
- return d.promise;
-};
-
-module.exports.help = function() {
- console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'log')));
- console.log('Gives the logcat output on the command line.');
- process.exit(0);
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/plugin-build.gradle b/StoneIsland/platforms/android/cordova/lib/plugin-build.gradle
deleted file mode 100644
index d1c63365..00000000
--- a/StoneIsland/platforms/android/cordova/lib/plugin-build.gradle
+++ /dev/null
@@ -1,70 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-// GENERATED FILE! DO NOT EDIT!
-
-buildscript {
- repositories {
- mavenCentral()
- jcenter()
- }
-
- // Switch the Android Gradle plugin version requirement depending on the
- // installed version of Gradle. This dependency is documented at
- // http://tools.android.com/tech-docs/new-build-system/version-compatibility
- // and https://issues.apache.org/jira/browse/CB-8143
- dependencies {
- classpath 'com.android.tools.build:gradle:1.0.0+'
- }
-}
-
-apply plugin: 'com.android.library'
-
-dependencies {
- compile fileTree(dir: 'libs', include: '*.jar')
- debugCompile project(path: ":CordovaLib", configuration: "debug")
- releaseCompile project(path: ":CordovaLib", configuration: "release")
-}
-
-android {
- compileSdkVersion cdvCompileSdkVersion
- buildToolsVersion cdvBuildToolsVersion
- publishNonDefault true
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_6
- targetCompatibility JavaVersion.VERSION_1_6
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- jniLibs.srcDirs = ['libs']
- }
- }
-}
-
-if (file('build-extras.gradle').exists()) {
- apply from: 'build-extras.gradle'
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/pluginHandlers.js b/StoneIsland/platforms/android/cordova/lib/pluginHandlers.js
deleted file mode 100644
index 5e745fd5..00000000
--- a/StoneIsland/platforms/android/cordova/lib/pluginHandlers.js
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- *
- * Copyright 2013 Anis Kadri
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-/* jshint unused: vars */
-
-var fs = require('fs');
-var path = require('path');
-var shell = require('shelljs');
-var events = require('cordova-common').events;
-var CordovaError = require('cordova-common').CordovaError;
-
-var handlers = {
- 'source-file':{
- install:function(obj, plugin, project, options) {
- if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
- if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
-
- var dest = path.join(obj.targetDir, path.basename(obj.src));
-
- if(options && options.android_studio === true) {
- dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
- }
-
- if (options && options.force) {
- copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
- } else {
- copyNewFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
- }
- },
- uninstall:function(obj, plugin, project, options) {
- var dest = path.join(obj.targetDir, path.basename(obj.src));
-
- if(options && options.android_studio === true) {
- dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
- }
-
- deleteJava(project.projectDir, dest);
- }
- },
- 'lib-file':{
- install:function(obj, plugin, project, options) {
- var dest = path.join('libs', path.basename(obj.src));
- if(options && options.android_studio === true) {
- dest = path.join('app/libs', path.basename(obj.src));
- }
- copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
- },
- uninstall:function(obj, plugin, project, options) {
- var dest = path.join('libs', path.basename(obj.src));
- if(options && options.android_studio === true) {
- dest = path.join('app/libs', path.basename(obj.src));
- }
- removeFile(project.projectDir, dest);
- }
- },
- 'resource-file':{
- install:function(obj, plugin, project, options) {
- copyFile(plugin.dir, obj.src, project.projectDir, path.normalize(obj.target), !!(options && options.link));
- },
- uninstall:function(obj, plugin, project, options) {
- removeFile(project.projectDir, path.normalize(obj.target));
- }
- },
- 'framework': {
- install:function(obj, plugin, project, options) {
- var src = obj.src;
- if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
-
- events.emit('verbose', 'Installing Android library: ' + src);
- var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
- var subDir;
-
- if (obj.custom) {
- var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
- copyNewFile(plugin.dir, src, project.projectDir, subRelativeDir, !!(options && options.link));
- subDir = path.resolve(project.projectDir, subRelativeDir);
- } else {
- obj.type = 'sys';
- subDir = src;
- }
-
- if (obj.type == 'gradleReference') {
- project.addGradleReference(parentDir, subDir);
- } else if (obj.type == 'sys') {
- project.addSystemLibrary(parentDir, subDir);
- } else {
- project.addSubProject(parentDir, subDir);
- }
- },
- uninstall:function(obj, plugin, project, options) {
- var src = obj.src;
- if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
-
- events.emit('verbose', 'Uninstalling Android library: ' + src);
- var parentDir = obj.parent ? path.resolve(project.projectDir, obj.parent) : project.projectDir;
- var subDir;
-
- if (obj.custom) {
- var subRelativeDir = project.getCustomSubprojectRelativeDir(plugin.id, src);
- removeFile(project.projectDir, subRelativeDir);
- subDir = path.resolve(project.projectDir, subRelativeDir);
- // If it's the last framework in the plugin, remove the parent directory.
- var parDir = path.dirname(subDir);
- if (fs.existsSync(parDir) && fs.readdirSync(parDir).length === 0) {
- fs.rmdirSync(parDir);
- }
- } else {
- obj.type = 'sys';
- subDir = src;
- }
-
- if (obj.type == 'gradleReference') {
- project.removeGradleReference(parentDir, subDir);
- } else if (obj.type == 'sys') {
- project.removeSystemLibrary(parentDir, subDir);
- } else {
- project.removeSubProject(parentDir, subDir);
- }
- }
- },
- asset:{
- install:function(obj, plugin, project, options) {
- if (!obj.src) {
- throw new CordovaError(generateAttributeError('src', 'asset', plugin.id));
- }
- if (!obj.target) {
- throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
- }
-
- copyFile(plugin.dir, obj.src, project.www, obj.target);
- if (options && options.usePlatformWww) {
- // CB-11022 copy file to both directories if usePlatformWww is specified
- copyFile(plugin.dir, obj.src, project.platformWww, obj.target);
- }
- },
- uninstall:function(obj, plugin, project, options) {
- var target = obj.target || obj.src;
-
- if (!target) throw new CordovaError(generateAttributeError('target', 'asset', plugin.id));
-
- removeFileF(path.resolve(project.www, target));
- removeFileF(path.resolve(project.www, 'plugins', plugin.id));
- if (options && options.usePlatformWww) {
- // CB-11022 remove file from both directories if usePlatformWww is specified
- removeFileF(path.resolve(project.platformWww, target));
- removeFileF(path.resolve(project.platformWww, 'plugins', plugin.id));
- }
- }
- },
- 'js-module': {
- install: function (obj, plugin, project, options) {
- // Copy the plugin's files into the www directory.
- var moduleSource = path.resolve(plugin.dir, obj.src);
- var moduleName = plugin.id + '.' + (obj.name || path.basename(obj.src, path.extname (obj.src)));
-
- // Read in the file, prepend the cordova.define, and write it back out.
- var scriptContent = fs.readFileSync(moduleSource, 'utf-8').replace(/^\ufeff/, ''); // Window BOM
- if (moduleSource.match(/.*\.json$/)) {
- scriptContent = 'module.exports = ' + scriptContent;
- }
- scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
-
- var wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
- shell.mkdir('-p', path.dirname(wwwDest));
- fs.writeFileSync(wwwDest, scriptContent, 'utf-8');
-
- if (options && options.usePlatformWww) {
- // CB-11022 copy file to both directories if usePlatformWww is specified
- var platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
- shell.mkdir('-p', path.dirname(platformWwwDest));
- fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
- }
- },
- uninstall: function (obj, plugin, project, options) {
- var pluginRelativePath = path.join('plugins', plugin.id, obj.src);
- removeFileAndParents(project.www, pluginRelativePath);
- if (options && options.usePlatformWww) {
- // CB-11022 remove file from both directories if usePlatformWww is specified
- removeFileAndParents(project.platformWww, pluginRelativePath);
- }
- }
- }
-};
-
-module.exports.getInstaller = function (type) {
- if (handlers[type] && handlers[type].install) {
- return handlers[type].install;
- }
-
- events.emit('verbose', '<' + type + '> is not supported for android plugins');
-};
-
-module.exports.getUninstaller = function(type) {
- if (handlers[type] && handlers[type].uninstall) {
- return handlers[type].uninstall;
- }
-
- events.emit('verbose', '<' + type + '> is not supported for android plugins');
-};
-
-function copyFile (plugin_dir, src, project_dir, dest, link) {
- src = path.resolve(plugin_dir, src);
- if (!fs.existsSync(src)) throw new CordovaError('"' + src + '" not found!');
-
- // check that src path is inside plugin directory
- var real_path = fs.realpathSync(src);
- var real_plugin_path = fs.realpathSync(plugin_dir);
- if (real_path.indexOf(real_plugin_path) !== 0)
- throw new CordovaError('File "' + src + '" is located outside the plugin directory "' + plugin_dir + '"');
-
- dest = path.resolve(project_dir, dest);
-
- // check that dest path is located in project directory
- if (dest.indexOf(project_dir) !== 0)
- throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project');
-
- shell.mkdir('-p', path.dirname(dest));
- if (link) {
- symlinkFileOrDirTree(src, dest);
- } else if (fs.statSync(src).isDirectory()) {
- // XXX shelljs decides to create a directory when -R|-r is used which sucks. http://goo.gl/nbsjq
- shell.cp('-Rf', src+'/*', dest);
- } else {
- shell.cp('-f', src, dest);
- }
-}
-
-// Same as copy file but throws error if target exists
-function copyNewFile (plugin_dir, src, project_dir, dest, link) {
- var target_path = path.resolve(project_dir, dest);
- if (fs.existsSync(target_path))
- throw new CordovaError('"' + target_path + '" already exists!');
-
- copyFile(plugin_dir, src, project_dir, dest, !!link);
-}
-
-function symlinkFileOrDirTree(src, dest) {
- if (fs.existsSync(dest)) {
- shell.rm('-Rf', dest);
- }
-
- if (fs.statSync(src).isDirectory()) {
- shell.mkdir('-p', dest);
- fs.readdirSync(src).forEach(function(entry) {
- symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
- });
- }
- else {
- fs.symlinkSync(path.relative(fs.realpathSync(path.dirname(dest)), src), dest);
- }
-}
-
-// checks if file exists and then deletes. Error if doesn't exist
-function removeFile (project_dir, src) {
- var file = path.resolve(project_dir, src);
- shell.rm('-Rf', file);
-}
-
-// deletes file/directory without checking
-function removeFileF (file) {
- shell.rm('-Rf', file);
-}
-
-// Sometimes we want to remove some java, and prune any unnecessary empty directories
-function deleteJava (project_dir, destFile) {
- removeFileAndParents(project_dir, destFile, 'src');
-}
-
-function removeFileAndParents (baseDir, destFile, stopper) {
- stopper = stopper || '.';
- var file = path.resolve(baseDir, destFile);
- if (!fs.existsSync(file)) return;
-
- removeFileF(file);
-
- // check if directory is empty
- var curDir = path.dirname(file);
-
- while(curDir !== path.resolve(baseDir, stopper)) {
- if(fs.existsSync(curDir) && fs.readdirSync(curDir).length === 0) {
- fs.rmdirSync(curDir);
- curDir = path.resolve(curDir, '..');
- } else {
- // directory not empty...do nothing
- break;
- }
- }
-}
-
-function generateAttributeError(attribute, element, id) {
- return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/prepare.js b/StoneIsland/platforms/android/cordova/lib/prepare.js
deleted file mode 100644
index 504eb612..00000000
--- a/StoneIsland/platforms/android/cordova/lib/prepare.js
+++ /dev/null
@@ -1,471 +0,0 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var Q = require('q');
-var fs = require('fs');
-var path = require('path');
-var shell = require('shelljs');
-var events = require('cordova-common').events;
-var AndroidManifest = require('./AndroidManifest');
-var xmlHelpers = require('cordova-common').xmlHelpers;
-var CordovaError = require('cordova-common').CordovaError;
-var ConfigParser = require('cordova-common').ConfigParser;
-var FileUpdater = require('cordova-common').FileUpdater;
-var PlatformJson = require('cordova-common').PlatformJson;
-var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger;
-var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
-
-module.exports.prepare = function (cordovaProject, options) {
- var self = this;
-
- var platformJson = PlatformJson.load(this.locations.root, this.platform);
- var munger = new PlatformMunger(this.platform, this.locations.root, platformJson, new PluginInfoProvider());
-
- this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations);
-
- // Update own www dir with project's www assets and plugins' assets and js-files
- return Q.when(updateWww(cordovaProject, this.locations))
- .then(function () {
- // update project according to config.xml changes.
- return updateProjectAccordingTo(self._config, self.locations);
- })
- .then(function () {
- updateIcons(cordovaProject, path.relative(cordovaProject.root, self.locations.res));
- updateSplashes(cordovaProject, path.relative(cordovaProject.root, self.locations.res));
- updateFileResources(cordovaProject, path.relative(cordovaProject.root, self.locations.root));
- })
- .then(function () {
- events.emit('verbose', 'Prepared android project successfully');
- });
-};
-
-module.exports.clean = function (options) {
- // A cordovaProject isn't passed into the clean() function, because it might have
- // been called from the platform shell script rather than the CLI. Check for the
- // noPrepare option passed in by the non-CLI clean script. If that's present, or if
- // there's no config.xml found at the project root, then don't clean prepared files.
- var projectRoot = path.resolve(this.root, '../..');
- if ((options && options.noPrepare) || !fs.existsSync(this.locations.configXml) ||
- !fs.existsSync(this.locations.configXml)) {
- return Q();
- }
-
- var projectConfig = new ConfigParser(this.locations.configXml);
-
- var self = this;
- return Q().then(function () {
- cleanWww(projectRoot, self.locations);
- cleanIcons(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
- cleanSplashes(projectRoot, projectConfig, path.relative(projectRoot, self.locations.res));
- cleanFileResources(projectRoot, projectConfig, path.relative(projectRoot, self.locations.root));
- });
-};
-
-/**
- * Updates config files in project based on app's config.xml and config munge,
- * generated by plugins.
- *
- * @param {ConfigParser} sourceConfig A project's configuration that will
- * be merged into platform's config.xml
- * @param {ConfigChanges} configMunger An initialized ConfigChanges instance
- * for this platform.
- * @param {Object} locations A map of locations for this platform
- *
- * @return {ConfigParser} An instance of ConfigParser, that
- * represents current project's configuration. When returned, the
- * configuration is already dumped to appropriate config.xml file.
- */
-function updateConfigFilesFrom(sourceConfig, configMunger, locations) {
- events.emit('verbose', 'Generating platform-specific config.xml from defaults for android at ' + locations.configXml);
-
- // First cleanup current config and merge project's one into own
- // Overwrite platform config.xml with defaults.xml.
- shell.cp('-f', locations.defaultConfigXml, locations.configXml);
-
- // Then apply config changes from global munge to all config files
- // in project (including project's config)
- configMunger.reapply_global_munge().save_all();
-
- events.emit('verbose', 'Merging project\'s config.xml into platform-specific android config.xml');
- // Merge changes from app's config.xml into platform's one
- var config = new ConfigParser(locations.configXml);
- xmlHelpers.mergeXml(sourceConfig.doc.getroot(),
- config.doc.getroot(), 'android', /*clobber=*/true);
-
- config.write();
- return config;
-}
-
-/**
- * Logs all file operations via the verbose event stream, indented.
- */
-function logFileOp(message) {
- events.emit('verbose', ' ' + message);
-}
-
-/**
- * Updates platform 'www' directory by replacing it with contents of
- * 'platform_www' and app www. Also copies project's overrides' folder into
- * the platform 'www' folder
- *
- * @param {Object} cordovaProject An object which describes cordova project.
- * @param {Object} destinations An object that contains destination
- * paths for www files.
- */
-function updateWww(cordovaProject, destinations) {
- var sourceDirs = [
- path.relative(cordovaProject.root, cordovaProject.locations.www),
- path.relative(cordovaProject.root, destinations.platformWww)
- ];
-
- // If project contains 'merges' for our platform, use them as another overrides
- var merges_path = path.join(cordovaProject.root, 'merges', 'android');
- if (fs.existsSync(merges_path)) {
- events.emit('verbose', 'Found "merges/android" folder. Copying its contents into the android project.');
- sourceDirs.push(path.join('merges', 'android'));
- }
-
- var targetDir = path.relative(cordovaProject.root, destinations.www);
- events.emit(
- 'verbose', 'Merging and updating files from [' + sourceDirs.join(', ') + '] to ' + targetDir);
- FileUpdater.mergeAndUpdateDir(
- sourceDirs, targetDir, { rootDir: cordovaProject.root }, logFileOp);
-}
-
-/**
- * Cleans all files from the platform 'www' directory.
- */
-function cleanWww(projectRoot, locations) {
- var targetDir = path.relative(projectRoot, locations.www);
- events.emit('verbose', 'Cleaning ' + targetDir);
-
- // No source paths are specified, so mergeAndUpdateDir() will clear the target directory.
- FileUpdater.mergeAndUpdateDir(
- [], targetDir, { rootDir: projectRoot, all: true }, logFileOp);
-}
-
-/**
- * Updates project structure and AndroidManifest according to project's configuration.
- *
- * @param {ConfigParser} platformConfig A project's configuration that will
- * be used to update project
- * @param {Object} locations A map of locations for this platform
- */
-function updateProjectAccordingTo(platformConfig, locations) {
- // Update app name by editing res/values/strings.xml
- var name = platformConfig.name();
- var strings = xmlHelpers.parseElementtreeSync(locations.strings);
- strings.find('string[@name="app_name"]').text = name.replace(/\'/g, '\\\'');
- fs.writeFileSync(locations.strings, strings.write({indent: 4}), 'utf-8');
- events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
-
- // Java packages cannot support dashes
- var pkg = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g, '_');
-
- var manifest = new AndroidManifest(locations.manifest);
- var orig_pkg = manifest.getPackageId();
-
- manifest.getActivity()
- .setOrientation(platformConfig.getPreference('orientation'))
- .setLaunchMode(findAndroidLaunchModePreference(platformConfig));
-
- manifest.setVersionName(platformConfig.version())
- .setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
- .setPackageId(pkg)
- .setMinSdkVersion(platformConfig.getPreference('android-minSdkVersion', 'android'))
- .setMaxSdkVersion(platformConfig.getPreference('android-maxSdkVersion', 'android'))
- .setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
- .write();
-
- var javaPattern = path.join(locations.root, 'src', orig_pkg.replace(/\./g, '/'), '*.java');
- var java_files = shell.ls(javaPattern).filter(function(f) {
- return shell.grep(/extends\s+CordovaActivity/g, f);
- });
-
- if (java_files.length === 0) {
- throw new CordovaError('No Java files found that extend CordovaActivity.');
- } else if(java_files.length > 1) {
- events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found. Guessing at the first one, ' + java_files[0]);
- }
-
- var destFile = path.join(locations.root, 'src', pkg.replace(/\./g, '/'), path.basename(java_files[0]));
- shell.mkdir('-p', path.dirname(destFile));
- shell.sed(/package [\w\.]*;/, 'package ' + pkg + ';', java_files[0]).to(destFile);
- events.emit('verbose', 'Wrote out Android package name "' + pkg + '" to ' + destFile);
-
- if (orig_pkg !== pkg) {
- // If package was name changed we need to remove old java with main activity
- shell.rm('-Rf',java_files[0]);
- // remove any empty directories
- var currentDir = path.dirname(java_files[0]);
- var sourcesRoot = path.resolve(locations.root, 'src');
- while(currentDir !== sourcesRoot) {
- if(fs.existsSync(currentDir) && fs.readdirSync(currentDir).length === 0) {
- fs.rmdirSync(currentDir);
- currentDir = path.resolve(currentDir, '..');
- } else {
- break;
- }
- }
- }
-}
-
-// Consturct the default value for versionCode as
-// PATCH + MINOR * 100 + MAJOR * 10000
-// see http://developer.android.com/tools/publishing/versioning.html
-function default_versionCode(version) {
- var nums = version.split('-')[0].split('.');
- var versionCode = 0;
- if (+nums[0]) {
- versionCode += +nums[0] * 10000;
- }
- if (+nums[1]) {
- versionCode += +nums[1] * 100;
- }
- if (+nums[2]) {
- versionCode += +nums[2];
- }
-
- events.emit('verbose', 'android-versionCode not found in config.xml. Generating a code based on version in config.xml (' + version + '): ' + versionCode);
- return versionCode;
-}
-
-function getImageResourcePath(resourcesDir, type, density, name, sourceName) {
- if (/\.9\.png$/.test(sourceName)) {
- name = name.replace(/\.png$/, '.9.png');
- }
- var resourcePath = path.join(resourcesDir, (density ? type + '-' + density : type), name);
- return resourcePath;
-}
-
-function updateSplashes(cordovaProject, platformResourcesDir) {
- var resources = cordovaProject.projectConfig.getSplashScreens('android');
-
- // if there are "splash" elements in config.xml
- if (resources.length === 0) {
- events.emit('verbose', 'This app does not have splash screens defined');
- return;
- }
-
- var resourceMap = mapImageResources(cordovaProject.root, platformResourcesDir, 'drawable', 'screen.png');
-
- var hadMdpi = false;
- resources.forEach(function (resource) {
- if (!resource.density) {
- return;
- }
- if (resource.density == 'mdpi') {
- hadMdpi = true;
- }
- var targetPath = getImageResourcePath(
- platformResourcesDir, 'drawable', resource.density, 'screen.png', path.basename(resource.src));
- resourceMap[targetPath] = resource.src;
- });
-
- // There's no "default" drawable, so assume default == mdpi.
- if (!hadMdpi && resources.defaultResource) {
- var targetPath = getImageResourcePath(
- platformResourcesDir, 'drawable', 'mdpi', 'screen.png', path.basename(resources.defaultResource.src));
- resourceMap[targetPath] = resources.defaultResource.src;
- }
-
- events.emit('verbose', 'Updating splash screens at ' + platformResourcesDir);
- FileUpdater.updatePaths(
- resourceMap, { rootDir: cordovaProject.root }, logFileOp);
-}
-
-function cleanSplashes(projectRoot, projectConfig, platformResourcesDir) {
- var resources = projectConfig.getSplashScreens('android');
- if (resources.length > 0) {
- var resourceMap = mapImageResources(projectRoot, platformResourcesDir, 'drawable', 'screen.png');
- events.emit('verbose', 'Cleaning splash screens at ' + platformResourcesDir);
-
- // No source paths are specified in the map, so updatePaths() will delete the target files.
- FileUpdater.updatePaths(
- resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
- }
-}
-
-function updateIcons(cordovaProject, platformResourcesDir) {
- var icons = cordovaProject.projectConfig.getIcons('android');
-
- // if there are icon elements in config.xml
- if (icons.length === 0) {
- events.emit('verbose', 'This app does not have launcher icons defined');
- return;
- }
-
- var resourceMap = mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'icon.png');
-
- var android_icons = {};
- var default_icon;
- // http://developer.android.com/design/style/iconography.html
- var sizeToDensityMap = {
- 36: 'ldpi',
- 48: 'mdpi',
- 72: 'hdpi',
- 96: 'xhdpi',
- 144: 'xxhdpi',
- 192: 'xxxhdpi'
- };
- // find the best matching icon for a given density or size
- // @output android_icons
- var parseIcon = function(icon, icon_size) {
- // do I have a platform icon for that density already
- var density = icon.density || sizeToDensityMap[icon_size];
- if (!density) {
- // invalid icon defition ( or unsupported size)
- return;
- }
- var previous = android_icons[density];
- if (previous && previous.platform) {
- return;
- }
- android_icons[density] = icon;
- };
-
- // iterate over all icon elements to find the default icon and call parseIcon
- for (var i=0; i<icons.length; i++) {
- var icon = icons[i];
- var size = icon.width;
- if (!size) {
- size = icon.height;
- }
- if (!size && !icon.density) {
- if (default_icon) {
- events.emit('verbose', 'Found extra default icon: ' + icon.src + ' (ignoring in favor of ' + default_icon.src + ')');
- } else {
- default_icon = icon;
- }
- } else {
- parseIcon(icon, size);
- }
- }
-
- // The source paths for icons and splashes are relative to
- // project's config.xml location, so we use it as base path.
- for (var density in android_icons) {
- var targetPath = getImageResourcePath(
- platformResourcesDir, 'mipmap', density, 'icon.png', path.basename(android_icons[density].src));
- resourceMap[targetPath] = android_icons[density].src;
- }
-
- // There's no "default" drawable, so assume default == mdpi.
- if (default_icon && !android_icons.mdpi) {
- var defaultTargetPath = getImageResourcePath(
- platformResourcesDir, 'mipmap', 'mdpi', 'icon.png', path.basename(default_icon.src));
- resourceMap[defaultTargetPath] = default_icon.src;
- }
-
- events.emit('verbose', 'Updating icons at ' + platformResourcesDir);
- FileUpdater.updatePaths(
- resourceMap, { rootDir: cordovaProject.root }, logFileOp);
-}
-
-function cleanIcons(projectRoot, projectConfig, platformResourcesDir) {
- var icons = projectConfig.getIcons('android');
- if (icons.length > 0) {
- var resourceMap = mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'icon.png');
- events.emit('verbose', 'Cleaning icons at ' + platformResourcesDir);
-
- // No source paths are specified in the map, so updatePaths() will delete the target files.
- FileUpdater.updatePaths(
- resourceMap, { rootDir: projectRoot, all: true }, logFileOp);
- }
-}
-
-/**
- * Gets a map containing resources of a specified name from all drawable folders in a directory.
- */
-function mapImageResources(rootDir, subDir, type, resourceName) {
- var pathMap = {};
- shell.ls(path.join(rootDir, subDir, type + '-*'))
- .forEach(function (drawableFolder) {
- var imagePath = path.join(subDir, path.basename(drawableFolder), resourceName);
- pathMap[imagePath] = null;
- });
- return pathMap;
-}
-
-
-function updateFileResources(cordovaProject, platformDir) {
- var files = cordovaProject.projectConfig.getFileResources('android');
-
- // if there are resource-file elements in config.xml
- if (files.length === 0) {
- events.emit('verbose', 'This app does not have additional resource files defined');
- return;
- }
-
- var resourceMap = {};
- files.forEach(function(res) {
- var targetPath = path.join(platformDir, res.target);
- resourceMap[targetPath] = res.src;
- });
-
- events.emit('verbose', 'Updating resource files at ' + platformDir);
- FileUpdater.updatePaths(
- resourceMap, { rootDir: cordovaProject.root }, logFileOp);
-}
-
-
-function cleanFileResources(projectRoot, projectConfig, platformDir) {
- var files = projectConfig.getFileResources('android');
- if (files.length > 0) {
- events.emit('verbose', 'Cleaning resource files at ' + platformDir);
-
- var resourceMap = {};
- files.forEach(function(res) {
- var filePath = path.join(platformDir, res.target);
- resourceMap[filePath] = null;
- });
-
- FileUpdater.updatePaths(
- resourceMap, { rootDir: projectRoot, all: true}, logFileOp);
- }
-}
-
-/**
- * Gets and validates 'AndroidLaunchMode' prepference from config.xml. Returns
- * preference value and warns if it doesn't seems to be valid
- *
- * @param {ConfigParser} platformConfig A configParser instance for
- * platform.
- *
- * @return {String} Preference's value from config.xml or
- * default value, if there is no such preference. The default value is
- * 'singleTop'
- */
-function findAndroidLaunchModePreference(platformConfig) {
- var launchMode = platformConfig.getPreference('AndroidLaunchMode');
- if (!launchMode) {
- // Return a default value
- return 'singleTop';
- }
-
- var expectedValues = ['standard', 'singleTop', 'singleTask', 'singleInstance'];
- var valid = expectedValues.indexOf(launchMode) >= 0;
- if (!valid) {
- // Note: warn, but leave the launch mode as developer wanted, in case the list of options changes in the future
- events.emit('warn', 'Unrecognized value for AndroidLaunchMode preference: ' +
- launchMode + '. Expected values are: ' + expectedValues.join(', '));
- }
-
- return launchMode;
-}
diff --git a/StoneIsland/platforms/android/cordova/lib/retry.js b/StoneIsland/platforms/android/cordova/lib/retry.js
deleted file mode 100644
index 3cb49274..00000000
--- a/StoneIsland/platforms/android/cordova/lib/retry.js
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/* jshint node: true */
-
-'use strict';
-
-var events = require('cordova-common').events;
-
-/*
- * Retry a promise-returning function a number of times, propagating its
- * results on success or throwing its error on a failed final attempt.
- *
- * @arg {Number} attemts_left - The number of times to retry the passed call.
- * @arg {Function} promiseFunction - A function that returns a promise.
- * @arg {...} - Arguments to pass to promiseFunction.
- *
- * @returns {Promise}
- */
-module.exports.retryPromise = function (attemts_left, promiseFunction) {
-
- // NOTE:
- // get all trailing arguments, by skipping the first two (attemts_left and
- // promiseFunction) because they shouldn't get passed to promiseFunction
- var promiseFunctionArguments = Array.prototype.slice.call(arguments, 2);
-
- return promiseFunction.apply(undefined, promiseFunctionArguments).then(
-
- // on success pass results through
- function onFulfilled(value) {
- return value;
- },
-
- // on rejection either retry, or throw the error
- function onRejected(error) {
-
- attemts_left -= 1;
-
- if (attemts_left < 1) {
- throw error;
- }
-
- events.emit('verbose', 'A retried call failed. Retrying ' + attemts_left + ' more time(s).');
-
- // retry call self again with the same arguments, except attemts_left is now lower
- var fullArguments = [attemts_left, promiseFunction].concat(promiseFunctionArguments);
- return module.exports.retryPromise.apply(undefined, fullArguments);
- }
- );
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/run.js b/StoneIsland/platforms/android/cordova/lib/run.js
deleted file mode 100644
index 214a1e19..00000000
--- a/StoneIsland/platforms/android/cordova/lib/run.js
+++ /dev/null
@@ -1,141 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/* jshint loopfunc:true */
-
-var path = require('path'),
- build = require('./build'),
- emulator = require('./emulator'),
- device = require('./device'),
- Q = require('q'),
- events = require('cordova-common').events;
-
-function getInstallTarget(runOptions) {
- var install_target;
- if (runOptions.target) {
- install_target = runOptions.target;
- } else if (runOptions.device) {
- install_target = '--device';
- } else if (runOptions.emulator) {
- install_target = '--emulator';
- }
-
- return install_target;
-}
-
-/**
- * Runs the application on a device if available. If no device is found, it will
- * use a started emulator. If no started emulators are found it will attempt
- * to start an avd. If no avds are found it will error out.
- *
- * @param {Object} runOptions various run/build options. See Api.js build/run
- * methods for reference.
- *
- * @return {Promise}
- */
- module.exports.run = function(runOptions) {
-
- var self = this;
- var install_target = getInstallTarget(runOptions);
-
- return Q()
- .then(function() {
- if (!install_target) {
- // no target given, deploy to device if available, otherwise use the emulator.
- return device.list()
- .then(function(device_list) {
- if (device_list.length > 0) {
- events.emit('warn', 'No target specified, deploying to device \'' + device_list[0] + '\'.');
- install_target = device_list[0];
- } else {
- events.emit('warn', 'No target specified and no devices found, deploying to emulator');
- install_target = '--emulator';
- }
- });
- }
- }).then(function() {
- if (install_target == '--device') {
- return device.resolveTarget(null);
- } else if (install_target == '--emulator') {
- // Give preference to any already started emulators. Else, start one.
- return emulator.list_started()
- .then(function(started) {
- return started && started.length > 0 ? started[0] : emulator.start();
- }).then(function(emulatorId) {
- return emulator.resolveTarget(emulatorId);
- });
- }
- // They specified a specific device/emulator ID.
- return device.list()
- .then(function(devices) {
- if (devices.indexOf(install_target) > -1) {
- return device.resolveTarget(install_target);
- }
- return emulator.list_started()
- .then(function(started_emulators) {
- if (started_emulators.indexOf(install_target) > -1) {
- return emulator.resolveTarget(install_target);
- }
- return emulator.list_images()
- .then(function(avds) {
- // if target emulator isn't started, then start it.
- for (var avd in avds) {
- if (avds[avd].name == install_target) {
- return emulator.start(install_target)
- .then(function(emulatorId) {
- return emulator.resolveTarget(emulatorId);
- });
- }
- }
- return Q.reject('Target \'' + install_target + '\' not found, unable to run project');
- });
- });
- });
- }).then(function(resolvedTarget) {
- // Better just call self.build, but we're doing some processing of
- // build results (according to platformApi spec) so they are in different
- // format than emulator.install expects.
- // TODO: Update emulator/device.install to handle this change
- return build.run.call(self, runOptions, resolvedTarget)
- .then(function(buildResults) {
- if (resolvedTarget.isEmulator) {
- return emulator.wait_for_boot(resolvedTarget.target)
- .then(function () {
- return emulator.install(resolvedTarget, buildResults);
- });
- }
- return device.install(resolvedTarget, buildResults);
- });
- });
-};
-
-module.exports.help = function() {
- console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]) + ' [options]');
- console.log('Build options :');
- console.log(' --debug : Builds project in debug mode');
- console.log(' --release : Builds project in release mode');
- console.log(' --nobuild : Runs the currently built project without recompiling');
- console.log('Deploy options :');
- console.log(' --device : Will deploy the built project to a device');
- console.log(' --emulator : Will deploy the built project to an emulator if one exists');
- console.log(' --target=<target_id> : Installs to the target with the specified id.');
- process.exit(0);
-};
diff --git a/StoneIsland/platforms/android/cordova/lib/start-emulator b/StoneIsland/platforms/android/cordova/lib/start-emulator
deleted file mode 100755
index f96bdc3e..00000000
--- a/StoneIsland/platforms/android/cordova/lib/start-emulator
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-var emulator = require('./emulator'),
- args = process.argv;
-
-var install_target;
-if(args.length > 2) {
- if (args[2].substring(0, 9) == '--target=') {
- install_target = args[2].substring(9, args[2].length);
- } else {
- console.error('ERROR : argument \'' + args[2] + '\' not recognized.');
- process.exit(2);
- }
-}
-
-emulator.start(install_target).done(null, function(err) {
- console.error('ERROR: ' + err);
- process.exit(2);
-});
-
diff --git a/StoneIsland/platforms/android/cordova/lib/start-emulator.bat b/StoneIsland/platforms/android/cordova/lib/start-emulator.bat
deleted file mode 100644
index 9329d951..00000000
--- a/StoneIsland/platforms/android/cordova/lib/start-emulator.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0start-emulator"
-IF EXIST %script_path% (
- node "%script_path%" %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'start-emulator' script in 'cordova\lib' folder, aborting...>&2
- EXIT /B 1
-) \ No newline at end of file