Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[CB-4268] Rework util functions to support getting list of connected …
…devices / emulators

This will be used by the run script to determine if a connected device or emulator is available.
  • Loading branch information
bryanhiggins committed Jul 17, 2013
1 parent 0dabef3 commit bc773871e0755ada26719317671c15f54dfebb28
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 75 deletions.

This file was deleted.

@@ -1,3 +1,5 @@
#!/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
@@ -15,6 +17,4 @@
// specific language governing permissions and limitations
// under the License.

var cordova = require('./cordova');

cordova.listTargets('device', true);
require('./target-utils').listTargets('device', true);
@@ -1,3 +1,4 @@
#!/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
@@ -15,6 +16,4 @@
// specific language governing permissions and limitations
// under the License.

var cordova = require('./cordova');

cordova.listTargets('simulator', false);
require('./target-utils').listTargets('simulator', false);
@@ -1,3 +1,4 @@
#!/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
@@ -14,7 +15,4 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

var cordova = require('./cordova');

cordova.listTargets('simulator', true);
require('./target-utils').listTargets('simulator', true);
@@ -256,9 +256,10 @@ function postBuild() {

function exec() {
program
.usage('[--target=<id>] [-k | --keystorepass] [--no-launch] [--no-uninstall] [--no-build]')
.usage('[--device] [--emulator] [--target=<id>] [-k | --keystorepass] [--no-launch] [--no-uninstall] [--no-build]')
.option('-k, --keystorepass <password>', 'the password of signing key; needed for creating debug token')
.option('--device', 'run on connected device')
.option('--emulator', 'run on BB10 simulator')
.option('--target', 'specifies the target to run the application')
.option('--no-uninstall', 'does not uninstall application from device')
.option('--no-launch', 'do not launch the application on device')
@@ -0,0 +1,80 @@
/*
* Copyright 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var _self,
exec = require('child_process').exec,
bb10_utils = require('./utils'),
blackberryProperties = bb10_utils.getProperties();

_self = {
getTargetList : function (type, pruneDisconnected, callback) {
var targList = [],
count = 0,
targets = blackberryProperties.targets,
addItem = function (t) {
targets[t].name = t;
targList.push(targets[t]);
},
checkConnection = function (name) {
_self.checkConnection(targets[name].ip, type, function (connected) {
count++;
if (connected) {
addItem(name);
}
complete();
});
},
complete = function () {
if (count === Object.keys(targets).length) {
callback(targList);
}
};
if (targets) {
for (t in targets) {
if (targets.hasOwnProperty(t) && targets[t].type === type) {
if (pruneDisconnected) {
checkConnection(t);
}
else {
addItem(t);
count++;
}
} else {
count++;
}
}
}
complete();
},

checkConnection: function(ip, type, callback) {
exec('blackberry-deploy -test ' + ip, function(error, stdout, stderr) {
// error code 3 corresponds to a connected device, null corresponds to connected sim
callback((type === 'simulator' && error === null) || (type == 'device' && error.code === 3));
});
},

listTargets : function(type, pruneDisconnected) {
_self.getTargetList(type, pruneDisconnected, function (targets) {
for (t in targets) {
console.log(targets[t].name + ' ip: ' + targets[t].ip + (pruneDisconnected ? ' status: connected' : ''));
}
});
}

};

module.exports = _self;

0 comments on commit bc77387

Please sign in to comment.