Skip to content

Commit

Permalink
#2708 fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Sep 4, 2018
1 parent 1ca376e commit 7e48897
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@

import { PluginDeployerFileHandler, PluginDeployerEntry, PluginDeployerFileHandlerContext } from '@theia/plugin-ext';
import { injectable } from 'inversify';
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import { getTempDir } from '@theia/plugin-ext';

@injectable()
export class PluginVsCodeFileHandler implements PluginDeployerFileHandler {

private unpackedFolder: string;
constructor() {
this.unpackedFolder = path.resolve(os.tmpdir(), 'vscode-unpacked');
// for mac os 'os.tmpdir()' return symlink, but we need real path
if (process.platform === 'darwin') {
this.unpackedFolder = fs.realpathSync(this.unpackedFolder);
}

this.unpackedFolder = getTempDir('vscode-unpacked');
}

accept(resolvedPlugin: PluginDeployerEntry): boolean {
Expand Down
8 changes: 1 addition & 7 deletions packages/plugin-ext-vscode/src/node/plugin-vscode-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,5 @@ function overrideInternalLoad(): void {
}

function findPlugin(filePath: string): Plugin | undefined {
for (const plugin of plugins) {
if (filePath.startsWith(plugin.pluginFolder)) {
return plugin;
}
}

return undefined;
return plugins.find(plugin => filePath.startsWith(plugin.pluginFolder));
}
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from '../hosted/node/hosted-plugin-uri-postprocessor';
export * from '../common/plugin-protocol';
export * from '../plugin/plugin-context';
export * from '../api/plugin-api';
export * from '../main/node/temp-dir-util';
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,5 @@ function overrideInternalLoad(): void {
}

function findPlugin(filePath: string): Plugin | undefined {
for (const plugin of plugins) {
console.error(`findPlugin: ${filePath} : plugin path: ${plugin.pluginFolder}; Start with: ${filePath.startsWith(plugin.pluginFolder)}`);
if (filePath.startsWith(plugin.pluginFolder)) {
return plugin;
}
}

return undefined;
return plugins.find(plugin => filePath.startsWith(plugin.pluginFolder));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@

import { PluginDeployerFileHandler, PluginDeployerEntry, PluginDeployerFileHandlerContext } from '../../../common/plugin-protocol';
import { injectable } from 'inversify';
import * as os from 'os';
import { getTempDir } from '../temp-dir-util';
import * as path from 'path';
import * as fs from 'fs';

@injectable()
export class PluginTheiaFileHandler implements PluginDeployerFileHandler {

private unpackedFolder: string;
constructor() {
this.unpackedFolder = path.resolve(os.tmpdir(), 'theia-unpacked');
// for mac os 'os.tmpdir()' return symlink, but we need real path
if (process.platform === 'darwin') {
this.unpackedFolder = fs.realpathSync(this.unpackedFolder);
}
this.unpackedFolder = getTempDir('theia-unpacked');
}

accept(resolvedPlugin: PluginDeployerEntry): boolean {
Expand Down
28 changes: 28 additions & 0 deletions packages/plugin-ext/src/main/node/temp-dir-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************************************************
* 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 * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';

export function getTempDir(name: string): string {
let tempDir = path.resolve(os.tmpdir(), name);
// for mac os 'os.tmpdir()' return symlink, but we need real path
if (process.platform === 'darwin') {
tempDir = fs.realpathSync(tempDir);
}

return tempDir;
}

0 comments on commit 7e48897

Please sign in to comment.