Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-5434 add homedir() function and use USERPROFILE on Windows
EXCEPTION_DEBUG_TOKEN_NOT_FOUND and EXCEPTION_DEBUG_TOKEN_NOT_FOUND should reference
the current expected path for files and not something that might only coincidentally
be the right location.

signing-utils should use USERPROFILE on Windows
  • Loading branch information
jsoref authored and bryanhiggins committed Dec 5, 2013
1 parent 5689a49 commit df49094aeac8c1048d9b015f1e61b850e0194c95
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 64 deletions.
@@ -24,17 +24,17 @@ var fs = require('fs'),

function getDefaultPath(file) {
// The default location where signing key files are stored will vary based on the OS:
// Windows XP: %HOMEPATH%\Local Settings\Application Data\Research In Motion
// Windows Vista and Windows 7: %HOMEPATH%\AppData\Local\Research In Motion
// Windows XP: %USERPROFILE%\Local Settings\Application Data\Research In Motion
// Windows Vista and Windows 7: %USERPROFILE%\AppData\Local\Research In Motion
// Mac OS: ~/Library/Research In Motion
// UNIX or Linux: ~/.rim
var p = "";
if (os.type().toLowerCase().indexOf("windows") >= 0) {
// Try Windows XP location
p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\Local Settings\\Application Data\\Research In Motion\\";
p = process.env.USERPROFILE + "\\Local Settings\\Application Data\\Research In Motion\\";
if (!fs.existsSync(p)) {
// Try Windows Vista and Windows 7 location
p = process.env.HOMEDRIVE + process.env.HOMEPATH + "\\AppData\\Local\\Research In Motion\\";
p = process.env.USERPROFILE + "\\AppData\\Local\\Research In Motion\\";
}
} else if (os.type().toLowerCase().indexOf("darwin") >= 0) {
// Try Mac OS location
@@ -93,7 +93,7 @@ try {
done();
});
} else {
err = "No signing password provided. Please enter a value for 'keystorepass' in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line";
err = "No signing password provided. Please enter a value for 'keystorepass' in "+pkgrUtils.homedir()+"/.cordova/blackberry10.json or use --keystorepass via command-line";
}
}

@@ -138,7 +138,7 @@ self.createToken = function (projectProperties, target, keystorepass, callback)
callback(-1);
}
} else if (!keystorepass) {
logger.warn(localize.translate("WARN_NO_SIGNING_PASSWORD_PROVIDED"));
logger.warn(localize.translate("WARN_NO_SIGNING_PASSWORD_PROVIDED", pkgrUtils.homedir()));
if (callback && typeof callback === "function") {
callback(-1);
}
@@ -35,7 +35,7 @@ var Localize = require("localize"),
"en": "Build ID set in config.xml [version], but no signing password was provided [-g]. Bar will be unsigned"
},
"EXCEPTION_DEBUG_TOKEN_NOT_FOUND": {
"en": "Failed to find debug token. If you have an existing debug token, please copy it to %HOME%/.cordova/blackberry10debugtoken.bar. To generate a new debug token, execute the 'run' command."
"en": "Failed to find debug token. If you have an existing debug token, please copy it to $[1]/.cordova/blackberry10debugtoken.bar. To generate a new debug token, execute the 'run' command."
},
"EXCEPTION_DEBUG_TOKEN_WRONG_FILE_EXTENSION": {
"en": "Specified debug token not a .bar extension"
@@ -188,7 +188,7 @@ var Localize = require("localize"),
"en": "No device PIN found, will omit debug token generation"
},
"WARN_NO_SIGNING_PASSWORD_PROVIDED": {
"en": "No signing password provided, debug token cannot be generated. Please enter a value for 'keystorepass' in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line directly from the project cordova scripts."
"en": "No signing password provided, debug token cannot be generated. Please enter a value for 'keystorepass' in $[1]/.cordova/blackberry10.json or use --keystorepass via command-line directly from the project cordova scripts."
},
"PROGRESS_GENERATING_DEBUG_TOKEN": {
"en": "Generating debug token"
@@ -219,7 +219,7 @@ function generateOptionsFile(session, target, config) {
debugToken = "-debugToken" + NL;
debugToken += conf.DEBUG_TOKEN + NL;
} else {
logger.warn(localize.translate("EXCEPTION_DEBUG_TOKEN_NOT_FOUND"));
logger.warn(localize.translate("EXCEPTION_DEBUG_TOKEN_NOT_FOUND", pkgrUtils.homedir()));
}
}

