Skip to content

Commit dba4052

Browse files
committed
Services refactoring
1 parent ee426f7 commit dba4052

19 files changed

+248
-266
lines changed

src/debug-adapter/adapter/adapterProxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import * as utils from '../utilities';
6-
import {Logger} from '../../services/Logger';
6+
import {DebugAdapterServices as Services} from '../../services/services/debugAdapterServices';
77
import {DebugProtocol} from 'vscode-debugprotocol';
88

99
export type EventHandler = (event: DebugProtocol.Event) => void;
@@ -78,7 +78,7 @@ export class AdapterProxy {
7878
this._eventHandler(event);
7979
}
8080
} catch (e) {
81-
Logger.error('Error handling adapter event: ' + (e ? e.stack : ''));
81+
Services.logger.error('Error handling adapter event: ' + (e ? e.stack : ''));
8282
}
8383
}
8484
}

src/debug-adapter/adapter/pathTransformer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*--------------------------------------------------------*/
44

55
import * as utils from '../utilities';
6-
import {Logger} from '../../services/Logger';
6+
import {DebugAdapterServices as Services} from '../../services/services/debugAdapterServices';
77
import {DebugProtocol} from 'vscode-debugprotocol';
88
import * as path from 'path';
99

@@ -44,15 +44,15 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
4444

4545
if (utils.isURL(args.source.path)) {
4646
// already a url, use as-is
47-
Logger.log(`Paths.setBP: ${args.source.path} is already a URL`);
47+
Services.logger.log(`Paths.setBP: ${args.source.path} is already a URL`);
4848
resolve();
4949
return;
5050
}
5151

5252
const url = utils.canonicalizeUrl(args.source.path);
5353
if (this._clientPathToWebkitUrl.has(url)) {
5454
args.source.path = this._clientPathToWebkitUrl.get(url);
55-
Logger.log(`Paths.setBP: Resolved ${url} to ${args.source.path}`);
55+
Services.logger.log(`Paths.setBP: Resolved ${url} to ${args.source.path}`);
5656
resolve();
5757
}
5858
else if (this.inferedDeviceRoot) {
@@ -72,11 +72,11 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
7272
inferedUrl = inferedUrl.replace(`.${this._platform}.`, '.');
7373

7474
args.source.path = inferedUrl;
75-
Logger.log(`Paths.setBP: Resolved (by infering) ${url} to ${args.source.path}`);
75+
Services.logger.log(`Paths.setBP: Resolved (by infering) ${url} to ${args.source.path}`);
7676
resolve();
7777
}
7878
else {
79-
Logger.log(`Paths.setBP: No target url cached for client path: ${url}, waiting for target script to be loaded.`);
79+
Services.logger.log(`Paths.setBP: No target url cached for client path: ${url}, waiting for target script to be loaded.`);
8080
args.source.path = url;
8181
this._pendingBreakpointsByPath.set(args.source.path, { resolve, reject, args });
8282
}
@@ -97,7 +97,7 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
9797
if (!this.inferedDeviceRoot && this._platform === "android")
9898
{
9999
this.inferedDeviceRoot = utils.inferDeviceRoot(this._appRoot, this._platform, webkitUrl);
100-
Logger.log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");
100+
Services.logger.log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");
101101

102102
if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1)
103103
{
@@ -108,17 +108,17 @@ export class PathTransformer implements DebugProtocol.IDebugTransformer {
108108
const clientPath = utils.webkitUrlToClientPath(this._appRoot, this._platform, webkitUrl);
109109

110110
if (!clientPath) {
111-
Logger.log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._appRoot}`);
111+
Services.logger.log(`Paths.scriptParsed: could not resolve ${webkitUrl} to a file in the workspace. webRoot: ${this._appRoot}`);
112112
} else {
113-
Logger.log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._appRoot}`);
113+
Services.logger.log(`Paths.scriptParsed: resolved ${webkitUrl} to ${clientPath}. webRoot: ${this._appRoot}`);
114114
this._clientPathToWebkitUrl.set(clientPath, webkitUrl);
115115
this._webkitUrlToClientPath.set(webkitUrl, clientPath);
116116

117117
event.body.scriptUrl = clientPath;
118118
}
119119

