提交 32d834b0 编写于 作者: S Sandeep Somavarapu

Store metadata for Local extensions

- While installing from zip
- While syncing with gallery
上级 77ba628a
...@@ -257,6 +257,8 @@ export interface IExtensionManagementService { ...@@ -257,6 +257,8 @@ export interface IExtensionManagementService {
installFromGallery(extension: IGalleryExtension): TPromise<void>; installFromGallery(extension: IGalleryExtension): TPromise<void>;
uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>; uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>;
getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>; getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension>;
} }
export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService'); export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService');
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc'; import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier } from './extensionManagement'; import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata } from './extensionManagement';
import Event, { buffer } from 'vs/base/common/event'; import Event, { buffer } from 'vs/base/common/event';
export interface IExtensionManagementChannel extends IChannel { export interface IExtensionManagementChannel extends IChannel {
...@@ -46,6 +46,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel { ...@@ -46,6 +46,7 @@ export class ExtensionManagementChannel implements IExtensionManagementChannel {
case 'installFromGallery': return this.service.installFromGallery(arg[0]); case 'installFromGallery': return this.service.installFromGallery(arg[0]);
case 'uninstall': return this.service.uninstall(arg[0], arg[1]); case 'uninstall': return this.service.uninstall(arg[0], arg[1]);
case 'getInstalled': return this.service.getInstalled(arg); case 'getInstalled': return this.service.getInstalled(arg);
case 'updateMetadata': return this.service.updateMetadata(arg[0], arg[1]);
} }
return undefined; return undefined;
} }
...@@ -84,4 +85,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer ...@@ -84,4 +85,8 @@ export class ExtensionManagementChannelClient implements IExtensionManagementSer
getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> { getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> {
return this.channel.call('getInstalled', type); return this.channel.call('getInstalled', type);
} }
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
return this.channel.call('updateMetadata', [local, metadata]);
}
} }
\ No newline at end of file
...@@ -123,11 +123,17 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -123,11 +123,17 @@ export class ExtensionManagementService implements IExtensionManagementService {
this._onInstallExtension.fire({ identifier, zipPath }); this._onInstallExtension.fire({ identifier, zipPath });
return this.installExtension({ zipPath, id: identifier.id, metadata: null }) return this.galleryService.query({ names: [getGalleryExtensionId(manifest.publisher, manifest.name)], pageSize: 1 })
.then( .then(galleryResult => {
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }), const galleryExtension = galleryResult.firstPage[0];
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); } const metadata = galleryExtension ? <IGalleryMetadata>{ id: galleryExtension.identifier.uuid, publisherDisplayName: galleryExtension.publisherDisplayName, publisherId: galleryExtension.publisherId } : null;
); return this.installExtension({ zipPath, id: identifier.id, metadata })
.then(
local => this._onDidInstallExtension.fire({ identifier, zipPath, local }),
error => { this._onDidInstallExtension.fire({ identifier, zipPath, error }); return TPromise.wrapError(error); }
);
});
}); });
}); });
} }
...@@ -253,12 +259,8 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -253,12 +259,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
const identifier = { id, uuid: metadata ? metadata.id : null }; const identifier = { id, uuid: metadata ? metadata.id : null };
const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl }; const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
const manifestPath = path.join(extensionPath, 'package.json');
return pfs.readFile(manifestPath, 'utf8') return this.saveMetadataForLocalExtension(local)
.then(raw => parseManifest(raw))
.then(({ manifest }) => assign(manifest, { __metadata: metadata }))
.then(manifest => pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t')))
.then(() => this.checkForRename(current, local)) .then(() => this.checkForRename(current, local))
.then(() => local); .then(() => local);
}); });
...@@ -279,6 +281,23 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -279,6 +281,23 @@ export class ExtensionManagementService implements IExtensionManagementService {
.then(() => { /* drop resolved value */ }); .then(() => { /* drop resolved value */ });
} }
updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
local.metadata = metadata;
return this.saveMetadataForLocalExtension(local);
}
private saveMetadataForLocalExtension(local: ILocalExtension): TPromise<ILocalExtension> {
if (!local.metadata) {
return TPromise.as(local);
}
const manifestPath = path.join(this.extensionsPath, local.identifier.id, 'package.json');
return pfs.readFile(manifestPath, 'utf8')
.then(raw => parseManifest(raw))
.then(({ manifest }) => assign(manifest, { __metadata: local.metadata }))
.then(manifest => pfs.writeFile(manifestPath, JSON.stringify(manifest, null, '\t')))
.then(() => local);
}
private checkForRename(currentExtension: ILocalExtension, newExtension: ILocalExtension): TPromise<void> { private checkForRename(currentExtension: ILocalExtension, newExtension: ILocalExtension): TPromise<void> {
// Check if the gallery id for current and new exensions are same, if not, remove the current one. // Check if the gallery id for current and new exensions are same, if not, remove the current one.
if (currentExtension && getGalleryExtensionIdFromLocal(currentExtension) !== getGalleryExtensionIdFromLocal(newExtension)) { if (currentExtension && getGalleryExtensionIdFromLocal(currentExtension) !== getGalleryExtensionIdFromLocal(newExtension)) {
......
...@@ -459,9 +459,14 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService { ...@@ -459,9 +459,14 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
} }
private syncLocalWithGalleryExtension(local: Extension, gallery: IGalleryExtension) { private syncLocalWithGalleryExtension(local: Extension, gallery: IGalleryExtension) {
local.gallery = gallery; // Sync the local extension with gallery extension if local extension doesnot has metadata
this._onChange.fire(); (local.local.metadata ? TPromise.as(local.local) : this.extensionService.updateMetadata(local.local, { id: gallery.identifier.uuid, publisherDisplayName: gallery.publisherDisplayName, publisherId: gallery.publisherId }))
this.eventuallyAutoUpdateExtensions(); .then(localExtension => {
local.local = localExtension;
local.gallery = gallery;
this._onChange.fire();
this.eventuallyAutoUpdateExtensions();
});
} }
checkForUpdates(): TPromise<void> { checkForUpdates(): TPromise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册