@@ -103,6 +103,13 @@ _self = {
return myString === "true" ? true : myString === "false" ? false : defaultVal;
},

homedir: function () {
if (_self.isWindows()) {
return process.env.USERPROFILE;
}
return process.env.HOME;
},

parseUri : function (str) {
var i, uri = {},
key = [ "source", "scheme", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor" ],
@@ -32,42 +32,28 @@ describe("signing-utils", function () {

beforeEach(function () {

/* Preserve the value of the HOMEPATH and HOMEDRIVE environment
* variables if they are defined. If they are not defined, mark
* variable for deletion after the test.*/
if (typeof process.env.HOMEPATH === 'undefined') {
properties.homepath = "delete";
/* Preserve the value of the USERPROFILE environment
* variable if it is defined. If it is not defined, mark
* the variable for deletion after the test.*/
if (typeof process.env.USERPROFILE === 'undefined') {
properties.userprofile = "delete";
} else {
properties.homepath = process.env.HOMEPATH;
}

if (typeof process.env.HOMEDRIVE === 'undefined') {
properties.homedrive = "delete";
} else {
properties.homedrive = process.env.HOMEDRIVE;
properties.userprofile = process.env.USERPROFILE;
}

spyOn(os, "type").andReturn("windows");
});

afterEach(function () {

/* Restore the value of the HOMEPATH and HOMEDRIVE environment
* variables if they are defined. If they are not defined, delete
/* Restore the value of the USERPROFILE environment
* variable if it is defined. If it is not defined, delete
* the property if it was defined in the test.*/
if (typeof process.env.HOMEPATH === 'string') {
if (properties.homepath === 'delete') {
delete process.env.HOMEPATH;
} else {
process.env.HOMEPATH = properties.homepath;
}
}

if (typeof process.env.HOMEDRIVE === 'string') {
if (properties.homedrive === 'delete') {
delete process.env.HOMEDRIVE;
if (typeof process.env.USERPROFILE === 'string') {
if (properties.userprofile === 'delete') {
delete process.env.USERPROFILE;
} else {
process.env.HOMEDRIVE = properties.homedrive;
process.env.USERPROFILE = properties.userprofile;
}
}
});
@@ -153,8 +139,7 @@ describe("signing-utils", function () {
});

it("can find keys in home path", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (p) {
return p.indexOf("\\Users\\user") !== -1;
@@ -165,9 +150,7 @@ describe("signing-utils", function () {
});

it("can find keys on C drive", function () {

process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (p) {
return p.indexOf("C:") !== -1;
@@ -178,8 +161,7 @@ describe("signing-utils", function () {
});

it("can find keys on a drive other than C", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1;
@@ -190,8 +172,7 @@ describe("signing-utils", function () {
});

it("can find bbidtoken.csk on a drive other than C", function() {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1;
@@ -202,8 +183,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.csk on a drive other than C", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1;
@@ -214,8 +194,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.db on a drive other than C", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1;
@@ -226,8 +205,7 @@ describe("signing-utils", function () {
});

it("can find keys in Local Settings on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("C:") !== -1 &&
@@ -240,8 +218,7 @@ describe("signing-utils", function () {
});

it("can find bbidtoken.csk in Local Settings on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("C:") !== -1 &&
@@ -254,8 +231,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.csk in Local Settings on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1 &&
@@ -268,8 +244,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.db in Local Settings on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1 &&
@@ -282,8 +257,7 @@ describe("signing-utils", function () {
});

it("can find keys in AppData on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("C:") !== -1 &&
@@ -296,8 +270,7 @@ describe("signing-utils", function () {
});

it("can find bbidtoken.csk in AppData on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "C:";
process.env.USERPROFILE = "C:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("C:") !== -1 &&
@@ -310,8 +283,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.csk in AppData on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1 &&
@@ -324,8 +296,7 @@ describe("signing-utils", function () {
});

it("can find barsigner.db in AppData on the correct drive", function () {
process.env.HOMEPATH = "\\Users\\user";
process.env.HOMEDRIVE = "D:";
process.env.USERPROFILE = "D:\\Users\\user";

spyOn(fs, "existsSync").andCallFake(function (path) {
return path.indexOf("D:") !== -1 &&

0 comments on commit df49094

Please sign in to comment.