120120
if (this._pendingBreakpointsByPath.has(event.body.scriptUrl)) {
121-
Logger.log(`Paths.scriptParsed: Resolving pending breakpoints for ${event.body.scriptUrl}`);
121+
Services.logger.log(`Paths.scriptParsed: Resolving pending breakpoints for ${event.body.scriptUrl}`);
122122
const pendingBreakpoint = this._pendingBreakpointsByPath.get(event.body.scriptUrl);
123123
this._pendingBreakpointsByPath.delete(event.body.scriptUrl);
124124
this.setBreakpoints(pendingBreakpoint.args).then(pendingBreakpoint.resolve, pendingBreakpoint.reject);

src/debug-adapter/adapter/sourceMaps/pathUtilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import * as Path from 'path';
88
import * as URL from 'url';
9-
import {Logger} from '../../../services/Logger';
9+
import {DebugAdapterServices as Services} from '../../../services/services/debugAdapterServices';
1010
import * as utils from '../../utilities';
1111

1212
export function getPathRoot(p: string) {
@@ -83,16 +83,16 @@ export function getAbsSourceRoot(sourceRoot: string, webRoot: string, generatedP
8383
}
8484
}
8585

86-
Logger.log(`SourceMap: resolved sourceRoot ${sourceRoot} -> ${absSourceRoot}`);
86+
Services.logger.log(`SourceMap: resolved sourceRoot ${sourceRoot} -> ${absSourceRoot}`);
8787
} else {
8888
if (Path.isAbsolute(generatedPath)) {
8989
absSourceRoot = Path.dirname(generatedPath);
90-
Logger.log(`SourceMap: no sourceRoot specified, using script dirname: ${absSourceRoot}`);
90+
Services.logger.log(`SourceMap: no sourceRoot specified, using script dirname: ${absSourceRoot}`);
9191
} else {
9292
// runtime script is not on disk, resolve the sourceRoot location on disk
9393
const scriptPathDirname = Path.dirname(URL.parse(generatedPath).pathname);
9494
absSourceRoot = Path.join(webRoot, scriptPathDirname);
95-
Logger.log(`SourceMap: no sourceRoot specified, using webRoot + script path dirname: ${absSourceRoot}`);
95+
Services.logger.log(`SourceMap: no sourceRoot specified, using webRoot + script path dirname: ${absSourceRoot}`);
9696
}
9797
}
9898

