Skip to content

Commit 399eb94

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #44 from telerik/fatme/fix-get-application-path-on-xcode-6
Fix getApplicationPath on xcode6
2 parents bf87d94 + 68a49a1 commit 399eb94

9 files changed

+69
-20
lines changed

lib/command-executor.js

+9-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/declarations.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface IiPhoneSimulator {
66
printDeviceTypes(): IFuture<void>;
77
printSDKS(): IFuture<void>;
88
sendNotification(notification: string): IFuture<void>;
9+
createSimulator(): IFuture<ISimulator>;
910
}
1011

1112
interface ICommand {
@@ -31,6 +32,7 @@ interface ISimctl {
3132
uninstall(deviceId: string, applicationIdentifier: string): IFuture<void>;
3233
notifyPost(deviceId: string, notification: string): IFuture<void>;
3334
getDevices(): IFuture<IDevice[]>;
35+
getAppContainer(deviceId: string, applicationIdentifier: string): IFuture<string>;
3436
}
3537

3638
interface IDictionary<T> {
@@ -47,6 +49,7 @@ interface ISimulator {
4749
getSdks(): IFuture<ISdk[]>;
4850
run(applicationPath: string, applicationIdentifier: string): IFuture<void>;
4951
sendNotification(notification: string): IFuture<void>;
52+
getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string>;
5053
}
5154

5255
interface IExecuteOptions {

lib/ios-sim.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ Object.defineProperty(global.publicApi, "getRunningSimulator", {
4242
Object.defineProperty(global.publicApi, "getApplicationPath", {
4343
get: () => {
4444
return (...args: any[]) => {
45-
let libraryPath = require("./simctl");
46-
let obj = new libraryPath.Simctl()
47-
let result = obj.getAppContainer.apply(obj, args).wait();
45+
let libraryPath = require("./iphone-simulator");
46+
let obj = new libraryPath.iPhoneSimulator();
47+
let simulator = obj.createSimulator().wait();
48+
let result = simulator.getApplicationPath.apply(simulator, args).wait();
4849
return result;
4950
}
5051
}

lib/iphone-simulator-xcode-5.ts

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
5959
return Future.fromResult();
6060
}
6161

62+
public getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string> {
63+
return Future.fromResult("");
64+
}
65+
6266
private get deviceIdentifier(): string {
6367
let identifier = options.device || XCode5Simulator.DEFAULT_DEVICE_IDENTIFIER;
6468
return XCode5Simulator.allowedDeviceIdentifiers[identifier];

lib/iphone-simulator-xcode-6.ts

+41
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import * as errors from "./errors";
44
import * as options from "./options";
55
import * as utils from "./utils";
6+
import * as fs from "fs";
7+
import Future = require("fibers/future");
8+
import * as path from "path";
69
import * as util from "util";
710
import * as os from "os";
811
let $ = require("nodobjc");
12+
let bplistParser = require("bplist-parser");
13+
let osenv = require("osenv");
914

1015
import iPhoneSimulatorBaseLib = require("./iphone-interop-simulator-base");
1116

@@ -39,6 +44,42 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
3944
return this.execute(() => this.sdks, { canRunMainLoop: false });
4045
}
4146

47+
public getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string> {
48+
return (() => {
49+
let rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Containers/Bundle/Application`);
50+
if(!fs.existsSync(rootApplicationsPath)) {
51+
rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Applications`);
52+
}
53+
let applicationGuids = fs.readdirSync(rootApplicationsPath);
54+
let result: string = null;
55+
_.each(applicationGuids, applicationGuid => {
56+
let fullApplicationPath = path.join(rootApplicationsPath, applicationGuid);
57+
let applicationDirContents = fs.readdirSync(fullApplicationPath);
58+
let applicationName = _.find(applicationDirContents, fileName => path.extname(fileName) === ".app");
59+
let plistFilePath = path.join(fullApplicationPath, applicationName, "Info.plist");
60+
let applicationData = this.parseFile(plistFilePath).wait();
61+
if(applicationData[0].CFBundleIdentifier === applicationIdentifier) {
62+
result = path.join(fullApplicationPath, applicationName);
63+
return false;
64+
}
65+
});
66+
67+
return result;
68+
}).future<string>()();
69+
}
70+
71+
private parseFile(plistFilePath: string): IFuture<any> {
72+
let future = new Future<any>();
73+
bplistParser.parseFile(plistFilePath, (err: Error, obj: any) => {
74+
if(err) {
75+
future.throw(err);
76+
} else {
77+
future.return(obj);
78+
}
79+
});
80+
return future;
81+
}
82+
4283
private get devices(): IDevice[] {
4384
if(!this.cachedDevices) {
4485
this.cachedDevices = [];

lib/iphone-simulator-xcode-7.ts

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class XCode7Simulator implements ISimulator {
7070
}).future<void>()();
7171
}
7272

73+
public getApplicationPath(deviceId: string, applicationIdentifier: string): IFuture<string> {
74+
return this.simctl.getAppContainer(deviceId, applicationIdentifier);
75+
}
76+
7377
private getDeviceToRun(): IFuture<IDevice> {
7478
return (() => {
7579
let devices = this.simctl.getDevices().wait();

lib/iphone-simulator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class iPhoneSimulator implements IiPhoneSimulator {
7575
return this.simulator.sendNotification(notification);
7676
}
7777

78-
private createSimulator(): IFuture<ISimulator> {
78+
public createSimulator(): IFuture<ISimulator> {
7979
return (() => {
8080
let xcodeVersionData = xcode.getXcodeVersionData().wait();
8181
let majorVersion = xcodeVersionData.major;

lib/simctl.ts

-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import errors = require("./errors");
77
import options = require("./options");
88

99
export class Simctl implements ISimctl {
10-
private devices: IDevice[] = null;
1110

1211
public launch(deviceId: string, applicationIdentifier: string): IFuture<void> {
1312
let args: string[] = [];
@@ -42,16 +41,6 @@ export class Simctl implements ISimctl {
4241
}
4342

4443
public getDevices(): IFuture<IDevice[]> {
45-
return (() => {
46-
if(!this.devices) {
47-
this.devices = this.getDevicesCore().wait();
48-
}
49-
50-
return this.devices;
51-
}).future<IDevice[]>()();
52-
}
53-
54-
private getDevicesCore(): IFuture<IDevice[]> {
5544
return (() => {
5645
let rawDevices = this.simctlExec("list", ["devices"]).wait();
5746

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "1.0.13-gamma",
3+
"version": "1.0.13-delta",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {
@@ -26,10 +26,12 @@
2626
},
2727
"homepage": "https://github.com/telerik/ios-sim-portable",
2828
"dependencies": {
29+
"bplist-parser": "0.1.0",
2930
"colors": "0.6.2",
3031
"fibers": "https://github.com/icenium/node-fibers/tarball/v1.0.6.0",
3132
"lodash": "3.2.0",
3233
"nodobjc": "https://github.com/telerik/NodObjC/tarball/v2.0.0.0",
34+
"osenv": "0.1.3",
3335
"yargs": "3.15.0"
3436
},
3537
"devDependencies": {

0 commit comments

Comments
 (0)