This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
che-task-provider.ts
57 lines (51 loc) · 2.12 KB
/
che-task-provider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*********************************************************************
* 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 { injectable, inject } from 'inversify';
import { che } from '@eclipse-che/api';
import { TaskProvider } from '@theia/task/lib/browser';
import { TaskConfiguration } from '@theia/task/lib/common';
import { CheTaskConfiguration, CHE_TASK_TYPE } from '../common/task-protocol';
import { CheWorkspaceClientService } from '../common/che-workspace-client-service';
/** Reads the commands from the current Che workspace and provides it as Task Configurations. */
@injectable()
export class CheTaskProvider implements TaskProvider {
@inject(CheWorkspaceClientService)
protected readonly cheWsClient: CheWorkspaceClientService;
async provideTasks(): Promise<TaskConfiguration[]> {
const tasks: TaskConfiguration[] = [];
const commands = await this.cheWsClient.getCommands();
for (const command of commands) {
const providedTask: CheTaskConfiguration = {
type: CHE_TASK_TYPE,
label: `${command.name!}`,
command: command.commandLine!,
target: {
machineName: this.getCommandAttribute(command, 'machineName')
},
previewUrl: this.getCommandAttribute(command, 'previewUrl'),
_source: 'che',
_scope: undefined
};
tasks.push(providedTask);
}
return tasks;
}
protected getCommandAttribute(command: che.workspace.Command, attrName: string): string | undefined {
if (!command.attributes) {
return undefined;
}
for (const attr in command.attributes) {
if (attr === attrName) {
return command.attributes[attr];
}
}
return undefined;
}
}