Skip to content

Commit

Permalink
Support plugin copying for remote feature
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Feb 8, 2024
1 parent b7ed5e9 commit 4cc05c3
Show file tree
Hide file tree
Showing 28 changed files with 313 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as http from 'http';
import { inject, injectable } from 'inversify';
import { BackendRemoteService } from '../../node/backend-remote-service';
import { BackendRemoteService } from '../../node/remote/backend-remote-service';
import { WsRequestValidatorContribution } from '../../node/ws-request-validators';

@injectable()
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/node/backend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import { bindNodeStopwatch, bindBackendStopwatchServer } from './performance';
import { OSBackendProviderImpl } from './os-backend-provider';
import { BackendRequestFacade } from './request/backend-request-facade';
import { FileSystemLocking, FileSystemLockingImpl } from './filesystem-locking';
import { BackendRemoteService } from './backend-remote-service';
import { BackendRemoteService } from './remote/backend-remote-service';
import { RemoteCliContribution } from './remote/remote-cli-contribution';

decorate(injectable(), ApplicationPackage);

Expand Down Expand Up @@ -127,6 +128,7 @@ export const backendApplicationModule = new ContainerModule(bind => {
bind(ProxyCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(ProxyCliContribution);

bindContributionProvider(bind, RemoteCliContribution);
bind(BackendRemoteService).toSelf().inSingletonScope();
bind(BackendRequestFacade).toSelf().inSingletonScope();
bind(ConnectionHandler).toDynamicValue(
Expand Down
34 changes: 34 additions & 0 deletions packages/core/src/node/remote/remote-cli-contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// *****************************************************************************
// Copyright (C) 2024 TypeFox 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import type { OS } from '../../common/os';
import type { MaybePromise } from '../../common/types';

export interface RemotePlatform {
os: OS.Type
arch: string
}

export interface RemoteCliContext {
platform: RemotePlatform;
directory: string;
}

export const RemoteCliContribution = Symbol('RemoteCliContribution');

export interface RemoteCliContribution {
enhanceArgs(context: RemoteCliContext): MaybePromise<string[]>;
}
45 changes: 45 additions & 0 deletions packages/core/src/node/remote/remote-copy-contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// *****************************************************************************
// Copyright (C) 2024 TypeFox 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { MaybePromise } from '../../common/types';

export const RemoteCopyContribution = Symbol('RemoteCopyContribution');

export interface RemoteCopyContribution {
copy(registry: RemoteCopyRegistry): MaybePromise<void>
}

export interface RemoteCopyOptions {
/**
* The mode that the file should be set to once copied to the remote.
*
* Only relevant for POSIX-like systems
*/
mode?: number;
}

export interface RemoteFile {
path: string
target: string
options?: RemoteCopyOptions;
}

export interface RemoteCopyRegistry {
getFiles(): RemoteFile[];
glob(pattern: string, target?: string): Promise<void>;
file(file: string, target?: string, options?: RemoteCopyOptions): void;
directory(dir: string, target?: string): Promise<void>;
}
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ export interface PluginDeployerHandler {
deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise<number | undefined>;
deployBackendPlugins(backendPlugins: PluginDeployerEntry[]): Promise<number | undefined>;

getDeployedPlugins(): Promise<DeployedPlugin[]>;
getDeployedPluginsById(pluginId: string): DeployedPlugin[];

getDeployedPlugin(pluginId: PluginIdentifiers.VersionedId): DeployedPlugin | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
return Array.from(this.deployedBackendPlugins.values());
}

async getDeployedPlugins(): Promise<DeployedPlugin[]> {
await this.frontendPluginsMetadataDeferred.promise;
await this.backendPluginsMetadataDeferred.promise;
return [...this.deployedFrontendPlugins.values(), ...this.deployedBackendPlugins.values()];
}

getDeployedPluginsById(pluginId: string): DeployedPlugin[] {
const matches: DeployedPlugin[] = [];
const handle = (plugins: Iterable<DeployedPlugin>): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import { PluginUninstallationManager } from './plugin-uninstallation-manager';
import { LocalizationServerImpl } from '@theia/core/lib/node/i18n/localization-server';
import { PluginLocalizationServer } from './plugin-localization-server';
import { PluginMgmtCliContribution } from './plugin-mgmt-cli-contribution';
import { PluginRemoteCliContribution } from './plugin-remote-cli-contribution';
import { RemoteCliContribution } from '@theia/core/lib/node/remote/remote-cli-contribution';
import { PluginRemoteCopyContribution } from './plugin-remote-copy-contribution';
import { RemoteCopyContribution } from '@theia/core/lib/node/remote/remote-copy-contribution';

export function bindMainBackend(bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind): void {
bind(PluginApiContribution).toSelf().inSingletonScope();
Expand Down Expand Up @@ -89,6 +93,11 @@ export function bindMainBackend(bind: interfaces.Bind, unbind: interfaces.Unbind
bind(PluginMgmtCliContribution).toSelf().inSingletonScope();
bind(CliContribution).toService(PluginMgmtCliContribution);

bind(PluginRemoteCliContribution).toSelf().inSingletonScope();
bind(RemoteCliContribution).toService(PluginRemoteCliContribution);
bind(PluginRemoteCopyContribution).toSelf().inSingletonScope();
bind(RemoteCopyContribution).toService(PluginRemoteCopyContribution);

bind(WebviewBackendSecurityWarnings).toSelf().inSingletonScope();
bind(BackendApplicationContribution).toService(WebviewBackendSecurityWarnings);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// *****************************************************************************
// Copyright (C) 2024 TypeFox 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { MaybePromise } from '@theia/core';
import { RemoteCliContext, RemoteCliContribution } from '@theia/core/lib/node/remote/remote-cli-contribution';
import { inject, injectable } from '@theia/core/shared/inversify';
import { PluginCliContribution } from './plugin-cli-contribution';

@injectable()
export class PluginRemoteCliContribution implements RemoteCliContribution {

@inject(PluginCliContribution)
protected readonly pluginCliContribution: PluginCliContribution;

enhanceArgs(context: RemoteCliContext): MaybePromise<string[]> {
const pluginsFolder = this.pluginCliContribution.localDir();
if (!pluginsFolder) {
return [];
} else {
return ['--plugins=local-dir:./plugins'];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// *****************************************************************************
// Copyright (C) 2024 TypeFox 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-only WITH Classpath-exception-2.0
// *****************************************************************************

import { RemoteCopyContribution, RemoteCopyRegistry } from '@theia/core/lib/node/remote/remote-copy-contribution';
import { inject, injectable } from '@theia/core/shared/inversify';
import { PluginCliContribution } from './plugin-cli-contribution';
import { FileUri } from '@theia/core/lib/common/file-uri';

@injectable()
export class PluginRemoteCopyContribution implements RemoteCopyContribution {

@inject(PluginCliContribution)
protected readonly pluginCliContribution: PluginCliContribution;

async copy(registry: RemoteCopyRegistry): Promise<void> {
const localDir = this.pluginCliContribution.localDir();
if (localDir) {
const fsPath = FileUri.fsPath(localDir);
await registry.directory(fsPath, 'plugins');
}

}
}
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/node/plugin-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { environment } from '@theia/core/shared/@theia/application-package/lib/e
import { WsRequestValidatorContribution } from '@theia/core/lib/node/ws-request-validators';
import { MaybePromise } from '@theia/core/lib/common';
import { ApplicationPackage } from '@theia/core/shared/@theia/application-package';
import { BackendRemoteService } from '@theia/core/lib/node/backend-remote-service';
import { BackendRemoteService } from '@theia/core/lib/node/remote/backend-remote-service';

@injectable()
export class PluginApiContribution implements BackendApplicationContribution, WsRequestValidatorContribution {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { CliContribution } from '@theia/core/lib/node';
import { injectable } from '@theia/core/shared/inversify';
import { Arguments, Argv } from '@theia/core/shared/yargs';
import { BackendRemoteService } from '@theia/core/lib/node/backend-remote-service';
import { BackendRemoteService } from '@theia/core/lib/node/remote/backend-remote-service';

export const REMOTE_START = 'remote';

Expand Down
7 changes: 4 additions & 3 deletions packages/remote/src/electron-node/remote-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import { RemoteCopyService } from './setup/remote-copy-service';
import { RemoteSetupService } from './setup/remote-setup-service';
import { RemoteNativeDependencyService } from './setup/remote-native-dependency-service';
import { BackendRemoteServiceImpl } from './backend-remote-service-impl';
import { BackendRemoteService } from '@theia/core/lib/node/backend-remote-service';
import { BackendRemoteService } from '@theia/core/lib/node/remote/backend-remote-service';
import { RemoteNodeSetupService } from './setup/remote-node-setup-service';
import { RemotePosixScriptStrategy, RemoteSetupScriptService, RemoteWindowsScriptStrategy } from './setup/remote-setup-script-service';
import { RemoteStatusService, RemoteStatusServicePath } from '../electron-common/remote-status-service';
import { RemoteStatusServiceImpl } from './remote-status-service';
import { ConnectionHandler, RpcConnectionHandler, bindContributionProvider } from '@theia/core';
import { RemoteCopyContribution, RemoteCopyRegistry } from './setup/remote-copy-contribution';
import { RemoteCopyRegistryImpl } from './setup/remote-copy-contribution';
import { RemoteCopyContribution } from '@theia/core/lib/node/remote/remote-copy-contribution';
import { MainCopyContribution } from './setup/main-copy-contribution';
import { RemoteNativeDependencyContribution } from './setup/remote-native-dependency-contribution';
import { AppNativeDependencyContribution } from './setup/app-native-dependency-contribution';
Expand Down Expand Up @@ -62,7 +63,7 @@ export default new ContainerModule((bind, _unbind, _isBound, rebind) => {
bind(RemotePosixScriptStrategy).toSelf().inSingletonScope();
bind(RemoteSetupScriptService).toSelf().inSingletonScope();
bind(RemoteNativeDependencyService).toSelf().inSingletonScope();
bind(RemoteCopyRegistry).toSelf().inSingletonScope();
bind(RemoteCopyRegistryImpl).toSelf().inSingletonScope();
bindContributionProvider(bind, RemoteCopyContribution);
bindContributionProvider(bind, RemoteNativeDependencyContribution);
bind(MainCopyContribution).toSelf().inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import { inject, injectable } from '@theia/core/shared/inversify';
import { RemoteConnection } from './remote-types';
import { Disposable } from '@theia/core';
import { RemoteCopyService } from './setup/remote-copy-service';
import { RemoteNativeDependencyService } from './setup/remote-native-dependency-service';
import { BackendApplicationContribution } from '@theia/core/lib/node';
import { RemoteSetupService } from './setup/remote-setup-service';

@injectable()
export class RemoteConnectionService implements BackendApplicationContribution {

@inject(RemoteCopyService)
protected readonly copyService: RemoteCopyService;

@inject(RemoteNativeDependencyService)
protected readonly nativeDependencyService: RemoteNativeDependencyService;
// Workaround for the fact that connection scoped services cannot directly inject these services.
@inject(RemoteSetupService)
protected readonly remoteSetupService: RemoteSetupService;

protected readonly connections = new Map<string, RemoteConnection>();

Expand Down
7 changes: 1 addition & 6 deletions packages/remote/src/electron-node/remote-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { Disposable, Event, OS } from '@theia/core';
import { Disposable, Event } from '@theia/core';
import * as net from 'net';

export interface RemotePlatform {
os: OS.Type
arch: string
}

export type RemoteStatusReport = (message: string) => void;

export interface ExpressLayer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable } from '@theia/core/shared/inversify';
import { RemoteNativeDependencyContribution, DownloadOptions, DependencyDownload } from './remote-native-dependency-contribution';
import { RemotePlatform } from '../remote-types';
import { RemotePlatform } from '@theia/core/lib/node/remote/remote-cli-contribution';
import { OS } from '@theia/core';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import { RemoteCopyContribution, RemoteCopyRegistry } from './remote-copy-contribution';
import { RemoteCopyContribution, RemoteCopyRegistry } from '@theia/core/lib/node/remote/remote-copy-contribution';

@injectable()
export class MainCopyContribution implements RemoteCopyContribution {
Expand Down
Loading

0 comments on commit 4cc05c3

Please sign in to comment.