@theia/process 1.53.0-next.4 → 1.53.0-next.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/common/shell-command-builder.slow-spec.js +4 -4
- package/package.json +4 -4
- package/src/common/process-common-module.ts +22 -22
- package/src/common/process-manager-types.ts +58 -58
- package/src/common/shell-command-builder.slow-spec.ts +486 -486
- package/src/common/shell-command-builder.ts +187 -187
- package/src/common/shell-quoting.spec.ts +176 -176
- package/src/common/shell-quoting.ts +236 -236
- package/src/common/tests/$weird(),file=name.js +1 -1
- package/src/common/tests/white space.js +1 -1
- package/src/node/dev-null-stream.ts +47 -47
- package/src/node/index.ts +22 -22
- package/src/node/multi-ring-buffer.spec.ts +486 -486
- package/src/node/multi-ring-buffer.ts +348 -348
- package/src/node/process-backend-module.ts +67 -67
- package/src/node/process-manager.ts +107 -107
- package/src/node/process.ts +207 -207
- package/src/node/pseudo-pty.ts +56 -56
- package/src/node/raw-process.spec.ts +199 -199
- package/src/node/raw-process.ts +156 -156
- package/src/node/string-argv.d.ts +21 -21
- package/src/node/task-terminal-process.ts +41 -41
- package/src/node/terminal-process.spec.ts +121 -121
- package/src/node/terminal-process.ts +290 -290
- package/src/node/test/process-fork-test.js +22 -22
- package/src/node/test/process-test-container.ts +27 -27
- package/src/node/utils.ts +79 -79
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ContainerModule, Container } from '@theia/core/shared/inversify';
|
|
18
|
-
import { RawProcess, RawProcessOptions, RawProcessFactory, RawForkOptions } from './raw-process';
|
|
19
|
-
import { TerminalProcess, TerminalProcessOptions, TerminalProcessFactory } from './terminal-process';
|
|
20
|
-
import { TaskTerminalProcess, TaskTerminalProcessFactory } from './task-terminal-process';
|
|
21
|
-
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
22
|
-
import { ProcessManager } from './process-manager';
|
|
23
|
-
import { ILogger } from '@theia/core/lib/common';
|
|
24
|
-
import { MultiRingBuffer, MultiRingBufferOptions } from './multi-ring-buffer';
|
|
25
|
-
|
|
26
|
-
export default new ContainerModule(bind => {
|
|
27
|
-
bind(RawProcess).toSelf().inTransientScope();
|
|
28
|
-
bind(ProcessManager).toSelf().inSingletonScope();
|
|
29
|
-
bind(BackendApplicationContribution).toService(ProcessManager);
|
|
30
|
-
bind(ILogger).toDynamicValue(ctx => {
|
|
31
|
-
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
|
32
|
-
return parentLogger.child('process');
|
|
33
|
-
}).inSingletonScope().whenTargetNamed('process');
|
|
34
|
-
bind(RawProcessFactory).toFactory(ctx =>
|
|
35
|
-
(options: RawProcessOptions | RawForkOptions) => {
|
|
36
|
-
const child = new Container({ defaultScope: 'Singleton' });
|
|
37
|
-
child.parent = ctx.container;
|
|
38
|
-
|
|
39
|
-
child.bind(RawProcessOptions).toConstantValue(options);
|
|
40
|
-
return child.get(RawProcess);
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
bind(TerminalProcess).toSelf().inTransientScope();
|
|
45
|
-
bind(TerminalProcessFactory).toFactory(ctx =>
|
|
46
|
-
(options: TerminalProcessOptions) => {
|
|
47
|
-
const child = new Container({ defaultScope: 'Singleton' });
|
|
48
|
-
child.parent = ctx.container;
|
|
49
|
-
|
|
50
|
-
child.bind(TerminalProcessOptions).toConstantValue(options);
|
|
51
|
-
return child.get(TerminalProcess);
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
bind(TaskTerminalProcess).toSelf().inTransientScope();
|
|
56
|
-
bind(TaskTerminalProcessFactory).toFactory(ctx =>
|
|
57
|
-
(options: TerminalProcessOptions) => {
|
|
58
|
-
const child = ctx.container.createChild();
|
|
59
|
-
child.bind(TerminalProcessOptions).toConstantValue(options);
|
|
60
|
-
return child.get(TaskTerminalProcess);
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
bind(MultiRingBuffer).toSelf().inTransientScope();
|
|
65
|
-
/* 1MB size, TODO should be a user preference. */
|
|
66
|
-
bind(MultiRingBufferOptions).toConstantValue({ size: 1048576 });
|
|
67
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule, Container } from '@theia/core/shared/inversify';
|
|
18
|
+
import { RawProcess, RawProcessOptions, RawProcessFactory, RawForkOptions } from './raw-process';
|
|
19
|
+
import { TerminalProcess, TerminalProcessOptions, TerminalProcessFactory } from './terminal-process';
|
|
20
|
+
import { TaskTerminalProcess, TaskTerminalProcessFactory } from './task-terminal-process';
|
|
21
|
+
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
22
|
+
import { ProcessManager } from './process-manager';
|
|
23
|
+
import { ILogger } from '@theia/core/lib/common';
|
|
24
|
+
import { MultiRingBuffer, MultiRingBufferOptions } from './multi-ring-buffer';
|
|
25
|
+
|
|
26
|
+
export default new ContainerModule(bind => {
|
|
27
|
+
bind(RawProcess).toSelf().inTransientScope();
|
|
28
|
+
bind(ProcessManager).toSelf().inSingletonScope();
|
|
29
|
+
bind(BackendApplicationContribution).toService(ProcessManager);
|
|
30
|
+
bind(ILogger).toDynamicValue(ctx => {
|
|
31
|
+
const parentLogger = ctx.container.get<ILogger>(ILogger);
|
|
32
|
+
return parentLogger.child('process');
|
|
33
|
+
}).inSingletonScope().whenTargetNamed('process');
|
|
34
|
+
bind(RawProcessFactory).toFactory(ctx =>
|
|
35
|
+
(options: RawProcessOptions | RawForkOptions) => {
|
|
36
|
+
const child = new Container({ defaultScope: 'Singleton' });
|
|
37
|
+
child.parent = ctx.container;
|
|
38
|
+
|
|
39
|
+
child.bind(RawProcessOptions).toConstantValue(options);
|
|
40
|
+
return child.get(RawProcess);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
bind(TerminalProcess).toSelf().inTransientScope();
|
|
45
|
+
bind(TerminalProcessFactory).toFactory(ctx =>
|
|
46
|
+
(options: TerminalProcessOptions) => {
|
|
47
|
+
const child = new Container({ defaultScope: 'Singleton' });
|
|
48
|
+
child.parent = ctx.container;
|
|
49
|
+
|
|
50
|
+
child.bind(TerminalProcessOptions).toConstantValue(options);
|
|
51
|
+
return child.get(TerminalProcess);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
bind(TaskTerminalProcess).toSelf().inTransientScope();
|
|
56
|
+
bind(TaskTerminalProcessFactory).toFactory(ctx =>
|
|
57
|
+
(options: TerminalProcessOptions) => {
|
|
58
|
+
const child = ctx.container.createChild();
|
|
59
|
+
child.bind(TerminalProcessOptions).toConstantValue(options);
|
|
60
|
+
return child.get(TaskTerminalProcess);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
bind(MultiRingBuffer).toSelf().inTransientScope();
|
|
65
|
+
/* 1MB size, TODO should be a user preference. */
|
|
66
|
+
bind(MultiRingBufferOptions).toConstantValue({ size: 1048576 });
|
|
67
|
+
});
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
17
|
-
import { Emitter, Event } from '@theia/core/lib/common';
|
|
18
|
-
import { ILogger } from '@theia/core/lib/common/logger';
|
|
19
|
-
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
20
|
-
import { ManagedProcessManager, ManagedProcess } from '../common/process-manager-types';
|
|
21
|
-
import { MAX_SAFE_INTEGER } from '@theia/core/lib/common/numbers';
|
|
22
|
-
import { Process } from './process';
|
|
23
|
-
|
|
24
|
-
@injectable()
|
|
25
|
-
export class ProcessManager implements ManagedProcessManager, BackendApplicationContribution {
|
|
26
|
-
|
|
27
|
-
protected readonly processes: Map<number, Process>;
|
|
28
|
-
protected readonly deleteEmitter: Emitter<number>;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
@inject(ILogger) @named('process') protected logger: ILogger
|
|
32
|
-
) {
|
|
33
|
-
this.processes = new Map();
|
|
34
|
-
this.deleteEmitter = new Emitter<number>();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Registers the given process into this manager. Both on process termination and on error,
|
|
39
|
-
* the process will be automatically removed from the manager.
|
|
40
|
-
*
|
|
41
|
-
* @param process the process to register.
|
|
42
|
-
*/
|
|
43
|
-
register(process: Process): number {
|
|
44
|
-
const id = this.generateId();
|
|
45
|
-
this.processes.set(id, process);
|
|
46
|
-
process.onError(() => this.unregister(process));
|
|
47
|
-
return id;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @returns a random id for a process that is not assigned to a different process yet.
|
|
52
|
-
*/
|
|
53
|
-
protected generateId(): number {
|
|
54
|
-
let id = undefined;
|
|
55
|
-
while (id === undefined) {
|
|
56
|
-
const candidate = Math.floor(Math.random() * MAX_SAFE_INTEGER);
|
|
57
|
-
if (!this.processes.has(candidate)) {
|
|
58
|
-
id = candidate;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return id;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Removes the process from this process manager. Invoking this method, will make
|
|
66
|
-
* sure that the process is terminated before eliminating it from the manager's cache.
|
|
67
|
-
*
|
|
68
|
-
* @param process the process to unregister from this process manager.
|
|
69
|
-
*/
|
|
70
|
-
unregister(process: ManagedProcess): void {
|
|
71
|
-
const processLabel = this.getProcessLabel(process);
|
|
72
|
-
this.logger.debug(`Unregistering process. ${processLabel}`);
|
|
73
|
-
if (!process.killed) {
|
|
74
|
-
this.logger.debug(`Ensuring process termination. ${processLabel}`);
|
|
75
|
-
process.kill();
|
|
76
|
-
}
|
|
77
|
-
if (this.processes.delete(process.id)) {
|
|
78
|
-
this.deleteEmitter.fire(process.id);
|
|
79
|
-
this.logger.debug(`The process was successfully unregistered. ${processLabel}`);
|
|
80
|
-
} else {
|
|
81
|
-
this.logger.warn(`This process was not registered or was already unregistered. ${processLabel}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get(id: number): ManagedProcess | undefined {
|
|
86
|
-
return this.processes.get(id);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get onDelete(): Event<number> {
|
|
90
|
-
return this.deleteEmitter.event;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
onStop(): void {
|
|
94
|
-
for (const process of this.processes.values()) {
|
|
95
|
-
try {
|
|
96
|
-
this.unregister(process);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
this.logger.error(`Error occurred when unregistering process. ${this.getProcessLabel(process)}`, error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private getProcessLabel(process: ManagedProcess): string {
|
|
104
|
-
return `[ID: ${process.id}]`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
17
|
+
import { Emitter, Event } from '@theia/core/lib/common';
|
|
18
|
+
import { ILogger } from '@theia/core/lib/common/logger';
|
|
19
|
+
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
20
|
+
import { ManagedProcessManager, ManagedProcess } from '../common/process-manager-types';
|
|
21
|
+
import { MAX_SAFE_INTEGER } from '@theia/core/lib/common/numbers';
|
|
22
|
+
import { Process } from './process';
|
|
23
|
+
|
|
24
|
+
@injectable()
|
|
25
|
+
export class ProcessManager implements ManagedProcessManager, BackendApplicationContribution {
|
|
26
|
+
|
|
27
|
+
protected readonly processes: Map<number, Process>;
|
|
28
|
+
protected readonly deleteEmitter: Emitter<number>;
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
@inject(ILogger) @named('process') protected logger: ILogger
|
|
32
|
+
) {
|
|
33
|
+
this.processes = new Map();
|
|
34
|
+
this.deleteEmitter = new Emitter<number>();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Registers the given process into this manager. Both on process termination and on error,
|
|
39
|
+
* the process will be automatically removed from the manager.
|
|
40
|
+
*
|
|
41
|
+
* @param process the process to register.
|
|
42
|
+
*/
|
|
43
|
+
register(process: Process): number {
|
|
44
|
+
const id = this.generateId();
|
|
45
|
+
this.processes.set(id, process);
|
|
46
|
+
process.onError(() => this.unregister(process));
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns a random id for a process that is not assigned to a different process yet.
|
|
52
|
+
*/
|
|
53
|
+
protected generateId(): number {
|
|
54
|
+
let id = undefined;
|
|
55
|
+
while (id === undefined) {
|
|
56
|
+
const candidate = Math.floor(Math.random() * MAX_SAFE_INTEGER);
|
|
57
|
+
if (!this.processes.has(candidate)) {
|
|
58
|
+
id = candidate;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return id;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Removes the process from this process manager. Invoking this method, will make
|
|
66
|
+
* sure that the process is terminated before eliminating it from the manager's cache.
|
|
67
|
+
*
|
|
68
|
+
* @param process the process to unregister from this process manager.
|
|
69
|
+
*/
|
|
70
|
+
unregister(process: ManagedProcess): void {
|
|
71
|
+
const processLabel = this.getProcessLabel(process);
|
|
72
|
+
this.logger.debug(`Unregistering process. ${processLabel}`);
|
|
73
|
+
if (!process.killed) {
|
|
74
|
+
this.logger.debug(`Ensuring process termination. ${processLabel}`);
|
|
75
|
+
process.kill();
|
|
76
|
+
}
|
|
77
|
+
if (this.processes.delete(process.id)) {
|
|
78
|
+
this.deleteEmitter.fire(process.id);
|
|
79
|
+
this.logger.debug(`The process was successfully unregistered. ${processLabel}`);
|
|
80
|
+
} else {
|
|
81
|
+
this.logger.warn(`This process was not registered or was already unregistered. ${processLabel}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get(id: number): ManagedProcess | undefined {
|
|
86
|
+
return this.processes.get(id);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get onDelete(): Event<number> {
|
|
90
|
+
return this.deleteEmitter.event;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onStop(): void {
|
|
94
|
+
for (const process of this.processes.values()) {
|
|
95
|
+
try {
|
|
96
|
+
this.unregister(process);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.logger.error(`Error occurred when unregistering process. ${this.getProcessLabel(process)}`, error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private getProcessLabel(process: ManagedProcess): string {
|
|
104
|
+
return `[ID: ${process.id}]`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
}
|