/********************************************************************************
 * 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 { PluginDevServer , PluginDevClient } from '../common/plugin-dev-protocol' ; import { injectable , inject } from '@theia/core/shared/inversify' ; import { HostedInstanceManager } from './hosted-instance-manager' ; import { PluginMetadata } from '@theia/plugin-ext/lib/common/plugin-protocol' ; import URI from '@theia/core/lib/common/uri' ; import { HostedPluginReader } from './hosted-plugin-reader' ; import { HostedPluginsManager } from './hosted-plugins-manager' ; import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin' ; import { DebugPluginConfiguration } from '@theia/debug/lib/browser/debug-contribution' ; @ injectable ( ) export class PluginDevServerImpl implements PluginDevServer { @ inject ( HostedPluginsManager ) protected readonly hostedPluginsManager : HostedPluginsManager ; @ inject ( HostedInstanceManager ) protected readonly hostedInstanceManager : HostedInstanceManager ; @ inject ( HostedPluginReader ) private readonly reader : HostedPluginReader ; @ inject ( HostedPluginSupport ) private readonly hostedPlugin : HostedPluginSupport ; dispose ( ) { if ( this . hostedInstanceManager . isRunning ( ) ) { this . hostedInstanceManager . terminate ( ) ; } } setClient ( client ) { } async getHostedPlugin ( ) { const pluginMetadata = await this . reader . getPlugin ( ) ; if ( pluginMetadata ) { this . hostedPlugin . runPlugin ( pluginMetadata . model ) ; } return Promise . resolve ( this . reader . getPlugin ( ) ) ; } isPluginValid ( uri ) { return Promise . resolve ( this . hostedInstanceManager . isPluginValid ( new URI ( uri ) ) ) ; } runHostedPluginInstance ( uri ) { return this . uriToStrPromise ( this . hostedInstanceManager . run ( new URI ( uri ) ) ) ; } runDebugHostedPluginInstance ( uri , debugConfig ) { return this . uriToStrPromise ( this . hostedInstanceManager . debug ( new URI ( uri ) , debugConfig ) ) ; } terminateHostedPluginInstance ( ) { this . hostedInstanceManager . terminate ( ) ; return Promise . resolve ( ) ; } isHostedPluginInstanceRunning ( ) { return Promise . resolve ( this . hostedInstanceManager . isRunning ( ) ) ; } getHostedPluginInstanceURI ( ) { return Promise . resolve ( this . hostedInstanceManager . getInstanceURI ( ) . toString ( ) ) ; } getHostedPluginURI ( ) { return Promise . resolve ( this . hostedInstanceManager . getPluginURI ( ) . toString ( ) ) ; } protected uriToStrPromise ( promise ) { return new Promise ( ( resolve , reject ) => { promise . then ( ( uri ) => { resolve ( uri . toString ( ) ) ; } ) . catch ( error => reject ( error ) ) ; } ) ; } runWatchCompilation ( path ) { return this . hostedPluginsManager . runWatchCompilation ( path ) ; } stopWatchCompilation ( path ) { return this . hostedPluginsManager . stopWatchCompilation ( path ) ; } isWatchCompilationRunning ( path ) { return this . hostedPluginsManager . isWatchCompilationRunning ( path ) ; } }