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
/
che-plugin-frontend-service.ts
93 lines (78 loc) · 3.44 KB
/
che-plugin-frontend-service.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/********************************************************************************
* Copyright (C) 2019 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { injectable, inject } from 'inversify';
import { HostedPluginServer, PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol';
import { ChePluginMetadata } from '../../common/che-protocol';
import { PluginFilter } from '../../common/plugin/plugin-filter';
@injectable()
export class ChePluginFrontentService {
@inject(HostedPluginServer)
protected readonly hostedPluginServer: HostedPluginServer;
// returns a list of built-in plugins when filter contains '@builtin'
async getBuiltInPlugins(filter: string): Promise<ChePluginMetadata[]> {
let pluginList = await this.getAllDeployedPlugins();
pluginList = PluginFilter.filterPlugins(pluginList, filter);
return pluginList;
}
/**
* Returns non-filtered list of the deployed plugins.
*/
private async getAllDeployedPlugins(): Promise<ChePluginMetadata[]> {
const metadata = await this.hostedPluginServer.getDeployedMetadata();
const plugins: ChePluginMetadata[] = metadata.map((meta: PluginMetadata) => {
const publisher = meta.source.publisher;
const name = meta.source.name;
const version = meta.source.version;
const type = this.determinePluginType(meta);
const displayName = meta.source.displayName ? meta.source.displayName : meta.source.name;
const title = name;
const description = meta.source.description;
// Temporary disabled.
// We don't have an ability for now to display icons from the file system.
// tslint:disable-next-line:no-any
// const icon = (meta.source as any).icon;
return {
publisher,
name,
version,
type,
displayName,
title,
description,
icon: '',
url: '',
repository: '',
firstPublicationDate: '',
category: '',
latestUpdateDate: '',
// Plugin KEY. Used to set in workspace configuration
key: `${publisher}/${name}/${version}`,
builtIn: true
};
});
return plugins;
}
private determinePluginType(meta: PluginMetadata): string {
if (meta && meta.model && meta.model.engine && meta.model.engine.type) {
if ('vscode' === meta.model.engine.type) {
return 'VS Code extension';
} else if ('theiaPlugin' === meta.model.engine.type) {
return 'Theia plugin';
}
}
return '';
}
}