mirror of
https://github.com/appium/appium.git
synced 2026-02-11 20:39:04 -06:00
Merge pull request #3151 from paymand/3150
Fix for #3150: Parse plist files as binary and XML.
This commit is contained in:
@@ -30,18 +30,42 @@ var path = require('path')
|
||||
, fruitstrap = path.resolve(__dirname, '../../../build/fruitstrap/fruitstrap')
|
||||
, prepareBootstrap = require('./uiauto').prepareBootstrap
|
||||
, CommandProxy = require('./uiauto').CommandProxy
|
||||
, UnknownError = errors.UnknownError;
|
||||
, UnknownError = errors.UnknownError
|
||||
, binaryPlist = true;
|
||||
|
||||
// XML Plist library helper
|
||||
var xmlPlistFile = function (filename, callback) {
|
||||
var parseXmlPlistFile = function (plist, cb) {
|
||||
try {
|
||||
var result = xmlplist.parseFileSync(filename);
|
||||
return callback(null, result);
|
||||
var result = xmlplist.parseFileSync(plist);
|
||||
return cb(null, result);
|
||||
} catch (ex) {
|
||||
return callback(ex);
|
||||
return cb(ex);
|
||||
}
|
||||
};
|
||||
|
||||
var parsePlistFile = function (plist, cb) {
|
||||
bplistParse.parseFile(plist, function (err, obj) {
|
||||
if (err) {
|
||||
logger.error("Could not parse plist file (as binary) at " + plist);
|
||||
logger.info("Will try to parse the plist file as XML");
|
||||
parseXmlPlistFile(plist, function (err, obj) {
|
||||
if (err) {
|
||||
logger.error("Could not parse plist file (as XML) at " + plist);
|
||||
return cb(err, null);
|
||||
} else {
|
||||
logger.debug("Parsed app Info.plist (as XML)");
|
||||
binaryPlist = false;
|
||||
cb(null, obj);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.debug("Parsed app Info.plist (as binary)");
|
||||
binaryPlist = true;
|
||||
cb(null, obj);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var IOS = function () {
|
||||
this.init();
|
||||
};
|
||||
@@ -883,49 +907,42 @@ IOS.prototype.getDeviceString = function () {
|
||||
|
||||
IOS.prototype.setDeviceTypeInInfoPlist = function (deviceTypeCode, cb) {
|
||||
var plist = path.resolve(this.args.app, "Info.plist");
|
||||
bplistParse.parseFile(plist, function (err, obj) {
|
||||
var newPlist;
|
||||
parsePlistFile(plist, function (err, obj) {
|
||||
if (err) {
|
||||
xmlPlistFile(plist, function (err, obj) {
|
||||
if (err) {
|
||||
logger.error("Could not parse plist file at " + plist);
|
||||
cb(err);
|
||||
return;
|
||||
} else {
|
||||
logger.debug("Parsed app Info.plist");
|
||||
obj.UIDeviceFamily = [deviceTypeCode];
|
||||
newPlist = xmlplist.build(obj);
|
||||
}
|
||||
});
|
||||
logger.error("Could not set the device type in Info.plist");
|
||||
return cb(err, null);
|
||||
} else {
|
||||
logger.debug("Parsed app Info.plist");
|
||||
obj[0].UIDeviceFamily = [deviceTypeCode];
|
||||
newPlist = bplistCreate(obj);
|
||||
}
|
||||
fs.writeFile(plist, newPlist, function (err) {
|
||||
if (err) {
|
||||
logger.error("Could not save new Info.plist");
|
||||
cb(err);
|
||||
var newPlist;
|
||||
obj.UIDeviceFamily = [deviceTypeCode];
|
||||
if (binaryPlist) {
|
||||
newPlist = bplistCreate(obj);
|
||||
} else {
|
||||
logger.debug("Wrote new app Info.plist with device type");
|
||||
cb();
|
||||
newPlist = xmlplist.build(obj);
|
||||
}
|
||||
});
|
||||
});
|
||||
fs.writeFile(plist, newPlist, function (err) {
|
||||
if (err) {
|
||||
logger.error("Could not save new Info.plist");
|
||||
cb(err);
|
||||
} else {
|
||||
logger.debug("Wrote new app Info.plist with device type");
|
||||
cb();
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
IOS.prototype.getBundleIdFromApp = function (cb) {
|
||||
logger.debug("Getting bundle ID from app");
|
||||
var plist = path.resolve(this.args.app, "Info.plist");
|
||||
bplistParse.parseFile(plist, function (err, obj) {
|
||||
parsePlistFile(plist, function (err, obj) {
|
||||
if (err) {
|
||||
logger.error("Could not parse plist file at " + plist);
|
||||
logger.error("Could not get the bundleId from app.");
|
||||
cb(err, null);
|
||||
} else {
|
||||
logger.debug("Parsed app Info.plist");
|
||||
cb(null, obj[0].CFBundleIdentifier);
|
||||
}
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
IOS.prototype.checkDeviceAvailable = function (cb) {
|
||||
@@ -1058,17 +1075,9 @@ IOS.prototype.parseLocalizableStrings = function (cb, language) {
|
||||
strings = path.resolve(this.args.app, this.args.localizableStringsDir, "Localizable.strings");
|
||||
}
|
||||
|
||||
bplistParse.parseFile(strings, function (err, obj) {
|
||||
parsePlistFile(strings, function (err, obj) {
|
||||
if (err) {
|
||||
xmlPlistFile(strings, function (err, obj) {
|
||||
if (err) {
|
||||
logger.warn("Could not parse plist file at " + strings);
|
||||
} else {
|
||||
logger.debug("Parsed app Localizable.strings");
|
||||
this.localizableStrings = obj;
|
||||
}
|
||||
cb();
|
||||
}.bind(this));
|
||||
logger.warn("Could not parse app Localizable.strings");
|
||||
} else {
|
||||
logger.debug("Parsed app Localizable.strings");
|
||||
this.localizableStrings = obj;
|
||||
|
||||
Reference in New Issue
Block a user