use cordova, not phonegap
This commit is contained in:
		
							parent
							
								
									445ddeab85
								
							
						
					
					
						commit
						72c3cd0c06
					
				
					 364 changed files with 55371 additions and 0 deletions
				
			
		
							
								
								
									
										65
									
								
								fritteliuhr/platforms/android/cordova/lib/android_sdk_version.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								fritteliuhr/platforms/android/cordova/lib/android_sdk_version.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,65 @@
 | 
			
		|||
#!/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 shell = require('shelljs'),
 | 
			
		||||
    child_process = require('child_process'),
 | 
			
		||||
    Q     = require('q');
 | 
			
		||||
 | 
			
		||||
get_highest_sdk = function(results){
 | 
			
		||||
    var reg = /\d+/;
 | 
			
		||||
    var apiLevels = [];
 | 
			
		||||
    for(var i=0;i<results.length;i++){
 | 
			
		||||
        apiLevels[i] = parseInt(results[i].match(reg)[0]);
 | 
			
		||||
    }
 | 
			
		||||
    apiLevels.sort(function(a,b){return b-a});
 | 
			
		||||
    console.log(apiLevels[0]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get_sdks = function() {
 | 
			
		||||
    var d = Q.defer();
 | 
			
		||||
    child_process.exec('android list targets', function(err, stdout, stderr) {
 | 
			
		||||
        if (err) d.reject(stderr);
 | 
			
		||||
        else d.resolve(stdout);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return d.promise.then(function(output) {
 | 
			
		||||
        var reg = /android-\d+/gi;
 | 
			
		||||
        var results = output.match(reg);
 | 
			
		||||
        if(results.length===0){
 | 
			
		||||
            return Q.reject(new Error('No android sdks installed.'));
 | 
			
		||||
        }else{
 | 
			
		||||
            get_highest_sdk(results);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Q();
 | 
			
		||||
    }, function(stderr) {
 | 
			
		||||
        if (stderr.match(/command\snot\sfound/) || stderr.match(/'android' is not recognized/)) {
 | 
			
		||||
            return Q.reject(new Error('The command \"android\" failed. Make sure you have the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) is added to your path.'));
 | 
			
		||||
        } else {
 | 
			
		||||
            return Q.reject(new Error('An error occurred while listing Android targets'));
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.run = function() {
 | 
			
		||||
    return Q.all([get_sdks()]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										41
									
								
								fritteliuhr/platforms/android/cordova/lib/appinfo.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								fritteliuhr/platforms/android/cordova/lib/appinfo.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
#!/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');
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
var cachedAppInfo = null;
 | 
			
		||||
 | 
			
		||||
function readAppInfoFromManifest() {
 | 
			
		||||
    var manifestPath = path.join(__dirname, '..', '..', 'AndroidManifest.xml');
 | 
			
		||||
    var manifestData = fs.readFileSync(manifestPath, {encoding:'utf8'});
 | 
			
		||||
    var packageName = /\bpackage\s*=\s*"(.+?)"/.exec(manifestData);
 | 
			
		||||
    if (!packageName) throw new Error('Could not find package name within ' + manifestPath);
 | 
			
		||||
    var activityTag = /<activity\b[\s\S]*<\/activity>/.exec(manifestData);
 | 
			
		||||
    if (!activityTag) throw new Error('Could not find <activity> within ' + manifestPath);
 | 
			
		||||
    var activityName = /\bandroid:name\s*=\s*"(.+?)"/.exec(activityTag);
 | 
			
		||||
    if (!activityName) throw new Error('Could not find android:name within ' + manifestPath);
 | 
			
		||||
 | 
			
		||||
    return packageName[1] + '/.' + activityName[1];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.getActivityName = function() {
 | 
			
		||||
    return cachedAppInfo = cachedAppInfo || readAppInfoFromManifest();
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										481
									
								
								fritteliuhr/platforms/android/cordova/lib/build.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										481
									
								
								fritteliuhr/platforms/android/cordova/lib/build.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,481 @@
 | 
			
		|||
#!/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 shell   = require('shelljs'),
 | 
			
		||||
    spawn   = require('./spawn'),
 | 
			
		||||
    Q       = require('q'),
 | 
			
		||||
    path    = require('path'),
 | 
			
		||||
    fs      = require('fs'),
 | 
			
		||||
    os      = require('os'),
 | 
			
		||||
    ROOT    = path.join(__dirname, '..', '..');
 | 
			
		||||
var check_reqs = require('./check_reqs');
 | 
			
		||||
var exec  = require('./exec');
 | 
			
		||||
 | 
			
		||||
var LOCAL_PROPERTIES_TEMPLATE =
 | 
			
		||||
    '# This file is automatically generated.\n' +
 | 
			
		||||
    '# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n';
 | 
			
		||||
 | 
			
		||||
function findApks(directory) {
 | 
			
		||||
    var ret = [];
 | 
			
		||||
    if (fs.existsSync(directory)) {
 | 
			
		||||
        fs.readdirSync(directory).forEach(function(p) {
 | 
			
		||||
            if (path.extname(p) == '.apk') {
 | 
			
		||||
                ret.push(path.join(directory, p));
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function sortFilesByDate(files) {
 | 
			
		||||
    return files.map(function(p) {
 | 
			
		||||
        return { p: p, t: fs.statSync(p).mtime };
 | 
			
		||||
    }).sort(function(a, b) {
 | 
			
		||||
        var timeDiff = b.t - a.t;
 | 
			
		||||
        return timeDiff === 0 ? a.p.length - b.p.length : timeDiff;
 | 
			
		||||
    }).map(function(p) { return p.p; });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function findOutputApksHelper(dir, build_type, arch) {
 | 
			
		||||
    var ret = findApks(dir).filter(function(candidate) {
 | 
			
		||||
        // Need to choose between release and debug .apk.
 | 
			
		||||
        if (build_type === 'debug') {
 | 
			
		||||
            return /-debug/.exec(candidate) && !/-unaligned|-unsigned/.exec(candidate);
 | 
			
		||||
        }
 | 
			
		||||
        if (build_type === 'release') {
 | 
			
		||||
            return /-release/.exec(candidate) && !/-unaligned/.exec(candidate);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    });
 | 
			
		||||
    ret = sortFilesByDate(ret);
 | 
			
		||||
    if (ret.length === 0) {
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    // Assume arch-specific build if newest api has -x86 or -arm.
 | 
			
		||||
    var archSpecific = !!/-x86|-arm/.exec(ret[0]);
 | 
			
		||||
    // And show only arch-specific ones (or non-arch-specific)
 | 
			
		||||
    ret = ret.filter(function(p) {
 | 
			
		||||
        return !!/-x86|-arm/.exec(p) == archSpecific;
 | 
			
		||||
    });
 | 
			
		||||
    if (arch && ret.length > 1) {
 | 
			
		||||
        ret = ret.filter(function(p) {
 | 
			
		||||
            return p.indexOf('-' + arch) != -1;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function hasCustomRules() {
 | 
			
		||||
    return fs.existsSync(path.join(ROOT, 'custom_rules.xml'));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function extractProjectNameFromManifest(projectPath) {
 | 
			
		||||
    var manifestPath = path.join(projectPath, 'AndroidManifest.xml');
 | 
			
		||||
    var manifestData = fs.readFileSync(manifestPath, 'utf8');
 | 
			
		||||
    var m = /<activity[\s\S]*?android:name\s*=\s*"(.*?)"/i.exec(manifestData);
 | 
			
		||||
    if (!m) {
 | 
			
		||||
        throw new Error('Could not find activity name in ' + manifestPath);
 | 
			
		||||
    }
 | 
			
		||||
    return m[1];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function extractSubProjectPaths() {
 | 
			
		||||
    var data = fs.readFileSync(path.join(ROOT, 'project.properties'), 'utf8');
 | 
			
		||||
    var ret = {};
 | 
			
		||||
    var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg
 | 
			
		||||
    var m;
 | 
			
		||||
    while (m = r.exec(data)) {
 | 
			
		||||
        ret[m[1]] = 1;
 | 
			
		||||
    }
 | 
			
		||||
    return Object.keys(ret);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var builders = {
 | 
			
		||||
    ant: {
 | 
			
		||||
        getArgs: function(cmd) {
 | 
			
		||||
            var args = [cmd, '-f', path.join(ROOT, 'build.xml')];
 | 
			
		||||
            // custom_rules.xml is required for incremental builds.
 | 
			
		||||
            if (hasCustomRules()) {
 | 
			
		||||
                args.push('-Dout.dir=ant-build', '-Dgen.absolute.dir=ant-gen');
 | 
			
		||||
            }
 | 
			
		||||
            return args;
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        prepEnv: function() {
 | 
			
		||||
            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.
 | 
			
		||||
                var sdkDir = process.env['ANDROID_HOME'];
 | 
			
		||||
                var buildTemplate = fs.readFileSync(path.join(sdkDir, 'tools', 'lib', 'build.template'), 'utf8');
 | 
			
		||||
                function writeBuildXml(projectPath) {
 | 
			
		||||
                    var newData = buildTemplate.replace('PROJECT_NAME', extractProjectNameFromManifest(ROOT));
 | 
			
		||||
                    fs.writeFileSync(path.join(projectPath, 'build.xml'), newData);
 | 
			
		||||
                    if (!fs.existsSync(path.join(projectPath, 'local.properties'))) {
 | 
			
		||||
                        fs.writeFileSync(path.join(projectPath, 'local.properties'), LOCAL_PROPERTIES_TEMPLATE);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                var subProjects = extractSubProjectPaths();
 | 
			
		||||
                writeBuildXml(ROOT);
 | 
			
		||||
                for (var i = 0; i < subProjects.length; ++i) {
 | 
			
		||||
                    writeBuildXml(path.join(ROOT, subProjects[i]));
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Builds the project with ant.
 | 
			
		||||
         * Returns a promise.
 | 
			
		||||
         */
 | 
			
		||||
        build: function(build_type) {
 | 
			
		||||
            // Without our custom_rules.xml, we need to clean before building.
 | 
			
		||||
            var ret = Q();
 | 
			
		||||
            if (!hasCustomRules()) {
 | 
			
		||||
                // clean will call check_ant() for us.
 | 
			
		||||
                ret = this.clean();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var builder = this;
 | 
			
		||||
            var args = this.getArgs(build_type == 'debug' ? 'debug' : 'release');
 | 
			
		||||
            return check_reqs.check_ant()
 | 
			
		||||
            .then(function() {
 | 
			
		||||
                return spawn('ant', args);
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        clean: function() {
 | 
			
		||||
            var args = this.getArgs('clean');
 | 
			
		||||
            return check_reqs.check_ant()
 | 
			
		||||
            .then(function() {
 | 
			
		||||
                return spawn('ant', args);
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        findOutputApks: function(build_type) {
 | 
			
		||||
            var binDir = path.join(ROOT, hasCustomRules() ? 'ant-build' : 'bin');
 | 
			
		||||
            return findOutputApksHelper(binDir, build_type, null);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    gradle: {
 | 
			
		||||
        getArgs: function(cmd, arch, extraArgs) {
 | 
			
		||||
            if (cmd == 'release') {
 | 
			
		||||
                cmd = 'cdvBuildRelease';
 | 
			
		||||
            } else if (cmd == 'debug') {
 | 
			
		||||
                cmd = 'cdvBuildDebug';
 | 
			
		||||
            }
 | 
			
		||||
            var args = [cmd, '-b', path.join(ROOT, 'build.gradle')];
 | 
			
		||||
            if (arch) {
 | 
			
		||||
                args.push('-PcdvBuildArch=' + arch);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 10 seconds -> 6 seconds
 | 
			
		||||
            args.push('-Dorg.gradle.daemon=true');
 | 
			
		||||
            args.push.apply(args, extraArgs);
 | 
			
		||||
            // Shaves another 100ms, but produces a "try at own risk" warning. Not worth it (yet):
 | 
			
		||||
            // args.push('-Dorg.gradle.parallel=true');
 | 
			
		||||
            return args;
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        prepEnv: function() {
 | 
			
		||||
            return check_reqs.check_gradle()
 | 
			
		||||
            .then(function() {
 | 
			
		||||
                // Copy the gradle wrapper 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.
 | 
			
		||||
                var projectPath = ROOT;
 | 
			
		||||
                // check_reqs ensures that this is set.
 | 
			
		||||
                var sdkDir = process.env['ANDROID_HOME'];
 | 
			
		||||
                var wrapperDir = path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper');
 | 
			
		||||
                if (process.platform == 'win32') {
 | 
			
		||||
                    shell.cp('-f', path.join(wrapperDir, 'gradlew.bat'), projectPath);
 | 
			
		||||
                } else {
 | 
			
		||||
                    shell.cp('-f', path.join(wrapperDir, 'gradlew'), projectPath);
 | 
			
		||||
                }
 | 
			
		||||
                shell.rm('-rf', path.join(projectPath, 'gradle', 'wrapper'));
 | 
			
		||||
                shell.mkdir('-p', path.join(projectPath, 'gradle'));
 | 
			
		||||
                shell.cp('-r', path.join(wrapperDir, 'gradle', 'wrapper'), path.join(projectPath, '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/;
 | 
			
		||||
                var distributionUrl = 'distributionUrl=http\\://services.gradle.org/distributions/gradle-2.2.1-all.zip';
 | 
			
		||||
                var gradleWrapperPropertiesPath = path.join(projectPath, 'gradle', 'wrapper', 'gradle-wrapper.properties');
 | 
			
		||||
                shell.sed('-i', distributionUrlRegex, distributionUrl, gradleWrapperPropertiesPath);
 | 
			
		||||
 | 
			
		||||
                // Update the version of build.gradle in each dependent library.
 | 
			
		||||
                var pluginBuildGradle = path.join(projectPath, 'cordova', 'lib', 'plugin-build.gradle');
 | 
			
		||||
                var subProjects = extractSubProjectPaths();
 | 
			
		||||
                for (var i = 0; i < subProjects.length; ++i) {
 | 
			
		||||
                    if (subProjects[i] !== 'CordovaLib') {
 | 
			
		||||
                        shell.cp('-f', pluginBuildGradle, path.join(ROOT, subProjects[i], 'build.gradle'));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var subProjectsAsGradlePaths = subProjects.map(function(p) { return ':' + p.replace(/[/\\]/g, ':') });
 | 
			
		||||
                // Write the settings.gradle file.
 | 
			
		||||
                fs.writeFileSync(path.join(projectPath, 'settings.gradle'),
 | 
			
		||||
                    '// GENERATED FILE - DO NOT EDIT\n' +
 | 
			
		||||
                    'include ":"\n' +
 | 
			
		||||
                    'include "' + subProjectsAsGradlePaths.join('"\ninclude "') + '"\n');
 | 
			
		||||
                // Update dependencies within build.gradle.
 | 
			
		||||
                var buildGradle = fs.readFileSync(path.join(projectPath, 'build.gradle'), 'utf8');
 | 
			
		||||
                var depsList = '';
 | 
			
		||||
                subProjectsAsGradlePaths.forEach(function(p) {
 | 
			
		||||
                    depsList += '    debugCompile project(path: "' + p + '", configuration: "debug")\n';
 | 
			
		||||
                    depsList += '    releaseCompile project(path: "' + p + '", configuration: "release")\n';
 | 
			
		||||
                });
 | 
			
		||||
                buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/ SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + '    $2');
 | 
			
		||||
                fs.writeFileSync(path.join(projectPath, 'build.gradle'), buildGradle);
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Builds the project with gradle.
 | 
			
		||||
         * Returns a promise.
 | 
			
		||||
         */
 | 
			
		||||
        build: function(build_type, arch, extraArgs) {
 | 
			
		||||
            var builder = this;
 | 
			
		||||
            var wrapper = path.join(ROOT, 'gradlew');
 | 
			
		||||
            var args = this.getArgs(build_type == 'debug' ? 'debug' : 'release', arch, extraArgs);
 | 
			
		||||
            return Q().then(function() {
 | 
			
		||||
                console.log('Running: ' + wrapper + ' ' + args.concat(extraArgs).join(' '));
 | 
			
		||||
                return spawn(wrapper, args);
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        clean: function(extraArgs) {
 | 
			
		||||
            var builder = this;
 | 
			
		||||
            var wrapper = path.join(ROOT, 'gradlew');
 | 
			
		||||
            var args = builder.getArgs('clean', null, extraArgs);
 | 
			
		||||
            return Q().then(function() {
 | 
			
		||||
                console.log('Running: ' + wrapper + ' ' + args.concat(extraArgs).join(' '));
 | 
			
		||||
                return spawn(wrapper, args);
 | 
			
		||||
            });
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        findOutputApks: function(build_type, arch) {
 | 
			
		||||
            var binDir = path.join(ROOT, 'build', 'outputs', 'apk');
 | 
			
		||||
            return findOutputApksHelper(binDir, build_type, arch);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    none: {
 | 
			
		||||
        prepEnv: function() {
 | 
			
		||||
            return Q();
 | 
			
		||||
        },
 | 
			
		||||
        build: function() {
 | 
			
		||||
            console.log('Skipping build...');
 | 
			
		||||
            return Q(null);
 | 
			
		||||
        },
 | 
			
		||||
        clean: function() {
 | 
			
		||||
            return Q();
 | 
			
		||||
        },
 | 
			
		||||
        findOutputApks: function(build_type, arch) {
 | 
			
		||||
            return sortFilesByDate(builders.ant.findOutputApks(build_type, arch).concat(builders.gradle.findOutputApks(build_type, arch)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function parseOpts(options, resolvedTarget) {
 | 
			
		||||
    // Backwards-compatibility: Allow a single string argument
 | 
			
		||||
    if (typeof options == "string") options = [options];
 | 
			
		||||
 | 
			
		||||
    var ret = {
 | 
			
		||||
        buildType: 'debug',
 | 
			
		||||
        buildMethod: process.env['ANDROID_BUILD'] || 'ant',
 | 
			
		||||
        arch: null,
 | 
			
		||||
        extraArgs: []
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var multiValueArgs = {
 | 
			
		||||
      'versionCode': true,
 | 
			
		||||
      'minSdkVersion': true,
 | 
			
		||||
      'gradleArg': true
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Iterate through command line options
 | 
			
		||||
    for (var i=0; options && (i < options.length); ++i) {
 | 
			
		||||
        if (/^--/.exec(options[i])) {
 | 
			
		||||
            var keyValue = options[i].substring(2).split('=');
 | 
			
		||||
            var flagName = keyValue.shift();
 | 
			
		||||
            var flagValue = keyValue.join('=');
 | 
			
		||||
            if (multiValueArgs[flagName] && !flagValue) {
 | 
			
		||||
                flagValue = options[i + 1];
 | 
			
		||||
                ++i;
 | 
			
		||||
            }
 | 
			
		||||
            switch(flagName) {
 | 
			
		||||
                case 'debug':
 | 
			
		||||
                case 'release':
 | 
			
		||||
                    ret.buildType = flagName;
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'ant':
 | 
			
		||||
                case 'gradle':
 | 
			
		||||
                    ret.buildMethod = flagName;
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'device':
 | 
			
		||||
                case 'emulator':
 | 
			
		||||
                    // Don't need to do anything special to when building for device vs emulator.
 | 
			
		||||
                    // iOS uses this flag to switch on architecture.
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'nobuild' :
 | 
			
		||||
                    ret.buildMethod = 'none';
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'versionCode':
 | 
			
		||||
                    ret.extraArgs.push('-PcdvVersionCode=' + flagValue);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'minSdkVersion':
 | 
			
		||||
                    ret.extraArgs.push('-PcdvMinSdkVersion=' + flagValue);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'gradleArg':
 | 
			
		||||
                    ret.extraArgs.push(flagValue);
 | 
			
		||||
                    break;
 | 
			
		||||
                default :
 | 
			
		||||
                    console.warn('Build option --\'' + flagName + '\' not recognized (ignoring).');
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            console.warn('Build option \'' + options[i] + '\' not recognized (ignoring).');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ret.arch = resolvedTarget && resolvedTarget.arch;
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Builds the project with the specifed options
 | 
			
		||||
 * Returns a promise.
 | 
			
		||||
 */
 | 
			
		||||
module.exports.runClean = function(options) {
 | 
			
		||||
    var opts = parseOpts(options);
 | 
			
		||||
    var builder = builders[opts.buildMethod];
 | 
			
		||||
    return builder.prepEnv()
 | 
			
		||||
    .then(function() {
 | 
			
		||||
        return builder.clean(opts.extraArgs);
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        shell.rm('-rf', path.join(ROOT, 'out'));
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Builds the project with the specifed options
 | 
			
		||||
 * Returns a promise.
 | 
			
		||||
 */
 | 
			
		||||
module.exports.run = function(options, optResolvedTarget) {
 | 
			
		||||
    var opts = parseOpts(options, optResolvedTarget);
 | 
			
		||||
    var builder = builders[opts.buildMethod];
 | 
			
		||||
    return builder.prepEnv()
 | 
			
		||||
    .then(function() {
 | 
			
		||||
        return builder.build(opts.buildType, opts.arch, opts.extraArgs);
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        var apkPaths = builder.findOutputApks(opts.buildType, opts.arch);
 | 
			
		||||
        console.log('Built the following apk(s):');
 | 
			
		||||
        console.log('    ' + apkPaths.join('\n    '));
 | 
			
		||||
        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 exec('adb -s ' + target + ' shell cat /proc/cpuinfo', os.tmpdir())
 | 
			
		||||
        .then(function(output) {
 | 
			
		||||
            if (/intel/i.exec(output)) {
 | 
			
		||||
                return 'x86';
 | 
			
		||||
            }
 | 
			
		||||
            return '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, '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.
 | 
			
		||||
            return exec('killall adb')
 | 
			
		||||
            .then(function() {
 | 
			
		||||
                console.log('adb seems hung. retrying.');
 | 
			
		||||
                return helper()
 | 
			
		||||
                .then(null, function() {
 | 
			
		||||
                    // The double kill is sadly often necessary, at least on mac.
 | 
			
		||||
                    console.log('Now device not found... restarting adb again.');
 | 
			
		||||
                    return exec('killall adb')
 | 
			
		||||
                    .then(function() {
 | 
			
		||||
                        return helper()
 | 
			
		||||
                        .then(null, function() {
 | 
			
		||||
                            return Q.reject('USB is flakey. 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) {
 | 
			
		||||
        if (buildResults.buildType == 'debug') {
 | 
			
		||||
            return /-debug/.exec(p);
 | 
			
		||||
        }
 | 
			
		||||
        return !/-debug/.exec(p);
 | 
			
		||||
    });
 | 
			
		||||
    var archPattern = new RegExp('-' + arch);
 | 
			
		||||
    var hasArchPattern = /-x86|-arm/;
 | 
			
		||||
    for (var i = 0; i < paths.length; ++i) {
 | 
			
		||||
        if (hasArchPattern.exec(paths[i])) {
 | 
			
		||||
            if (archPattern.exec(paths[i])) {
 | 
			
		||||
                return paths[i];
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            return paths[i];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    throw new Error('Could not find apk architecture: ' + arch + ' build-type: ' + buildResults.buildType);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports.help = function() {
 | 
			
		||||
    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'cordova', 'build')) + ' [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 (default)');
 | 
			
		||||
    console.log('    \'--gradle\': will build project with gradle');
 | 
			
		||||
    console.log('    \'--nobuild\': will skip build process (useful when using run command)');
 | 
			
		||||
    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');
 | 
			
		||||
    process.exit(0);
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										242
									
								
								fritteliuhr/platforms/android/cordova/lib/check_reqs.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										242
									
								
								fritteliuhr/platforms/android/cordova/lib/check_reqs.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,242 @@
 | 
			
		|||
#!/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 shelljs = require('shelljs'),
 | 
			
		||||
    child_process = require('child_process'),
 | 
			
		||||
    Q     = require('q'),
 | 
			
		||||
    path  = require('path'),
 | 
			
		||||
    fs    = require('fs'),
 | 
			
		||||
    which = require('which'),
 | 
			
		||||
    ROOT  = path.join(__dirname, '..', '..');
 | 
			
		||||
 | 
			
		||||
var isWindows = process.platform == 'win32';
 | 
			
		||||
 | 
			
		||||
function forgivingWhichSync(cmd) {
 | 
			
		||||
    try {
 | 
			
		||||
        return fs.realpathSync(which.sync(cmd));
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        return '';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function tryCommand(cmd, errMsg) {
 | 
			
		||||
    var d = Q.defer();
 | 
			
		||||
    child_process.exec(cmd, function(err, stdout, stderr) {
 | 
			
		||||
        if (err) d.reject(new Error(errMsg));
 | 
			
		||||
        else d.resolve(stdout);
 | 
			
		||||
    });
 | 
			
		||||
    return d.promise;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get valid target from framework/project.properties
 | 
			
		||||
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();
 | 
			
		||||
    }
 | 
			
		||||
    if (fs.existsSync(path.join(ROOT, 'framework', 'project.properties'))) {
 | 
			
		||||
        return extractFromFile(path.join(ROOT, 'framework', 'project.properties'));
 | 
			
		||||
    }
 | 
			
		||||
    if (fs.existsSync(path.join(ROOT, 'project.properties'))) {
 | 
			
		||||
        // if no target found, we're probably in a project and project.properties is in ROOT.
 | 
			
		||||
        return extractFromFile(path.join(ROOT, 'project.properties'));
 | 
			
		||||
    }
 | 
			
		||||
    throw new Error('Could not find android target. File missing: ' + path.join(ROOT, 'project.properties'));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a promise. Called only by build and clean commands.
 | 
			
		||||
module.exports.check_ant = function() {
 | 
			
		||||
    return tryCommand('ant -version', 'Failed to run "ant -version", make sure you have ant installed and added to your PATH.');
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Returns a promise. Called only by build and clean commands.
 | 
			
		||||
module.exports.check_gradle = function() {
 | 
			
		||||
    var sdkDir = process.env['ANDROID_HOME'];
 | 
			
		||||
    var wrapperDir = path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper');
 | 
			
		||||
    if (!fs.existsSync(wrapperDir)) {
 | 
			
		||||
        return Q.reject(new Error('Could not find gradle wrapper within android sdk. Might need to update your Android SDK.\n' +
 | 
			
		||||
            'Looked here: ' + wrapperDir));
 | 
			
		||||
    }
 | 
			
		||||
    return Q.when();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// 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.
 | 
			
		||||
                if (fs.existsSync('/usr/libexec/java_home')) {
 | 
			
		||||
                    return tryCommand('/usr/libexec/java_home', 'Failed to run: /usr/libexec/java_home')
 | 
			
		||||
                    .then(function(stdout) {
 | 
			
		||||
                        process.env['JAVA_HOME'] = stdout.trim();
 | 
			
		||||
                    });
 | 
			
		||||
                } 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 Error('Could not find JAVA_HOME. Try setting the environment variable manually');
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else if (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 "java -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';
 | 
			
		||||
        }
 | 
			
		||||
        return tryCommand('java -version', msg)
 | 
			
		||||
        .then(function() {
 | 
			
		||||
            return tryCommand('javac -version', msg);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a promise.
 | 
			
		||||
module.exports.check_android = function() {
 | 
			
		||||
    return Q().then(function() {
 | 
			
		||||
        var androidCmdPath = forgivingWhichSync('android');
 | 
			
		||||
        var adbInPath = !!forgivingWhichSync('adb');
 | 
			
		||||
        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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!hasAndroidHome && !androidCmdPath) {
 | 
			
		||||
            if (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 (process.platform == 'darwin') {
 | 
			
		||||
                // 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 && !androidCmdPath) {
 | 
			
		||||
            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools');
 | 
			
		||||
        }
 | 
			
		||||
        if (androidCmdPath && !hasAndroidHome) {
 | 
			
		||||
            var parentDir = path.dirname(androidCmdPath);
 | 
			
		||||
            var grandParentDir = path.dirname(parentDir);
 | 
			
		||||
            if (path.basename(parentDir) == 'tools') {
 | 
			
		||||
                process.env['ANDROID_HOME'] = path.dirname(parentDir);
 | 
			
		||||
                hasAndroidHome = true;
 | 
			
		||||
            } else if (fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
 | 
			
		||||
                process.env['ANDROID_HOME'] = grandParentDir;
 | 
			
		||||
                hasAndroidHome = true;
 | 
			
		||||
            } else {
 | 
			
		||||
                throw new Error('ANDROID_HOME is not set and no "tools" directory found at ' + parentDir);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (hasAndroidHome && !adbInPath) {
 | 
			
		||||
            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'platform-tools');
 | 
			
		||||
        }
 | 
			
		||||
        if (!process.env['ANDROID_HOME']) {
 | 
			
		||||
            throw new Error('ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.');
 | 
			
		||||
        }
 | 
			
		||||
        if (!fs.existsSync(process.env['ANDROID_HOME'])) {
 | 
			
		||||
            throw new Error('ANDROID_HOME is set to a non-existant path: ' + process.env['ANDROID_HOME']);
 | 
			
		||||
        }
 | 
			
		||||
        // Check that the target sdk level is installed.
 | 
			
		||||
        return module.exports.check_android_target(module.exports.get_target());
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports.getAbsoluteAndroidCmd = function() {
 | 
			
		||||
    return forgivingWhichSync('android').replace(/(\s)/g, '\\$1');
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports.check_android_target = function(valid_target) {
 | 
			
		||||
    // valid_target can look like:
 | 
			
		||||
    //   android-19
 | 
			
		||||
    //   android-L
 | 
			
		||||
    //   Google Inc.:Google APIs:20
 | 
			
		||||
    //   Google Inc.:Glass Development Kit Preview:20
 | 
			
		||||
    var msg = 'Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.';
 | 
			
		||||
    return tryCommand('android list targets --compact', msg)
 | 
			
		||||
    .then(function(output) {
 | 
			
		||||
        if (output.split('\n').indexOf(valid_target) == -1) {
 | 
			
		||||
            var androidCmd = module.exports.getAbsoluteAndroidCmd();
 | 
			
		||||
            throw new Error('Please install Android target: "' + valid_target + '".\n\n' +
 | 
			
		||||
                'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
 | 
			
		||||
                'You will require:\n' +
 | 
			
		||||
                '1. "SDK Platform" for ' + valid_target + '\n' +
 | 
			
		||||
                '2. "Android SDK Platform-tools (latest)\n' +
 | 
			
		||||
                '3. "Android SDK Build-tools" (latest)');
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Returns a promise.
 | 
			
		||||
module.exports.run = function() {
 | 
			
		||||
    return Q.all([this.check_java(), this.check_android()]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										123
									
								
								fritteliuhr/platforms/android/cordova/lib/device.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								fritteliuhr/platforms/android/cordova/lib/device.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,123 @@
 | 
			
		|||
#!/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 exec  = require('./exec'),
 | 
			
		||||
    Q     = require('q'),
 | 
			
		||||
    path  = require('path'),
 | 
			
		||||
    os    = require('os'),
 | 
			
		||||
    build = require('./build'),
 | 
			
		||||
    appinfo = require('./appinfo'),
 | 
			
		||||
    ROOT = path.join(__dirname, '..', '..');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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) {
 | 
			
		||||
    function helper() {
 | 
			
		||||
        return exec('adb devices', os.tmpdir())
 | 
			
		||||
        .then(function(output) {
 | 
			
		||||
            var response = output.split('\n');
 | 
			
		||||
            var device_list = [];
 | 
			
		||||
            for (var i = 1; i < response.length; i++) {
 | 
			
		||||
                if (response[i].match(/\w+\tdevice/) && !response[i].match(/emulator/)) {
 | 
			
		||||
                    device_list.push(response[i].replace(/\tdevice/, '').replace('\r', ''));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return device_list;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    return helper()
 | 
			
		||||
    .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 exec('killall adb')
 | 
			
		||||
            .then(function() {
 | 
			
		||||
                console.log('Restarting adb to see if more devices are detected.');
 | 
			
		||||
                return helper();
 | 
			
		||||
            }, 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('ERROR: 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 launchName = appinfo.getActivityName();
 | 
			
		||||
        console.log('Using apk: ' + apk_path);
 | 
			
		||||
        console.log('Installing app on device...');
 | 
			
		||||
        var cmd = 'adb -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"';
 | 
			
		||||
        return exec(cmd, os.tmpdir())
 | 
			
		||||
        .then(function(output) {
 | 
			
		||||
            if (output.match(/Failure/)) return Q.reject('ERROR: Failed to install apk to device: ' + output);
 | 
			
		||||
 | 
			
		||||
            //unlock screen
 | 
			
		||||
            var cmd = 'adb -s ' + resolvedTarget.target + ' shell input keyevent 82';
 | 
			
		||||
            return exec(cmd, os.tmpdir());
 | 
			
		||||
        }, function(err) { return Q.reject('ERROR: Failed to install apk to device: ' + err); })
 | 
			
		||||
        .then(function() {
 | 
			
		||||
            // launch the application
 | 
			
		||||
            console.log('Launching application...');
 | 
			
		||||
            var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
 | 
			
		||||
            return exec(cmd, os.tmpdir());
 | 
			
		||||
        }).then(function() {
 | 
			
		||||
            console.log('LAUNCH SUCCESS');
 | 
			
		||||
        }, function(err) {
 | 
			
		||||
            return Q.reject('ERROR: Failed to launch application on device: ' + err);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										336
									
								
								fritteliuhr/platforms/android/cordova/lib/emulator.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										336
									
								
								fritteliuhr/platforms/android/cordova/lib/emulator.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,336 @@
 | 
			
		|||
#!/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 shell = require('shelljs'),
 | 
			
		||||
    exec  = require('./exec'),
 | 
			
		||||
    Q     = require('q'),
 | 
			
		||||
    path  = require('path'),
 | 
			
		||||
    os    = require('os'),
 | 
			
		||||
    appinfo = require('./appinfo'),
 | 
			
		||||
    build = require('./build'),
 | 
			
		||||
    ROOT  = path.join(__dirname, '..', '..'),
 | 
			
		||||
    child_process = require('child_process'),
 | 
			
		||||
    new_emulator = 'cordova_emulator';
 | 
			
		||||
var check_reqs = require('./check_reqs');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Returns a Promise for a list of emulator images in the form of objects
 | 
			
		||||
 * {
 | 
			
		||||
       name   : <emulator_name>,
 | 
			
		||||
       path   : <path_to_emulator_image>,
 | 
			
		||||
       target : <api_target>,
 | 
			
		||||
       abi    : <cpu>,
 | 
			
		||||
       skin   : <skin>
 | 
			
		||||
   }
 | 
			
		||||
 */
 | 
			
		||||
module.exports.list_images = function() {
 | 
			
		||||
    return exec('android list avds')
 | 
			
		||||
    .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(/Path:\s/)) {
 | 
			
		||||
                    i++;
 | 
			
		||||
                    img_obj['path'] = response[i].split('Path: ')[1].replace('\r', '');
 | 
			
		||||
                }
 | 
			
		||||
                if (response[i + 1].match(/\(API\slevel\s/)) {
 | 
			
		||||
                    i++;
 | 
			
		||||
                    img_obj['target'] = response[i].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;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Will return the closest avd to the projects target
 | 
			
		||||
 * or undefined if no avds exist.
 | 
			
		||||
 * Returns a promise.
 | 
			
		||||
 */
 | 
			
		||||
module.exports.best_image = function() {
 | 
			
		||||
    var project_target = check_reqs.get_target().replace('android-', '');
 | 
			
		||||
    return this.list_images()
 | 
			
		||||
    .then(function(images) {
 | 
			
		||||
        var closest = 9999;
 | 
			
		||||
        var best = images[0];
 | 
			
		||||
        for (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) {
 | 
			
		||||
                    var closest = project_target - num;
 | 
			
		||||
                    best = images[i];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return best;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a promise.
 | 
			
		||||
module.exports.list_started = function() {
 | 
			
		||||
    return exec('adb devices', os.tmpdir())
 | 
			
		||||
    .then(function(output) {
 | 
			
		||||
        var response = output.split('\n');
 | 
			
		||||
        var started_emulator_list = [];
 | 
			
		||||
        for (var i = 1; i < response.length; i++) {
 | 
			
		||||
            if (response[i].match(/device/) && response[i].match(/emulator/)) {
 | 
			
		||||
                started_emulator_list.push(response[i].replace(/\tdevice/, '').replace('\r', ''));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return started_emulator_list;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a promise.
 | 
			
		||||
module.exports.list_targets = function() {
 | 
			
		||||
    return exec('android list targets', 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;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Starts an emulator with the given ID,
 | 
			
		||||
 * and returns the started ID of that emulator.
 | 
			
		||||
 * If no ID is given it will used the first image available,
 | 
			
		||||
 * if no image is available it will error out (maybe create one?).
 | 
			
		||||
 *
 | 
			
		||||
 * Returns a promise.
 | 
			
		||||
 */
 | 
			
		||||
module.exports.start = function(emulator_ID) {
 | 
			
		||||
    var self = this;
 | 
			
		||||
    var emulator_id, num_started, started_emulators;
 | 
			
		||||
 | 
			
		||||
    return self.list_started()
 | 
			
		||||
    .then(function(list) {
 | 
			
		||||
        started_emulators = list;
 | 
			
		||||
        num_started = started_emulators.length;
 | 
			
		||||
        if (!emulator_ID) {
 | 
			
		||||
            return self.list_images()
 | 
			
		||||
            .then(function(emulator_list) {
 | 
			
		||||
                if (emulator_list.length > 0) {
 | 
			
		||||
                    return self.best_image()
 | 
			
		||||
                    .then(function(best) {
 | 
			
		||||
                        emulator_ID = best.name;
 | 
			
		||||
                        console.log('WARNING : no emulator specified, defaulting to ' + emulator_ID);
 | 
			
		||||
                        return emulator_ID;
 | 
			
		||||
                    });
 | 
			
		||||
                } else {
 | 
			
		||||
                    var androidCmd = check_reqs.getAbsoluteAndroidCmd();
 | 
			
		||||
                    return Q.reject('ERROR : 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');
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
            return Q(emulator_ID);
 | 
			
		||||
        }
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        var cmd = 'emulator';
 | 
			
		||||
        var args = ['-avd', emulator_ID];
 | 
			
		||||
        var proc = child_process.spawn(cmd, args, { stdio: 'inherit', detached: true });
 | 
			
		||||
        proc.unref(); // Don't wait for it to finish, since the emulator will probably keep running for a long time.
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        // wait for emulator to start
 | 
			
		||||
        console.log('Waiting for emulator...');
 | 
			
		||||
        return self.wait_for_emulator(num_started);
 | 
			
		||||
    }).then(function(new_started) {
 | 
			
		||||
        if (new_started.length > 1) {
 | 
			
		||||
            for (i in new_started) {
 | 
			
		||||
                if (started_emulators.indexOf(new_started[i]) < 0) {
 | 
			
		||||
                    emulator_id = new_started[i];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            emulator_id = new_started[0];
 | 
			
		||||
        }
 | 
			
		||||
        if (!emulator_id) return Q.reject('ERROR :  Failed to start emulator, could not find new emulator');
 | 
			
		||||
 | 
			
		||||
        //wait for emulator to boot up
 | 
			
		||||
        process.stdout.write('Booting up emulator (this may take a while)...');
 | 
			
		||||
        return self.wait_for_boot(emulator_id);
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        console.log('BOOT COMPLETE');
 | 
			
		||||
 | 
			
		||||
        //unlock screen
 | 
			
		||||
        return exec('adb -s ' + emulator_id + ' shell input keyevent 82', os.tmpdir());
 | 
			
		||||
    }).then(function() {
 | 
			
		||||
        //return the new emulator id for the started emulators
 | 
			
		||||
        return emulator_id;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Waits for the new emulator to apear on the started-emulator list.
 | 
			
		||||
 * Returns a promise with a list of newly started emulators' IDs.
 | 
			
		||||
 */
 | 
			
		||||
module.exports.wait_for_emulator = function(num_running) {
 | 
			
		||||
    var self = this;
 | 
			
		||||
    return self.list_started()
 | 
			
		||||
    .then(function(new_started) {
 | 
			
		||||
        if (new_started.length > num_running) {
 | 
			
		||||
            return new_started;
 | 
			
		||||
        } else {
 | 
			
		||||
            return Q.delay(1000).then(function() {
 | 
			
		||||
                return self.wait_for_emulator(num_running);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Waits for the boot animation property of the emulator to switch to 'stopped'
 | 
			
		||||
 */
 | 
			
		||||
module.exports.wait_for_boot = function(emulator_id) {
 | 
			
		||||
    var self = this;
 | 
			
		||||
    return exec('adb -s ' + emulator_id + ' shell getprop init.svc.bootanim', os.tmpdir())
 | 
			
		||||
    .then(function(output) {
 | 
			
		||||
        if (output.match(/stopped/)) {
 | 
			
		||||
            return;
 | 
			
		||||
        } else {
 | 
			
		||||
            process.stdout.write('.');
 | 
			
		||||
            return Q.delay(3000).then(function() {
 | 
			
		||||
                return self.wait_for_boot(emulator_id);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 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 avd named ' + name);
 | 
			
		||||
    if (target) {
 | 
			
		||||
        return exec('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(create.output);
 | 
			
		||||
        });
 | 
			
		||||
    } else {
 | 
			
		||||
        console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.');
 | 
			
		||||
        return exec('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('Please insure 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 started emulators found, please start an emultor 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(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);
 | 
			
		||||
        console.log('Installing app on emulator...');
 | 
			
		||||
        console.log('Using apk: ' + apk_path);
 | 
			
		||||
        return exec('adb -s ' + resolvedTarget.target + ' install -r "' + apk_path + '"', os.tmpdir())
 | 
			
		||||
        .then(function(output) {
 | 
			
		||||
            if (output.match(/Failure/)) {
 | 
			
		||||
                return Q.reject('Failed to install apk to emulator: ' + output);
 | 
			
		||||
            }
 | 
			
		||||
            return Q();
 | 
			
		||||
        }, function(err) {
 | 
			
		||||
            return Q.reject('Failed to install apk to emulator: ' + err);
 | 
			
		||||
        }).then(function() {
 | 
			
		||||
            //unlock screen
 | 
			
		||||
            return exec('adb -s ' + resolvedTarget.target + ' shell input keyevent 82', os.tmpdir());
 | 
			
		||||
        }).then(function() {
 | 
			
		||||
            // launch the application
 | 
			
		||||
            console.log('Launching application...');
 | 
			
		||||
            var launchName = appinfo.getActivityName();
 | 
			
		||||
            cmd = 'adb -s ' + resolvedTarget.target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
 | 
			
		||||
            return exec(cmd, os.tmpdir());
 | 
			
		||||
        }).then(function(output) {
 | 
			
		||||
            console.log('LAUNCH SUCCESS');
 | 
			
		||||
        }, function(err) {
 | 
			
		||||
            return Q.reject('Failed to launch app on emulator: ' + err);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								fritteliuhr/platforms/android/cordova/lib/exec.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								fritteliuhr/platforms/android/cordova/lib/exec.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
#!/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 child_process = require('child_process'),
 | 
			
		||||
    Q       = require('q');
 | 
			
		||||
 | 
			
		||||
// Takes a command and optional current working directory.
 | 
			
		||||
// Returns a promise that either resolves with the stdout, or
 | 
			
		||||
// rejects with an error message and the stderr.
 | 
			
		||||
module.exports = function(cmd, opt_cwd) {
 | 
			
		||||
    var d = Q.defer();
 | 
			
		||||
    try {
 | 
			
		||||
        child_process.exec(cmd, {cwd: opt_cwd, maxBuffer: 1024000}, function(err, stdout, stderr) {
 | 
			
		||||
            if (err) d.reject('Error executing "' + cmd + '": ' + stderr);
 | 
			
		||||
            else d.resolve(stdout);
 | 
			
		||||
        });
 | 
			
		||||
    } catch(e) {
 | 
			
		||||
        console.error('error caught: ' + e);
 | 
			
		||||
        d.reject(e);
 | 
			
		||||
    }
 | 
			
		||||
    return d.promise;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										42
									
								
								fritteliuhr/platforms/android/cordova/lib/install-device
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								fritteliuhr/platforms/android/cordova/lib/install-device
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,42 @@
 | 
			
		|||
#!/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);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/install-device.bat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/install-device.bat
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										38
									
								
								fritteliuhr/platforms/android/cordova/lib/install-emulator
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								fritteliuhr/platforms/android/cordova/lib/install-emulator
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
#!/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);
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										33
									
								
								fritteliuhr/platforms/android/cordova/lib/list-devices
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								fritteliuhr/platforms/android/cordova/lib/list-devices
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
#!/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
 | 
			
		||||
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);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/list-devices.bat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/list-devices.bat
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
#!/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
 | 
			
		||||
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);
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
#!/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
 | 
			
		||||
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);
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										58
									
								
								fritteliuhr/platforms/android/cordova/lib/log.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								fritteliuhr/platforms/android/cordova/lib/log.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
#!/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 shell = require('shelljs'),
 | 
			
		||||
    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 cmd = 'adb logcat | grep -v nativeGetEnabledTags';
 | 
			
		||||
    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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,79 @@
 | 
			
		|||
/* 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()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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
 | 
			
		||||
    if (gradle.gradleVersion >= "2.2") {
 | 
			
		||||
        dependencies {
 | 
			
		||||
            classpath 'com.android.tools.build:gradle:1.0.0+'
 | 
			
		||||
        }
 | 
			
		||||
    } else if (gradle.gradleVersion >= "2.1") {
 | 
			
		||||
        dependencies {
 | 
			
		||||
            classpath 'com.android.tools.build:gradle:0.14.0+'
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        dependencies {
 | 
			
		||||
            classpath 'com.android.tools.build:gradle:0.12.0+'
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
apply plugin: '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'
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										158
									
								
								fritteliuhr/platforms/android/cordova/lib/run.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								fritteliuhr/platforms/android/cordova/lib/run.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,158 @@
 | 
			
		|||
#!/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'),
 | 
			
		||||
    build = require('./build'),
 | 
			
		||||
    emulator = require('./emulator'),
 | 
			
		||||
    device   = require('./device'),
 | 
			
		||||
    shell = require('shelljs'),
 | 
			
		||||
    Q = require('q');
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 * Returns a promise.
 | 
			
		||||
 */
 | 
			
		||||
 module.exports.run = function(args) {
 | 
			
		||||
    var buildFlags = [];
 | 
			
		||||
    var install_target;
 | 
			
		||||
    var list = false;
 | 
			
		||||
 | 
			
		||||
    for (var i=2; i<args.length; i++) {
 | 
			
		||||
        if (/^--(debug|release|ant|gradle|nobuild|versionCode=|minSdkVersion=|gradleArg=)/.exec(args[i])) {
 | 
			
		||||
            buildFlags.push(args[i]);
 | 
			
		||||
        } else if (args[i] == '--device') {
 | 
			
		||||
            install_target = '--device';
 | 
			
		||||
        } else if (args[i] == '--emulator') {
 | 
			
		||||
            install_target = '--emulator';
 | 
			
		||||
        } else if (/^--target=/.exec(args[i])) {
 | 
			
		||||
            install_target = args[i].substring(9, args[i].length);
 | 
			
		||||
        } else if (args[i] == '--list') {
 | 
			
		||||
            list = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            console.warn('Option \'' + args[i] + '\' not recognized (ignoring).');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (list) {
 | 
			
		||||
        var output = '';
 | 
			
		||||
        var temp = '';
 | 
			
		||||
        if (!install_target) {
 | 
			
		||||
            output += 'Available Android Devices:\n';
 | 
			
		||||
            temp = shell.exec(path.join(__dirname, 'list-devices'), {silent:true}).output;
 | 
			
		||||
            temp = temp.replace(/^(?=[^\s])/gm, '\t');
 | 
			
		||||
            output += temp;
 | 
			
		||||
            output += 'Available Android Virtual Devices:\n';
 | 
			
		||||
            temp = shell.exec(path.join(__dirname, 'list-emulator-images'), {silent:true}).output;
 | 
			
		||||
            temp = temp.replace(/^(?=[^\s])/gm, '\t');
 | 
			
		||||
            output += temp;
 | 
			
		||||
        } else if (install_target == '--emulator') {
 | 
			
		||||
            output += 'Available Android Virtual Devices:\n';
 | 
			
		||||
            temp = shell.exec(path.join(__dirname, 'list-emulator-images'), {silent:true}).output;
 | 
			
		||||
            temp = temp.replace(/^(?=[^\s])/gm, '\t');
 | 
			
		||||
            output += temp;
 | 
			
		||||
        } else if (install_target == '--device') {
 | 
			
		||||
            output += 'Available Android Devices:\n';
 | 
			
		||||
            temp = shell.exec(path.join(__dirname, 'list-devices'), {silent:true}).output;
 | 
			
		||||
            temp = temp.replace(/^(?=[^\s])/gm, '\t');
 | 
			
		||||
            output += temp;
 | 
			
		||||
        }
 | 
			
		||||
        console.log(output);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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) {
 | 
			
		||||
                    console.log('WARNING : No target specified, deploying to device \'' + device_list[0] + '\'.');
 | 
			
		||||
                    install_target = device_list[0];
 | 
			
		||||
                } else {
 | 
			
		||||
                    console.log('WARNING : No target specified, 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 (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) {
 | 
			
		||||
        return build.run(buildFlags, resolvedTarget).then(function(buildResults) {
 | 
			
		||||
            if (resolvedTarget.isEmulator) {
 | 
			
		||||
                return emulator.install(resolvedTarget, buildResults);
 | 
			
		||||
            }
 | 
			
		||||
            return device.install(resolvedTarget, buildResults);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports.help = function(args) {
 | 
			
		||||
    console.log('Usage: ' + path.relative(process.cwd(), args[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);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								fritteliuhr/platforms/android/cordova/lib/spawn.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								fritteliuhr/platforms/android/cordova/lib/spawn.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
#!/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 child_process = require('child_process'),
 | 
			
		||||
    Q       = require('q');
 | 
			
		||||
var isWindows = process.platform.slice(0, 3) == 'win';
 | 
			
		||||
 | 
			
		||||
// Takes a command and optional current working directory.
 | 
			
		||||
module.exports = function(cmd, args, opt_cwd) {
 | 
			
		||||
    var d = Q.defer();
 | 
			
		||||
    var opts = { cwd: opt_cwd, stdio: 'inherit' };
 | 
			
		||||
    try {
 | 
			
		||||
        // Work around spawn not being able to find .bat files.
 | 
			
		||||
        if (isWindows) {
 | 
			
		||||
            args = [['/s', '/c', '"' + [cmd].concat(args).map(function(a){if (/^[^"].* .*[^"]/.test(a)) return '"' + a + '"'; return a;}).join(' ')+'"'].join(' ')];
 | 
			
		||||
            cmd = 'cmd';
 | 
			
		||||
            opts.windowsVerbatimArguments = true;
 | 
			
		||||
        }
 | 
			
		||||
        var child = child_process.spawn(cmd, args, opts);
 | 
			
		||||
        child.on('exit', function(code) {
 | 
			
		||||
            if (code) {
 | 
			
		||||
                d.reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
 | 
			
		||||
            } else {
 | 
			
		||||
                d.resolve();
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    } catch(e) {
 | 
			
		||||
        console.error('error caught: ' + e);
 | 
			
		||||
        d.reject(e);
 | 
			
		||||
    }
 | 
			
		||||
    return d.promise;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										39
									
								
								fritteliuhr/platforms/android/cordova/lib/start-emulator
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								fritteliuhr/platforms/android/cordova/lib/start-emulator
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
#!/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);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/start-emulator.bat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								fritteliuhr/platforms/android/cordova/lib/start-emulator.bat
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
:: 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
 | 
			
		||||
)
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue