This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-11954: Add che.registerTaskRunner Theia Plugin API (#8)
- Loading branch information
Showing
13 changed files
with
512 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
yarn-error.log | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
extensions/eclipse-che-theia-plugin-ext/src/browser/che-task-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2018 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
import { CheTaskClient } from '../common/che-protocol'; | ||
import { Emitter, Event } from '@theia/core'; | ||
import { injectable } from 'inversify'; | ||
import { TaskConfiguration, TaskInfo } from '@eclipse-che/plugin'; | ||
|
||
@injectable() | ||
export class CheTaskClientImpl implements CheTaskClient { | ||
private readonly onKillEventEmitter: Emitter<number>; | ||
private taskInfoHandler: ((id: number) => Promise<TaskInfo>) | undefined; | ||
private runTaskHandler: ((id: number, config: TaskConfiguration, ctx?: string) => Promise<void>) | undefined; | ||
constructor() { | ||
this.onKillEventEmitter = new Emitter<number>(); | ||
} | ||
|
||
async runTask(id: number, taskConfig: TaskConfiguration, ctx?: string): Promise<void> { | ||
if (this.runTaskHandler) { | ||
return await this.runTaskHandler(id, taskConfig, ctx); | ||
} | ||
} | ||
|
||
async getTaskInfo(id: number): Promise<TaskInfo | undefined> { | ||
if (this.taskInfoHandler) { | ||
return await this.taskInfoHandler(id); | ||
} | ||
} | ||
|
||
get onKillEvent(): Event<number> { | ||
return this.onKillEventEmitter.event; | ||
} | ||
|
||
async killTask(id: number): Promise<void> { | ||
this.onKillEventEmitter.fire(id); | ||
} | ||
|
||
setTaskInfoHandler(handler: (id: number) => Promise<TaskInfo>) { | ||
this.taskInfoHandler = handler; | ||
} | ||
|
||
setRunTaskHandler(handler: (id: number, config: TaskConfiguration, ctx?: string) => Promise<void>) { | ||
this.runTaskHandler = handler; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
extensions/eclipse-che-theia-plugin-ext/src/browser/che-task-main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2018 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
import { CheTask, CheTaskMain, CheTaskService, CheTaskClient, PLUGIN_RPC_CONTEXT } from '../common/che-protocol'; | ||
import { RPCProtocol } from '@theia/plugin-ext/lib/api/rpc-protocol'; | ||
import { interfaces, injectable } from 'inversify'; | ||
|
||
@injectable() | ||
export class CheTaskMainImpl implements CheTaskMain { | ||
private readonly delegate: CheTaskService; | ||
private readonly cheTaskClient: CheTaskClient; | ||
constructor(container: interfaces.Container, rpc: RPCProtocol) { | ||
const proxy: CheTask = rpc.getProxy(PLUGIN_RPC_CONTEXT.CHE_TASK); | ||
this.delegate = container.get(CheTaskService); | ||
this.cheTaskClient = container.get(CheTaskClient); | ||
this.cheTaskClient.onKillEvent(id => proxy.$killTask(id)); | ||
this.cheTaskClient.setTaskInfoHandler(id => proxy.$getTaskInfo(id)); | ||
this.cheTaskClient.setRunTaskHandler((id, config, ctx) => proxy.$runTask(id, config, ctx)); | ||
} | ||
$registerTaskRunner(type: string): Promise<void> { | ||
return this.delegate.registerTaskRunner(type); | ||
} | ||
|
||
$disposeTaskRunner(type: string): Promise<void> { | ||
return this.delegate.disposeTaskRunner(type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
extensions/eclipse-che-theia-plugin-ext/src/node/che-task-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2018 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
import { CheTaskClient, CheTaskService } from '../common/che-protocol'; | ||
import { injectable, interfaces } from 'inversify'; | ||
import { Task, TaskManager, TaskOptions, TaskRunnerRegistry } from '@theia/task/lib/node' | ||
import { Disposable, ILogger } from '@theia/core'; | ||
import { TaskConfiguration, TaskInfo } from '@theia/task/lib/common/task-protocol'; | ||
|
||
@injectable() | ||
export class CheTaskServiceImpl implements CheTaskService { | ||
private readonly runnerRegistry: TaskRunnerRegistry; | ||
private readonly taskManager: TaskManager; | ||
private readonly logger: ILogger; | ||
private readonly disposableMap: Map<string, Disposable>; | ||
private readonly clients: CheTaskClient[]; | ||
private taskId: number; | ||
constructor(container: interfaces.Container) { | ||
this.runnerRegistry = container.get(TaskRunnerRegistry); | ||
this.taskManager = container.get(TaskManager); | ||
this.logger = container.get(ILogger); | ||
this.disposableMap = new Map(); | ||
this.clients = []; | ||
this.taskId = 0; | ||
} | ||
|
||
async registerTaskRunner(type: string): Promise<void> { | ||
const runner = { | ||
run(taskConfig: TaskConfiguration, ctx?: string): Promise<Task> { | ||
return runTask(taskConfig, ctx); | ||
} | ||
}; | ||
this.disposableMap.set(type, this.runnerRegistry.registerRunner(type, runner)); | ||
const runTask = async (config: TaskConfiguration, ctx?: string): Promise<Task> => { | ||
const id = this.taskId++; | ||
for (const client of this.clients) { | ||
await client.runTask(id, config, ctx); | ||
} | ||
return new CheTask(id, this.taskManager, this.logger, { label: config.label, config }, this.clients); | ||
}; | ||
} | ||
|
||
dispose() { | ||
// do nothing | ||
} | ||
|
||
setClient(client: CheTaskClient) { | ||
this.clients.push(client); | ||
} | ||
|
||
async disposeTaskRunner(type: string): Promise<void> { | ||
const disposable = this.disposableMap.get(type); | ||
if (disposable) { | ||
disposable.dispose(); | ||
} | ||
} | ||
|
||
async disconnectClient(client: CheTaskClient) { | ||
const idx = this.clients.indexOf(client); | ||
if (idx > -1) { | ||
this.clients.splice(idx, 1); | ||
} | ||
} | ||
} | ||
|
||
class CheTask extends Task { | ||
private readonly clients: CheTaskClient[]; | ||
constructor(id: number, | ||
taskManager: TaskManager, | ||
logger: ILogger, | ||
options: TaskOptions, | ||
clients: CheTaskClient[]) { | ||
super(taskManager, logger, options); | ||
this.clients = clients; | ||
this.taskId = id; | ||
} | ||
|
||
async getRuntimeInfo(): Promise<TaskInfo> { | ||
for (const client of this.clients) { | ||
const taskInfo = await client.getTaskInfo(this.taskId); | ||
if (taskInfo) { | ||
return { | ||
taskId: this.taskId, | ||
terminalId: taskInfo.terminalId, | ||
ctx: taskInfo.ctx, | ||
config: taskInfo.config | ||
}; | ||
} | ||
} | ||
throw new Error('Information not found'); | ||
} | ||
|
||
async kill(): Promise<void> { | ||
this.clients.forEach(client => client.killTask(this.taskId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.