-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathhosted-plugin-reader.ts
57 lines (48 loc) · 2.67 KB
/
hosted-plugin-reader.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. 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 { inject, injectable } from 'inversify';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
import { HostedPluginReader as PluginReaderHosted } from '@theia/plugin-ext/lib/hosted/node/plugin-reader';
import { Deferred } from '@theia/core/lib/common/promise-util';
import { PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol';
import { PluginDeployerEntryImpl } from '@theia/plugin-ext/lib/main/node/plugin-deployer-entry-impl';
import { HostedPluginDeployerHandler } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin-deployer-handler';
@injectable()
export class HostedPluginReader implements BackendApplicationContribution {
@inject(PluginReaderHosted)
protected pluginReader: PluginReaderHosted;
private readonly hostedPlugin = new Deferred<PluginMetadata | undefined>();
@inject(HostedPluginDeployerHandler)
protected deployerHandler: HostedPluginDeployerHandler;
async initialize(): Promise<void> {
this.pluginReader.doGetPluginMetadata(process.env.HOSTED_PLUGIN, {})
.then(this.hostedPlugin.resolve.bind(this.hostedPlugin));
const pluginPath = process.env.HOSTED_PLUGIN;
if (pluginPath) {
const hostedPlugin = new PluginDeployerEntryImpl('Hosted Plugin', pluginPath!, pluginPath);
const hostedMetadata = await this.hostedPlugin.promise;
if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.backend) {
this.deployerHandler.deployBackendPlugins([hostedPlugin]);
}
if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.frontend) {
this.deployerHandler.deployFrontendPlugins([hostedPlugin]);
}
}
}
async getPlugin(): Promise<PluginMetadata | undefined> {
return this.hostedPlugin.promise;
}
}