Skip to content

Commit

Permalink
Add correct extension mode to plugin context
Browse files Browse the repository at this point in the history
The plugin context was hardcoded to have the production extensionMode.
Now a flag is passed to mark a plugin as under development when
deploying it. This flag is stored in the plugin metadata and later set in
the plugin. When creating the context this flag is then converted to the
correct extensionMode.

Fix eclipse-theia#10201

Contributed on behalf of STMicroelectronics
Signed-off-by: Eugen Neufeld <[email protected]>
  • Loading branch information
eneufeld committed Apr 1, 2022
1 parent 7b8d3b7 commit ad47fcf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-dev/src/node/hosted-plugin-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export class HostedPluginReader implements BackendApplicationContribution {
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]);
this.deployerHandler.deployBackendPlugins([hostedPlugin], true);
}

if (hostedMetadata!.model.entryPoint && hostedMetadata!.model.entryPoint.frontend) {
this.deployerHandler.deployFrontendPlugins([hostedPlugin]);
this.deployerHandler.deployFrontendPlugins([hostedPlugin], true);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface Plugin {
model: PluginModel;
rawModel: PluginPackage;
lifecycle: PluginLifecycle;
isUnderDevelopment: boolean;
}

export interface ConfigStorage {
Expand Down Expand Up @@ -193,7 +194,8 @@ export const emptyPlugin: Plugin = {
version: 'empty'
},
packagePath: 'empty'
}
},
isUnderDevelopment: false
};

export interface PluginManagerInitializeParams {
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-ext/src/common/plugin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ export interface PluginMetadata {
host: string;
model: PluginModel;
lifecycle: PluginLifecycle;
isUnderDevelopment?: boolean;
}

export const MetadataProcessor = Symbol('MetadataProcessor');
Expand Down Expand Up @@ -826,8 +827,8 @@ export interface PluginDependencies {

export const PluginDeployerHandler = Symbol('PluginDeployerHandler');
export interface PluginDeployerHandler {
deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise<void>;
deployBackendPlugins(backendPlugins: PluginDeployerEntry[]): Promise<void>;
deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[], isUnderDevelopment?: boolean): Promise<void>;
deployBackendPlugins(backendPlugins: PluginDeployerEntry[], isUnderDevelopment?: boolean): Promise<void>;

getDeployedPlugin(pluginId: string): DeployedPlugin | undefined;
undeployPlugin(pluginId: string): Promise<boolean>;
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-ext/src/hosted/browser/worker/worker-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ const pluginManager = new PluginManagerExtImpl({
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
};
const apiImpl = apiFactory(plugin);
pluginsApiImpl.set(plugin.model.id, apiImpl);
Expand All @@ -146,7 +147,8 @@ const pluginManager = new PluginManagerExtImpl({
lifecycle: pluginLifecycle,
get rawModel(): never {
throw new Error('not supported');
}
},
isUnderDevelopment: !!plg.isUnderDevelopment
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
}
}

async deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise<void> {
async deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[], isUnderDevelopment?: boolean): Promise<void> {
for (const plugin of frontendPlugins) {
await this.deployPlugin(plugin, 'frontend');
await this.deployPlugin(plugin, 'frontend', isUnderDevelopment);
}
// resolve on first deploy
this.frontendPluginsMetadataDeferred.resolve(undefined);
}

async deployBackendPlugins(backendPlugins: PluginDeployerEntry[]): Promise<void> {
async deployBackendPlugins(backendPlugins: PluginDeployerEntry[], isUnderDevelopment?: boolean): Promise<void> {
for (const plugin of backendPlugins) {
await this.deployPlugin(plugin, 'backend');
await this.deployPlugin(plugin, 'backend', isUnderDevelopment);
}
// rebuild translation config after deployment
this.localizationService.buildTranslationConfig([...this.deployedBackendPlugins.values()]);
Expand All @@ -120,7 +120,7 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
/**
* @throws never! in order to isolate plugin deployment
*/
protected async deployPlugin(entry: PluginDeployerEntry, entryPoint: keyof PluginEntryPoint): Promise<void> {
protected async deployPlugin(entry: PluginDeployerEntry, entryPoint: keyof PluginEntryPoint, isUnderDevelopment: boolean = false): Promise<void> {
const pluginPath = entry.path();
const deployPlugin = this.stopwatch.start('deployPlugin');
try {
Expand All @@ -131,6 +131,7 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler {
}

const metadata = this.reader.readMetadata(manifest);
metadata.isUnderDevelopment = isUnderDevelopment;

const deployedLocations = this.deployedLocations.get(metadata.model.id) || new Set<string>();
deployedLocations.add(entry.rootPath);
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export class PluginHostRPC {
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
});
} else {
let backendInitPath = pluginLifecycle.backendInitPath;
Expand All @@ -182,7 +183,8 @@ export class PluginHostRPC {
pluginUri: pluginModel.packageUri,
model: pluginModel,
lifecycle: pluginLifecycle,
rawModel
rawModel,
isUnderDevelopment: !!plg.isUnderDevelopment
};

self.initContext(backendInitPath, plugin);
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-ext/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../common/plugin-api-rpc';
import { PluginMetadata, PluginJsonValidationContribution } from '../common/plugin-protocol';
import * as theia from '@theia/plugin';
import * as types from './types-impl';
import { join } from './path';
import { EnvExtImpl } from './env';
import { PreferenceRegistryExtImpl } from './preference-registry';
Expand Down Expand Up @@ -372,6 +373,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
const secrets = new SecretStorageExt(plugin, this.secrets);
const globalStoragePath = join(configStorage.hostGlobalStoragePath, plugin.model.id);
const extension = new PluginExt(this, plugin);
const extensionModeValue = plugin.isUnderDevelopment ? types.ExtensionMode.Development : types.ExtensionMode.Production;
const pluginContext: theia.PluginContext = {
extensionPath: extension.extensionPath,
extensionUri: extension.extensionUri,
Expand All @@ -386,7 +388,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager {
globalStoragePath: globalStoragePath,
globalStorageUri: Uri.file(globalStoragePath),
environmentVariableCollection: this.terminalService.getEnvironmentVariableCollection(plugin.model.id),
extensionMode: 1, // @todo: implement proper `extensionMode`.
extensionMode: extensionModeValue,
extension,
logUri: Uri.file(logPath)
};
Expand Down

0 comments on commit ad47fcf

Please sign in to comment.