Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
Removed downloader.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Waterman committed Feb 19, 2014
1 parent b586d3d commit 7de4f4a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 215 deletions.
107 changes: 39 additions & 68 deletions Gruntfile.js
Expand Up @@ -15,82 +15,54 @@ module.exports = function (grunt) {
chromeInfo: grunt.file.readJSON('platforms/chrome-crx/manifest.json'),

apk_generator: {
download_xwalk_android : {
stable_x86: {
"outDir": 'build',
"channel": 'stable',
"arch": 'x86'
},
stable_arm: {
"outDir": 'build',
"channel": 'stable',
"arch": 'arm'
},
canary_x86: {
"outDir": 'build',
"channel": 'canary',
"arch": 'x86'
},
canary_arm: {
"outDir": 'build',
"channel": 'canary',
"arch": 'arm'
}
},
generate_apk : {
//"outDir": process.env.HOME+'/z/webapps/webapps-annex/build',
"outDir": 'build',
//"outDir": process.env.HOME+'/z/webapps/webapps-annex/build',
"outDir": 'build',

"appConfig": {
// display name for the app on the device;
// the sanitisedName used to construct the Locations object later
// is derived from this
name: '<%= packageInfo.name %>',
// display name for the app on the device;
// the sanitisedName used to construct the Locations object later
// is derived from this
name: '<%= packageInfo.name %>',

// package for the app's generated Java files; this works best if
// you have at least one period character between two character
// strings, and no digits
pkg: 'org.org01.webapps.annex',
// package for the app's generated Java files; this works best if
// you have at least one period character between two character
// strings, and no digits
pkg: 'org.org01.webapps.annex',

icon: 'build/xpk/icon_128.png',
icon: 'icon_128.png',

fullscreen: true,
//fullscreen: true,

remoteDebugging: true,
//remoteDebugging: true,

// path to the directory containing your HTML5 app;
// note that this must use the correct path separators for your
// platform: Windows uses '\\' while Linux uses '/'
appRoot: 'build/xpk',
// path to the directory containing your HTML5 app;
// note that this must use the correct path separators for your
// platform: Windows uses '\\' while Linux uses '/'
appRoot: 'build/xpk',

// relative path from appRoot of the entry HTML file for your app
appLocalPath: 'index.html',
// relative path from appRoot of the entry HTML file for your app
appLocalPath: 'index.html',

embedded: true
},
//embedded: true,

envConfig: {
// path to the root of your Android SDK installation;
// on Windows, use the path to the sdk directory inside
// the installation, e.g. 'c:\\android-sdk\\sdk'
// automatically obtained from the 'android' command's path
//androidSDKDir: '/opt/android-sdk-linux/',

// path to the xwalk_app_template directory; you can either
// download and unpack this manually, or use the xwalk_android_dl
// script to do so (part of this project; see the README for details);
// note that path separators specific to your platform must be used
// don't set this to allow it to be set by the downloader
//xwalkAndroidDir: 'build/crosswalk-*/xwalk_app_template/',

// architecture of embedded crosswalk
// don't set this to allow it to be set by the downloader
//arch: 'x86',

// automatically obtains latest from androidSDKDir/build-tools
//androidAPIVersion: "18.0.1"
}
}
// path to the root of your Android SDK installation;
// on Windows, use the path to the sdk directory inside
// the installation, e.g. 'c:\\android-sdk\\sdk'
// default: automatically obtain from the 'android' command's path
//androidSDKDir: '/opt/android-sdk-linux/',

// path to the xwalk_app_template directory; you can either
// download and unpack this manually, or use the xwalk_android_dl
// script to do so (part of this project; see the README for details);
// note that path separators specific to your platform must be used
// eg: export XWALKANDROIDDIR=$HOME/Downloads/crosswalk-3.32.53.4-x86
xwalkAndroidDir: process.env.XWALKANDROIDDIR,

// architecture of embedded crosswalk
// default: it is obtains from the path of xwalkAndroidDir
//arch: 'x86',

// default: automatically obtains latest from androidSDKDir/build-tools
//androidAPIVersion: "18.0.1"
},

clean: ['build'],
Expand Down Expand Up @@ -420,7 +392,6 @@ module.exports = function (grunt) {
grunt.registerTask('default', 'wgt');
grunt.registerTask('apk', [
'xpk',
'apk_generator:download_xwalk_android:canary_x86',
'apk_generator:generate_apk'
]);
};
181 changes: 34 additions & 147 deletions tools/grunt-tasks/grunt-apk-generator.js
Expand Up @@ -15,141 +15,57 @@ module.exports = function (grunt) {
var Env = Api.Env;
var App = Api.App;

// options passed from the downloader to the generator
var passthrough = {
xwalkAndroidDir: '',
arch: ''
};

var download_xwalk_android = function(data, done) {
var archiveFetcher = ArchiveFetcher({logger: logger});

// generic error handler
var errorHandler = function (err) {
logger.error(err.message);
logger.error(err.stack);
done(false);
};

// show parameters used for the fetch or query
var showParams = function (params) {
logger.log(' architecture = ' + params.arch);
logger.log(' channel = ' + params.channel);

if (params.version) {
logger.log(' version = ' + params.version);
}

if (params.url) {
logger.log(' url = ' + params.url);
}
};

// derive the tarballName and outDir
var tarballName = data.tarballName || 'xwalk_app_template.tar.gz';
var outDir = data.outDir || '.';

var paramsDfd = Q.defer();

// work out what we're going to download

var urlTemplate = data.urlTemplate ||
'https://download.01.org/crosswalk/releases/android-' +
'<%= arch %>/<%= channel %>/crosswalk-<%= version %>-<%= arch %>.zip';

var params = {
arch: data.arch || Env.CONFIG_DEFAULTS.arch,
channel: data.channel || "beta",
version: data.version
};

// URL is set as an option
var archiveUrl = data.url;

// no url option, but we've got the version, which is enough to build a URL
if (!archiveUrl && params.version) {
archiveUrl = _.template(urlTemplate, params);
}

// we already know the archiveUrl
if (archiveUrl) {
params.url = archiveUrl;
paramsDfd.resolve(params);
}
// no version specified and no url option, so get the latest version,
// based on arch and channel
else {
versionsFetcher = VersionsFetcher();
versionsFetcher.getDownloads(params.arch, params.channel)
.done(
function (results) {
params.version = results.files[0].version;
params.url = results.files[0].url;
return paramsDfd.resolve(params);
},

function (err) {
logger.error('error while retrieving available versions');
errorHandler(err);
}
);
}

paramsDfd.promise
.then(
function (params) {
logger.log('fetching xwalk-android using parameters:');
showParams(params);
return archiveFetcher.fetch(params.url, tarballName, outDir);
}
)
.done(
function (xwalkAndroidDir) {
logger.log('xwalk zip file and app template downloaded and unpacked successfully');
logger.log('\nxwalkAndroidDir (xwalk_app_template directory inside ' +
'unpacked xwalk-android):\n' + xwalkAndroidDir);
passthrough.arch = params.arch;
passthrough.xwalkAndroidDir = xwalkAndroidDir;
done();
},

errorHandler
);
};

var generate_apk = function(data,done) {
var outDir = data.outDir || '.';

// use values from downloader, if none specified
Object.keys(passthrough).forEach(function(property){
data.envConfig[property] = data.envConfig[property] || passthrough[property];
var appConfig = {};
var envConfig = {};

// copy user-supplied parameters into envConfig or appConfig
var envProperties = [ 'androidSDKDir', 'xwalkAndroidDir', 'arch', 'androidAPIVersion' ];
Object.keys(data).forEach(function(property){
if (envProperties.indexOf(property)!=-1) {
envConfig[property] = data[property];
} else {
appConfig[property] = data[property];
}
});

// convert to full pathname
outDir = path.resolve(outDir);

// automatically find androidSDKDir from 'android' command in PATH
if (!data.envConfig.androidSDKDir) {
if (!envConfig.androidSDKDir) {
var androidPath = which.sync('android');
// up two directories
data.envConfig.androidSDKDir = path.dirname(path.dirname(androidPath));
envConfig.androidSDKDir = path.dirname(path.dirname(androidPath));
}

if (!data.envConfig.androidAPIVersion) {
// determine arch from directory name
if (!envConfig.arch) {
var xwalkAndroidRoot = path.dirname(envConfig.xwalkAndroidDir);
//HOME/Downloads/crosswalk-4.32.69.0-x86/xwalk_app_template
var pathBits = xwalkAndroidRoot.split(path.sep);
var sdkName = pathBits[pathBits.length-2];
var sdkNameBits = sdkName.split('-');

envConfig.arch = sdkNameBits[sdkNameBits-1];
}

if (!envConfig.androidAPIVersion) {
// get the api latest version from androidSDK/build-tools
var buildToolsDir = path.join(data.envConfig.androidSDKDir,"build-tools");
var buildToolsDir = path.join(envConfig.androidSDKDir,"build-tools");
var files = fs.readdirSync(buildToolsDir);
var androidAPIVersions = files.sort(semver.compare);
var length = androidAPIVersions.length;
var latest = androidAPIVersions[length-1];
data.envConfig.androidAPIVersion = latest;
envConfig.androidAPIVersion = latest;
}

// create a promise for a configured Env object
var envPromise = Env(data.envConfig);
var envPromise = Env(envConfig);

// create a promise for a configured App object
var appPromise = App(data.appConfig);
var appPromise = App(appConfig);

// use the Q promises library to synchronise the promises, so we
// can create the objects in "parallel"
Expand All @@ -171,14 +87,14 @@ module.exports = function (grunt) {
.done(
// success
function (finalApk) {
console.log('\n*** DONE\n output apk path is ' + finalApk);
grunt.log.writeln('\n*** DONE\n output apk path is ' + finalApk);
done();
},

// error handler
function (err) {
console.log('!!! ERROR');
console.log(err.stack);
grunt.log.error('!!! ERROR');
grunt.log.error(err.stack);
done(false);
}
);
Expand All @@ -196,39 +112,10 @@ module.exports = function (grunt) {
* version - application version
*
*/
grunt.registerMultiTask('apk_generator', 'Tasks for generating apk packages', function (identifier) {
grunt.registerTask('apk_generator', 'Tasks for generating apk packages', function (identifier) {
var done = this.async();

if (this.target == 'generate_apk') {
generate_apk(this.data, done);
} else
if (this.target == 'download_xwalk_android') {
// support a list of targets, eg :
// apk_generator: {
// download_xwalk_android : {
// stable_x86: {
// "outDir": 'build',
// "channel": 'stable',
// "arch": 'x86'
// },
// stable_arm: {
// "outDir": 'build',
// "channel": 'stable',
// ... and so one
//
// or just a single one :
// apk_generator: {
// download_xwalk_android : {
// "outDir": 'build',
// "channel": 'stable',
// "arch": 'x86'
// },
// ...
var targetName = this.args[0];
var data = (targetName)?this.data[targetName]:this.data;

download_xwalk_android(data, done);
}
generate_apk(grunt.config('apk_generator'), done);
});

};
Expand Down

0 comments on commit 7de4f4a

Please sign in to comment.