提交 b82b1cd1 编写于 作者: S Sandeep Somavarapu

Add logs to extension management service

上级 d09e6ef3
...@@ -32,6 +32,7 @@ import { IChoiceService, Severity } from 'vs/platform/message/common/message'; ...@@ -32,6 +32,7 @@ import { IChoiceService, Severity } from 'vs/platform/message/common/message';
import pkg from 'vs/platform/node/package'; import pkg from 'vs/platform/node/package';
import { isMacintosh } from 'vs/base/common/platform'; import { isMacintosh } from 'vs/base/common/platform';
import { MANIFEST_CACHE_FOLDER, USER_MANIFEST_CACHE_FILE } from 'vs/platform/extensions/common/extensions'; import { MANIFEST_CACHE_FOLDER, USER_MANIFEST_CACHE_FILE } from 'vs/platform/extensions/common/extensions';
import { ILogService } from 'vs/platform/log/common/log';
const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions')); const SystemExtensionsRoot = path.normalize(path.join(URI.parse(require.toUrl('')).fsPath, '..', 'extensions'));
const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem'; const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
...@@ -119,7 +120,8 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -119,7 +120,8 @@ export class ExtensionManagementService implements IExtensionManagementService {
constructor( constructor(
@IEnvironmentService environmentService: IEnvironmentService, @IEnvironmentService environmentService: IEnvironmentService,
@IChoiceService private choiceService: IChoiceService, @IChoiceService private choiceService: IChoiceService,
@IExtensionGalleryService private galleryService: IExtensionGalleryService @IExtensionGalleryService private galleryService: IExtensionGalleryService,
@ILogService private logService: ILogService,
) { ) {
this.extensionsPath = environmentService.extensionsPath; this.extensionsPath = environmentService.extensionsPath;
this.uninstalledPath = path.join(this.extensionsPath, '.obsolete'); this.uninstalledPath = path.join(this.extensionsPath, '.obsolete');
...@@ -147,11 +149,13 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -147,11 +149,13 @@ export class ExtensionManagementService implements IExtensionManagementService {
() => this.checkOutdated(manifest) () => this.checkOutdated(manifest)
.then(validated => { .then(validated => {
if (validated) { if (validated) {
this.logService.info('Installing the extension', identifier.id);
this._onInstallExtension.fire({ identifier, zipPath }); this._onInstallExtension.fire({ identifier, zipPath });
return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name)) return this.getMetadata(getGalleryExtensionId(manifest.publisher, manifest.name))
.then( .then(
metadata => this.installFromZipPath(identifier, zipPath, metadata, manifest), metadata => this.installFromZipPath(identifier, zipPath, metadata, manifest),
error => this.installFromZipPath(identifier, zipPath, null, manifest)); error => this.installFromZipPath(identifier, zipPath, null, manifest))
.then(() => this.logService.info('Successfully installed the extension', identifier.id), e => this.logService.error('Failed to install the extension', identifier.id, e.message));
} }
return null; return null;
}), }),
...@@ -163,9 +167,11 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -163,9 +167,11 @@ export class ExtensionManagementService implements IExtensionManagementService {
return this.isUninstalled(id) return this.isUninstalled(id)
.then(isUninstalled => { .then(isUninstalled => {
if (isUninstalled) { if (isUninstalled) {
this.logService.trace('Removing the extension', id);
const extensionPath = path.join(this.extensionsPath, id); const extensionPath = path.join(this.extensionsPath, id);
return pfs.rimraf(extensionPath) return pfs.rimraf(extensionPath)
.then(() => this.unsetUninstalled(id)); .then(() => this.unsetUninstalled(id))
.then(() => this.logService.info('Reomved the extension', id));
} }
return null; return null;
}); });
...@@ -263,13 +269,17 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -263,13 +269,17 @@ export class ExtensionManagementService implements IExtensionManagementService {
.then( .then(
compatible => { compatible => {
if (compatible) { if (compatible) {
this.logService.trace('Downloading extension', extension.name);
return this.galleryService.download(extension) return this.galleryService.download(extension)
.then( .then(
zipPath => validateLocalExtension(zipPath) zipPath => {
.then( this.logService.info('Downloaded extension', extension.name);
() => (<InstallableExtension>{ zipPath, id, metadata }), return validateLocalExtension(zipPath)
error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING)) .then(
), () => (<InstallableExtension>{ zipPath, id, metadata }),
error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_VALIDATING))
);
},
error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING))); error => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(error).message, INSTALL_ERROR_DOWNLOADING)));
} else { } else {
return TPromise.wrapError<InstallableExtension>(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the depending extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE)); return TPromise.wrapError<InstallableExtension>(new ExtensionManagementError(nls.localize('notFoundCompatibleDependency', "Unable to install because, the depending extension '{0}' compatible with current version '{1}' of VS Code is not found.", extension.identifier.id, pkg.version), INSTALL_ERROR_INCOMPATIBLE));
...@@ -286,6 +296,7 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -286,6 +296,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
private onInstallExtensions(extensions: IGalleryExtension[]): void { private onInstallExtensions(extensions: IGalleryExtension[]): void {
for (const extension of extensions) { for (const extension of extensions) {
this.logService.info('Installing extension', extension.name);
const id = getLocalExtensionIdFromGallery(extension, extension.version); const id = getLocalExtensionIdFromGallery(extension, extension.version);
this._onInstallExtension.fire({ identifier: { id, uuid: extension.identifier.uuid }, gallery: extension }); this._onInstallExtension.fire({ identifier: { id, uuid: extension.identifier.uuid }, gallery: extension });
} }
...@@ -297,9 +308,11 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -297,9 +308,11 @@ export class ExtensionManagementService implements IExtensionManagementService {
const local = locals[index]; const local = locals[index];
const error = errors[index]; const error = errors[index];
if (local) { if (local) {
this.logService.info(`Extensions installed successfully`, gallery.identifier.id);
this._onDidInstallExtension.fire({ identifier, gallery, local }); this._onDidInstallExtension.fire({ identifier, gallery, local });
} else { } else {
const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : INSTALL_ERROR_UNKNOWN; const errorCode = error && (<ExtensionManagementError>error).code ? (<ExtensionManagementError>error).code : INSTALL_ERROR_UNKNOWN;
this.logService.error(`Failed to install extension`, gallery.identifier.id, error ? error.message : errorCode);
this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode }); this._onDidInstallExtension.fire({ identifier, gallery, error: errorCode });
} }
}); });
...@@ -351,9 +364,13 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -351,9 +364,13 @@ export class ExtensionManagementService implements IExtensionManagementService {
return this.isUninstalled(id) return this.isUninstalled(id)
.then(isUninstalled => { .then(isUninstalled => {
if (isUninstalled) { if (isUninstalled) {
this.logService.trace('Removing the extension from uninstalled list', id);
// If the same version of extension is marked as uninstalled, remove it from there and return the local. // If the same version of extension is marked as uninstalled, remove it from there and return the local.
return this.unsetUninstalled(id) return this.unsetUninstalled(id)
.then(() => this.getInstalled(LocalExtensionType.User)) .then(() => {
this.logService.info('Removed the extension from uninstalled list', id);
return this.getInstalled(LocalExtensionType.User);
})
.then(installed => installed.filter(i => i.identifier.id === id)[0]); .then(installed => installed.filter(i => i.identifier.id === id)[0]);
} }
return null; return null;
...@@ -364,10 +381,14 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -364,10 +381,14 @@ export class ExtensionManagementService implements IExtensionManagementService {
const extensionPath = path.join(this.extensionsPath, id); const extensionPath = path.join(this.extensionsPath, id);
return pfs.rimraf(extensionPath) return pfs.rimraf(extensionPath)
.then(() => { .then(() => {
this.logService.trace(`Extracting the extension from ${zipPath} to ${extensionPath}`, id);
return extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true }) return extract(zipPath, extensionPath, { sourcePath: 'extension', overwrite: true })
.then( .then(
() => TPromise.join([readManifest(extensionPath), pfs.readdir(extensionPath)]) () => {
.then(null, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_LOCAL))), this.logService.info(`Extracted extension to ${extensionPath}`, id);
return TPromise.join([readManifest(extensionPath), pfs.readdir(extensionPath)])
.then(null, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_LOCAL)));
},
e => TPromise.wrapError(new ExtensionManagementError(e.message, INSTALL_ERROR_EXTRACTING))) e => TPromise.wrapError(new ExtensionManagementError(e.message, INSTALL_ERROR_EXTRACTING)))
.then(([{ manifest }, children]) => { .then(([{ manifest }, children]) => {
const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0]; const readme = children.filter(child => /^readme(\.txt|\.md|)$/i.test(child))[0];
...@@ -379,8 +400,12 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -379,8 +400,12 @@ export class ExtensionManagementService implements IExtensionManagementService {
const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl }; const local: ILocalExtension = { type, identifier, manifest, metadata, path: extensionPath, readmeUrl, changelogUrl };
this.logService.trace(`Updating metadata of the extension`, id);
return this.saveMetadataForLocalExtension(local) return this.saveMetadataForLocalExtension(local)
.then(() => local, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_LOCAL))); .then(() => {
this.logService.info(`Updated metadata of the extension`, id);
return local;
}, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_LOCAL)));
}); });
}, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_DELETING))); }, e => TPromise.wrapError(new ExtensionManagementError(this.joinErrors(e).message, INSTALL_ERROR_DELETING)));
} }
...@@ -472,6 +497,7 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -472,6 +497,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
const dependencies = distinct(this.getDependenciesToUninstallRecursively(extension, installed, [])).filter(e => e !== extension); const dependencies = distinct(this.getDependenciesToUninstallRecursively(extension, installed, [])).filter(e => e !== extension);
return this.uninstallWithDependencies(extension, dependencies, installed); return this.uninstallWithDependencies(extension, dependencies, installed);
} }
this.logService.info('Cancelled uninstalling extension', extension.identifier.id);
return TPromise.wrapError(errors.canceled()); return TPromise.wrapError(errors.canceled());
}, error => TPromise.wrapError(errors.canceled())); }, error => TPromise.wrapError(errors.canceled()));
} }
...@@ -491,6 +517,7 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -491,6 +517,7 @@ export class ExtensionManagementService implements IExtensionManagementService {
if (value === 0) { if (value === 0) {
return this.uninstallWithDependencies(extension, [], installed); return this.uninstallWithDependencies(extension, [], installed);
} }
this.logService.info('Cancelled uninstalling extension', extension.identifier.id);
return TPromise.wrapError(errors.canceled()); return TPromise.wrapError(errors.canceled());
}, error => TPromise.wrapError(errors.canceled())); }, error => TPromise.wrapError(errors.canceled()));
} }
...@@ -564,7 +591,10 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -564,7 +591,10 @@ export class ExtensionManagementService implements IExtensionManagementService {
const extensionPath = path.join(this.extensionsPath, extension.identifier.id); const extensionPath = path.join(this.extensionsPath, extension.identifier.id);
return pfs.exists(extensionPath) return pfs.exists(extensionPath)
.then(exists => exists ? null : TPromise.wrapError(new Error(nls.localize('notExists', "Could not find extension")))) .then(exists => exists ? null : TPromise.wrapError(new Error(nls.localize('notExists', "Could not find extension"))))
.then(() => this._onUninstallExtension.fire(extension.identifier)); .then(() => {
this.logService.info('Uninstalling extesion', extension.identifier.id);
this._onUninstallExtension.fire(extension.identifier);
});
} }
private uninstallExtension(local: ILocalExtension): TPromise<void> { private uninstallExtension(local: ILocalExtension): TPromise<void> {
...@@ -575,13 +605,15 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -575,13 +605,15 @@ export class ExtensionManagementService implements IExtensionManagementService {
} }
private async postUninstallExtension(extension: ILocalExtension, error?: string): TPromise<void> { private async postUninstallExtension(extension: ILocalExtension, error?: string): TPromise<void> {
if (!error) { if (error) {
this.logService.info('Successfully uninstalled extesion', extension.identifier.id);
} else {
this.logService.error('Failed to uninstall extesion', extension.identifier.id, error);
// only report if extension has a mapped gallery extension. UUID identifies the gallery extension. // only report if extension has a mapped gallery extension. UUID identifies the gallery extension.
if (extension.identifier.uuid) { if (extension.identifier.uuid) {
await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall); await this.galleryService.reportStatistic(extension.manifest.publisher, extension.manifest.name, extension.manifest.version, StatisticType.Uninstall);
} }
} }
this._onDidUninstallExtension.fire({ identifier: extension.identifier, error }); this._onDidUninstallExtension.fire({ identifier: extension.identifier, error });
} }
...@@ -600,12 +632,19 @@ export class ExtensionManagementService implements IExtensionManagementService { ...@@ -600,12 +632,19 @@ export class ExtensionManagementService implements IExtensionManagementService {
} }
private scanSystemExtensions(): TPromise<ILocalExtension[]> { private scanSystemExtensions(): TPromise<ILocalExtension[]> {
return this.scanExtensions(SystemExtensionsRoot, LocalExtensionType.System); this.logService.trace('Scanning system extesions');
return this.scanExtensions(SystemExtensionsRoot, LocalExtensionType.System)
.then(result => {
this.logService.info('Finished scanning system extesions', result.length);
return result;
});
} }
private scanUserExtensions(excludeOutdated: boolean): TPromise<ILocalExtension[]> { private scanUserExtensions(excludeOutdated: boolean): TPromise<ILocalExtension[]> {
this.logService.trace('Scanning user extesions');
return this.scanExtensions(this.extensionsPath, LocalExtensionType.User) return this.scanExtensions(this.extensionsPath, LocalExtensionType.User)
.then(extensions => { .then(extensions => {
this.logService.info('Finished scanning user extesions', extensions.length);
if (excludeOutdated) { if (excludeOutdated) {
const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid })); const byExtension: ILocalExtension[][] = groupByExtension(extensions, e => ({ id: getGalleryExtensionIdFromLocal(e), uuid: e.identifier.uuid }));
return byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]); return byExtension.map(p => p.sort((a, b) => semver.rcompare(a.manifest.version, b.manifest.version))[0]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册