#!/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 = /\': Extra args to pass to the gradle command. Use one flag per arg. Ex. --gradleArg=-PcdvBuildMultipleApks=true'); process.exit(0); };