src/debug-adapter/adapter/sourceMaps/sourceMapTransformer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import * as path from 'path';
66
import * as fs from 'fs';
7-
import {Logger} from '../../../services/Logger';
7+
import {DebugAdapterServices as Services} from '../../../services/services/debugAdapterServices';
88
import {DebugProtocol} from 'vscode-debugprotocol';
99
import {ISourceMaps, SourceMaps} from './sourceMaps';
1010
import * as utils from '../../utilities';
@@ -60,7 +60,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
6060
const argsPath = args.source.path;
6161
const mappedPath = this._sourceMaps.MapPathFromSource(argsPath);
6262
if (mappedPath) {
63-
Logger.log(`SourceMaps.setBP: Mapped ${argsPath} to ${mappedPath}`);
63+
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath} to ${mappedPath}`);
6464
args.authoredPath = argsPath;
6565
args.source.path = mappedPath;
6666

@@ -69,11 +69,11 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
6969
const mappedLines = args.lines.map((line, i) => {
7070
const mapped = this._sourceMaps.MapFromSource(argsPath, line, /*column=*/0);
7171
if (mapped) {
72-
Logger.log(`SourceMaps.setBP: Mapped ${argsPath}:${line}:0 to ${mappedPath}:${mapped.line}:${mapped.column}`);
72+
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath}:${line}:0 to ${mappedPath}:${mapped.line}:${mapped.column}`);
7373
mappedCols[i] = mapped.column;
7474
return mapped.line;
7575
} else {
76-
Logger.log(`SourceMaps.setBP: Mapped ${argsPath} but not line ${line}, column 0`);
76+
Services.logger.log(`SourceMaps.setBP: Mapped ${argsPath} but not line ${line}, column 0`);
7777
mappedCols[i] = 0;
7878
return line;
7979
}
@@ -101,10 +101,10 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
101101
});
102102
} else if (this._allRuntimeScriptPaths.has(argsPath)) {
103103
// It's a generated file which is loaded
104-
Logger.log(`SourceMaps.setBP: SourceMaps are enabled but ${argsPath} is a runtime script`);
104+
Services.logger.log(`SourceMaps.setBP: SourceMaps are enabled but ${argsPath} is a runtime script`);
105105
} else {
106106
// Source (or generated) file which is not loaded, need to wait
107-
Logger.log(`SourceMaps.setBP: ${argsPath} can't be resolved to a loaded script.`);
107+
Services.logger.log(`SourceMaps.setBP: ${argsPath} can't be resolved to a loaded script.`);
108108
this._pendingBreakpointsByPath.set(argsPath, { resolve, reject, args, requestSeq });
109109
return;
110110
}
@@ -132,10 +132,10 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
132132
response.breakpoints.forEach((bp, i) => {
133133
const mapped = this._sourceMaps.MapToSource(args.source.path, args.lines[i], args.cols[i]);
134134
if (mapped) {
135-
Logger.log(`SourceMaps.setBP: Mapped ${args.source.path}:${bp.line}:${bp.column} to ${mapped.path}:${mapped.line}`);
135+
Services.logger.log(`SourceMaps.setBP: Mapped ${args.source.path}:${bp.line}:${bp.column} to ${mapped.path}:${mapped.line}`);
136136
bp.line = mapped.line;
137137
} else {
138-
Logger.log(`SourceMaps.setBP: Can't map ${args.source.path}:${bp.line}:${bp.column}, keeping the line number as-is.`);
138+
Services.logger.log(`SourceMaps.setBP: Can't map ${args.source.path}:${bp.line}:${bp.column}, keeping the line number as-is.`);
139139
}
140140

141141
this._requestSeqToSetBreakpointsArgs.delete(requestSeq);
@@ -201,7 +201,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
201201
this._sourceMaps.ProcessNewSourceMap(event.body.scriptUrl, sourceMapUrlValue).then(() => {
202202
const sources = this._sourceMaps.AllMappedSources(event.body.scriptUrl);
203203
if (sources) {
204-
Logger.log(`SourceMaps.scriptParsed: ${event.body.scriptUrl} was just loaded and has mapped sources: ${JSON.stringify(sources)}`);
204+
Services.logger.log(`SourceMaps.scriptParsed: ${event.body.scriptUrl} was just loaded and has mapped sources: ${JSON.stringify(sources)}`);
205205
sources.forEach(this.resolvePendingBreakpoints, this);
206206
}
207207
});
@@ -241,7 +241,7 @@ export class SourceMapTransformer implements DebugProtocol.IDebugTransformer {
241241
private resolvePendingBreakpoints(sourcePath: string): void {
242242
// If there's a setBreakpoints request waiting on this script, go through setBreakpoints again
243243
if (this._pendingBreakpointsByPath.has(sourcePath)) {
244-
Logger.log(`SourceMaps.scriptParsed: Resolving pending breakpoints for ${sourcePath}`);
244+
Services.logger.log(`SourceMaps.scriptParsed: Resolving pending breakpoints for ${sourcePath}`);
245245
const pendingBreakpoint = this._pendingBreakpointsByPath.get(sourcePath);
246246
this._pendingBreakpointsByPath.delete(sourcePath);
247247

src/debug-adapter/adapter/sourceMaps/sourceMaps.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as FS from 'fs';
1010
import {SourceMapConsumer} from 'source-map';
1111
import * as PathUtils from './pathUtilities';
1212
import * as utils from '../../utilities';
13-
import {Logger} from '../../../services/Logger';
13+
import {DebugAdapterServices as Services} from '../../../services/services/debugAdapterServices';
1414

1515

1616
export interface MappingResult {
@@ -191,7 +191,7 @@ export class SourceMaps implements ISourceMaps {
191191
const matches = SourceMaps.SOURCE_MAPPING_MATCHER.exec(line);
192192
if (matches && matches.length === 2) {
193193
const uri = matches[1].trim();
194-
Logger.log(`_findSourceMapUrlInFile: source map url at end of generated file '${generatedFilePath}''`);
194+
Services.logger.log(`_findSourceMapUrlInFile: source map url at end of generated file '${generatedFilePath}''`);
195195
return uri;
196196
}
197197
}
@@ -329,7 +329,7 @@ export class SourceMaps implements ISourceMaps {
329329
}
330330

331331
if (!FS.existsSync(generatedFilePath)) {
332-
Logger.log("findGeneratedToSourceMappingSync: can't find the sourceMapping for file: " + generatedFilePath);
332+
Services.logger.log("findGeneratedToSourceMappingSync: can't find the sourceMapping for file: " + generatedFilePath);
333333
return null;
334334
}
335335

@@ -379,7 +379,7 @@ export class SourceMaps implements ISourceMaps {
379379
}
380380
}
381381
catch (e) {
382-
Logger.log(`can't parse inlince sourcemap. exception while processing data url (${e.stack})`);
382+
Services.logger.log(`can't parse inlince sourcemap. exception while processing data url (${e.stack})`);
383383
}
384384
}
385385

@@ -390,14 +390,14 @@ export class SourceMaps implements ISourceMaps {
390390
let contentsP: Promise<string>;
391391
if (utils.isURL(mapPath)) {
392392
contentsP = utils.getURL(mapPath).catch(e => {
393-
Logger.log(`SourceMaps.createSourceMap: Could not download map from ${mapPath}`);
393+
Services.logger.log(`SourceMaps.createSourceMap: Could not download map from ${mapPath}`);
394394
return null;
395395
});
396396
} else {
397397
contentsP = new Promise((resolve, reject) => {
398398
FS.readFile(mapPath, (err, data) => {
399399
if (err) {
400-
Logger.log(`SourceMaps.createSourceMap: Could not read map from ${mapPath}`);
400+
Services.logger.log(`SourceMaps.createSourceMap: Could not read map from ${mapPath}`);
401401
resolve(null);
402402
} else {
403403
resolve(data);
@@ -412,7 +412,7 @@ export class SourceMaps implements ISourceMaps {
412412
// Throws for invalid contents JSON
413413
return new SourceMap(pathToGenerated, contents, this._webRoot);
414414
} catch (e) {
415-
Logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
415+
Services.logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
416416
return null;
417417
}
418418
} else {
@@ -427,7 +427,7 @@ export class SourceMaps implements ISourceMaps {
427427
// Throws for invalid contents JSON
428428
return new SourceMap(pathToGenerated, contents, this._webRoot);
429429
} catch (e) {
430-
Logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
430+
Services.logger.log(`SourceMaps.createSourceMap: exception while processing sourcemap: ${e.stack}`);
431431
return null;
432432
}
433433
}
@@ -452,7 +452,7 @@ class SourceMap {
452452
* webRoot - an absolute path
453453
*/
454454
public constructor(generatedPath: string, json: string, webRoot: string) {
455-
Logger.log(`SourceMap: creating SM for ${generatedPath}`)
455+
Services.logger.log(`SourceMap: creating SM for ${generatedPath}`)
456456
this._generatedPath = generatedPath;
457457
this._webRoot = webRoot;
458458

src/debug-adapter/connection/androidConnection.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as http from 'http';
22
import {EventEmitter} from 'events';
3-
import {Logger} from '../../services/Logger';
3+
import {DebugAdapterServices as Services} from '../../services/services/debugAdapterServices';
44
import * as Net from 'net';
5-
import * as ns from '../../services/NsCliService';
65
import { INSDebugConnection } from './INSDebugConnection';
76

87

@@ -137,7 +136,7 @@ class ResReqNetSocket extends EventEmitter {
137136
this.debugBuffer = b.toString('utf8', this.msg.contentLength, b.length);
138137
if (this.msg.body.length > 0) {
139138
obj = JSON.parse(this.msg.body);
140-
Logger.log('From target(' + (obj.type ? obj.type : '') + '): ' + this.msg.body);
139+
Services.logger.log('From target(' + (obj.type ? obj.type : '') + '): ' + this.msg.body);
141140
if (typeof obj.running === 'boolean') {
142141
this.isRunning = obj.running;
143142
}
@@ -182,7 +181,7 @@ class ResReqNetSocket extends EventEmitter {
182181

183182
public send(data) {
184183
if (this.connected) {
185-
Logger.log('To target: ' + data);
184+
Services.logger.log('To target: ' + data);
186185
this.conn.write('Content-Length: ' + data.length + '\r\n\r\n' + data);
187186
this.hasNewDataMessage = true;
188187
if (!this.isMessageFlushLoopStarted) {
@@ -438,7 +437,7 @@ export class AndroidConnection implements INSDebugConnection {
438437
}
439438

440439
public attach(port: number, url?: string): Promise<void> {
441-
Logger.log('Attempting to attach on port ' + port);
440+
Services.logger.log('Attempting to attach on port ' + port);
442441
return this._attach(port, url);
443442
//.then(() => this.sendMessage('Console.enable'))
444443
}

src/debug-adapter/connection/iosConnection.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import * as stream from 'stream';
77
import {EventEmitter} from 'events';
88
import {INSDebugConnection} from './INSDebugConnection';
99
import * as utils from '../utilities';
10-
import {Logger} from '../../services/Logger';
11-
import * as ns from '../../services/NsCliService';
10+
import {DebugAdapterServices as Services} from '../../services/services/debugAdapterServices';
1211

1312
interface IMessageWithId {
1413
id: number;
@@ -74,7 +73,7 @@ class ResReqTcpSocket extends EventEmitter {
7473
});
7574

7675
unixSocket.on('close', () => {
77-
Logger.log('Unix socket closed');
76+
Services.logger.log('Unix socket closed');
7877
this.emit('close');
7978
});
8079

@@ -83,7 +82,7 @@ class ResReqTcpSocket extends EventEmitter {
8382

8483
packetsStream.on('data', (buffer: Buffer) => {
8584
let packet = buffer.toString('utf16le');
86-
Logger.log('From target: ' + packet);
85+
Services.logger.log('From target: ' + packet);
8786
this.onMessage(JSON.parse(packet));
8887
});
8988
} catch (e) {
@@ -111,7 +110,7 @@ class ResReqTcpSocket extends EventEmitter {
111110
this._pendingRequests.set(message.id, resolve);
112111
this._unixSocketAttached.then(socket => {
113112
const msgStr = JSON.stringify(message);
114-
Logger.log('To target: ' + msgStr);
113+
Services.logger.log('To target: ' + msgStr);
115114
let encoding = "utf16le";
116115
let length = Buffer.byteLength(msgStr, encoding);
117116
let payload = new Buffer(length + 4);
@@ -156,7 +155,7 @@ export class IosConnection implements INSDebugConnection {
156155
* Attach the underlying Unix socket
157156
*/
158157
public attach(filePath: string): Promise<void> {
159-
Logger.log('Attempting to attach to path ' + filePath);
158+
Services.logger.log('Attempting to attach to path ' + filePath);
160159
return utils.retryAsync(() => this._attach(filePath), 6000)
161160
.then(() => {
162161
Promise.all<WebKitProtocol.Response>([

0 commit comments

Comments
 (0)