From fde7af20fd18226a2d4d2a34f2121582268b3b08 Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Sun, 25 Aug 2019 13:52:47 +0000 Subject: [PATCH] fix #6036: prefer listed plugins to dependencies otherwise the wrong version gets installed from a marketplace instead of from local vsix file for example Signed-off-by: Anton Kosyakov --- .../plugin-ext/src/common/plugin-protocol.ts | 2 +- .../node/hosted-plugin-deployer-handler.ts | 10 +---- .../src/main/node/plugin-deployer-impl.ts | 44 ++++++++----------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/packages/plugin-ext/src/common/plugin-protocol.ts b/packages/plugin-ext/src/common/plugin-protocol.ts index bd515f9a112c3..1bb8e317c00cb 100644 --- a/packages/plugin-ext/src/common/plugin-protocol.ts +++ b/packages/plugin-ext/src/common/plugin-protocol.ts @@ -611,7 +611,7 @@ export interface PluginDeployerHandler { deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise; deployBackendPlugins(backendPlugins: PluginDeployerEntry[]): Promise; - getPluginDependencies(pluginToBeInstalled: PluginDeployerEntry): Promise + getPluginMetadata(pluginToBeInstalled: PluginDeployerEntry): Promise } export const HostedPluginServer = Symbol('HostedPluginServer'); diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugin-deployer-handler.ts b/packages/plugin-ext/src/hosted/node/hosted-plugin-deployer-handler.ts index 633e036e84f37..216443f25f3e9 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-plugin-deployer-handler.ts +++ b/packages/plugin-ext/src/hosted/node/hosted-plugin-deployer-handler.ts @@ -57,14 +57,8 @@ export class HostedPluginDeployerHandler implements PluginDeployerHandler { return this.currentBackendPluginsMetadata; } - async getPluginDependencies(plugin: PluginDeployerEntry): Promise { - const metadata = await this.reader.getPluginMetadata(plugin.path()); - if (metadata) { - if (metadata.model.extensionDependencies) { - return metadata.model.extensionDependencies; - } - } - return []; + getPluginMetadata(plugin: PluginDeployerEntry): Promise { + return this.reader.getPluginMetadata(plugin.path()); } async deployFrontendPlugins(frontendPlugins: PluginDeployerEntry[]): Promise { diff --git a/packages/plugin-ext/src/main/node/plugin-deployer-impl.ts b/packages/plugin-ext/src/main/node/plugin-deployer-impl.ts index 3c3d2a13e0f19..d572a05aa9e00 100644 --- a/packages/plugin-ext/src/main/node/plugin-deployer-impl.ts +++ b/packages/plugin-ext/src/main/node/plugin-deployer-impl.ts @@ -108,23 +108,20 @@ export class PluginDeployerImpl implements PluginDeployer { await this.deployMultipleEntries([pluginEntry]); } - protected async deployMultipleEntries(pluginEntries: string[]): Promise { - - const deployedPlugins = new Set(); - - /** - * Iterate over all the plugins, resolving them one at a time and adding - * in extension dependencies - */ - const futurePlugins = []; - while (pluginEntries.length !== 0) { - const currentPlugin = pluginEntries.pop() as string; - if (deployedPlugins.has(currentPlugin)) { + protected async deployMultipleEntries(pluginEntries: ReadonlyArray): Promise { + const visited = new Set(); + const pluginsToDeploy = new Map(); + + const queue = [...pluginEntries]; + while (queue.length) { + const current = queue.shift()!; + if (visited.has(current)) { continue; } + visited.add(current); // resolve plugins - const pluginDeployerEntries = await this.resolvePlugin(currentPlugin); + const pluginDeployerEntries = await this.resolvePlugin(current); // now that we have plugins check if we have File Handler for them await this.applyFileHandlers(pluginDeployerEntries); @@ -132,23 +129,18 @@ export class PluginDeployerImpl implements PluginDeployer { // ok now ask for directory handlers await this.applyDirectoryFileHandlers(pluginDeployerEntries); - // add current plugin deployer entries first because dependencies to be installed first - futurePlugins.unshift(...pluginDeployerEntries); - - deployedPlugins.add(currentPlugin); - - // gather all dependencies needed for current plugin for (const deployerEntry of pluginDeployerEntries) { - const deployDependencies = await this.pluginDeployerHandler.getPluginDependencies(deployerEntry); - pluginEntries.push(...deployDependencies); + const metadata = await this.pluginDeployerHandler.getPluginMetadata(deployerEntry); + if (metadata && !pluginsToDeploy.has(metadata.model.id)) { + pluginsToDeploy.set(metadata.model.id, deployerEntry); + if (metadata.model.extensionDependencies) { + queue.push(...metadata.model.extensionDependencies); + } + } } - } - await this.deployPlugins(futurePlugins); - - return Promise.resolve(); - + await this.deployPlugins([...pluginsToDeploy.values()]); } /**