@@ -18,13 +18,10 @@ import {
18
18
ServerInstallOptions , ServerInstallVSIXOptions , ServerUninstallOptions , Metadata , ServerInstallExtensionEvent , ServerInstallExtensionResult , ServerUninstallExtensionEvent , ServerDidUninstallExtensionEvent
19
19
} from 'vs/platform/extensionManagement/common/extensionManagement' ;
20
20
import { areSameExtensions , ExtensionKey , getGalleryExtensionTelemetryData , getLocalExtensionTelemetryData , getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil' ;
21
- import { IExtensionsProfileScannerService } from 'vs/platform/extensionManagement/common/extensionsProfileScannerService' ;
22
21
import { ExtensionType , IExtensionManifest , TargetPlatform } from 'vs/platform/extensions/common/extensions' ;
23
22
import { ILogService } from 'vs/platform/log/common/log' ;
24
23
import { IProductService } from 'vs/platform/product/common/productService' ;
25
24
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
26
- import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity' ;
27
- import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile' ;
28
25
29
26
export interface IInstallExtensionTask {
30
27
readonly identifier : IExtensionIdentifier ;
@@ -66,10 +63,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
66
63
private readonly participants : IExtensionManagementParticipant [ ] = [ ] ;
67
64
68
65
constructor (
69
- @IUserDataProfilesService private readonly userDataProfilesService : IUserDataProfilesService ,
70
- @IUriIdentityService private readonly uriIdenityService : IUriIdentityService ,
71
66
@IExtensionGalleryService protected readonly galleryService : IExtensionGalleryService ,
72
- @IExtensionsProfileScannerService protected readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
73
67
@ITelemetryService protected readonly telemetryService : ITelemetryService ,
74
68
@ILogService protected readonly logService : ILogService ,
75
69
@IProductService protected readonly productService : IProductService
@@ -120,7 +114,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
120
114
throw new Error ( nls . localize ( 'Not a Marketplace extension' , "Only Marketplace Extensions can be reinstalled" ) ) ;
121
115
}
122
116
123
- await this . createDefaultUninstallExtensionTask ( extension , { remove : true , versionOnly : true } ) . run ( ) ;
117
+ await this . createUninstallExtensionTask ( extension , { remove : true , versionOnly : true } ) . run ( ) ;
124
118
await this . installFromGallery ( galleryExtension ) ;
125
119
}
126
120
@@ -140,13 +134,15 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
140
134
}
141
135
142
136
protected async installExtension ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : Promise < ILocalExtension > {
137
+
138
+ const getInstallExtensionTaskKey = ( extension : IGalleryExtension ) => `${ ExtensionKey . create ( extension ) . toString ( ) } ${ options . profileLocation ? `-${ options . profileLocation . toString ( ) } ` : '' } ` ;
139
+
143
140
// only cache gallery extensions tasks
144
141
if ( ! URI . isUri ( extension ) ) {
145
- const installExtensionTask = this . installingExtensions . get ( ExtensionKey . create ( extension ) . toString ( ) ) ;
142
+ const installExtensionTask = this . installingExtensions . get ( getInstallExtensionTaskKey ( extension ) ) ;
146
143
if ( installExtensionTask ) {
147
144
this . logService . info ( 'Extensions is already requested to install' , extension . identifier . id ) ;
148
- const waitUntilTaskIsFinishedTask = this . createWaitUntilInstallExtensionTaskIsFinishedTask ( installExtensionTask , options ) ;
149
- const { local } = await waitUntilTaskIsFinishedTask . waitUntilTaskIsFinished ( ) ;
145
+ const { local } = await installExtensionTask . waitUntilTaskIsFinished ( ) ;
150
146
return local ;
151
147
}
152
148
options = { ...options , installOnlyNewlyAddedFromExtensionPack : true /* always true for gallery extensions */ } ;
@@ -156,7 +152,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
156
152
const installResults : ( ServerInstallExtensionResult & { local : ILocalExtension } ) [ ] = [ ] ;
157
153
const installExtensionTask = this . createInstallExtensionTask ( manifest , extension , options ) ;
158
154
if ( ! URI . isUri ( extension ) ) {
159
- this . installingExtensions . set ( ExtensionKey . create ( extension ) . toString ( ) , installExtensionTask ) ;
155
+ this . installingExtensions . set ( getInstallExtensionTaskKey ( extension ) , installExtensionTask ) ;
160
156
}
161
157
this . _onInstallExtension . fire ( { identifier : installExtensionTask . identifier , source : extension , profileLocation : options . profileLocation } ) ;
162
158
this . logService . info ( 'Installing extension:' , installExtensionTask . identifier . id ) ;
@@ -171,7 +167,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
171
167
const allDepsAndPackExtensionsToInstall = await this . getAllDepsAndPackExtensionsToInstall ( installExtensionTask . identifier , manifest , ! ! options . installOnlyNewlyAddedFromExtensionPack , ! ! options . installPreReleaseVersion , options . profileLocation ) ;
172
168
for ( const { gallery, manifest } of allDepsAndPackExtensionsToInstall ) {
173
169
installExtensionHasDependents = installExtensionHasDependents || ! ! manifest . extensionDependencies ?. some ( id => areSameExtensions ( { id } , installExtensionTask . identifier ) ) ;
174
- const key = ExtensionKey . create ( gallery ) . toString ( ) ;
170
+ const key = getInstallExtensionTaskKey ( gallery ) ;
175
171
if ( this . installingExtensions . has ( key ) ) {
176
172
this . logService . info ( 'Extension is already requested to install' , gallery . identifier . id ) ;
177
173
} else {
@@ -260,7 +256,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
260
256
// rollback installed extensions
261
257
if ( installResults . length ) {
262
258
try {
263
- const result = await Promise . allSettled ( installResults . map ( ( { local } ) => this . createUninstallExtensionTask ( local , { versionOnly : true } , options . profileLocation ) . run ( ) ) ) ;
259
+ const result = await Promise . allSettled ( installResults . map ( ( { local } ) => this . createUninstallExtensionTask ( local , { versionOnly : true , profileLocation : options . profileLocation } ) . run ( ) ) ) ;
264
260
for ( let index = 0 ; index < result . length ; index ++ ) {
265
261
const r = result [ index ] ;
266
262
const { identifier } = installResults [ index ] ;
@@ -282,7 +278,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
282
278
/* Remove the gallery tasks from the cache */
283
279
for ( const { task } of allInstallExtensionTasks ) {
284
280
if ( ! URI . isUri ( task . source ) ) {
285
- const key = ExtensionKey . create ( task . source ) . toString ( ) ;
281
+ const key = getInstallExtensionTaskKey ( task . source ) ;
286
282
if ( ! this . installingExtensions . delete ( key ) ) {
287
283
this . logService . warn ( 'Installation task is not found in the cache' , key ) ;
288
284
}
@@ -434,7 +430,7 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
434
430
}
435
431
436
432
const createUninstallExtensionTask = ( extension : ILocalExtension , uninstallOptions : ServerUninstallOptions ) : IUninstallExtensionTask => {
437
- const uninstallExtensionTask = this . createUninstallExtensionTask ( extension , uninstallOptions , options . profileLocation ) ;
433
+ const uninstallExtensionTask = this . createUninstallExtensionTask ( extension , uninstallOptions ) ;
438
434
this . uninstallingExtensions . set ( getUninstallExtensionTaskKey ( uninstallExtensionTask . extension . identifier ) , uninstallExtensionTask ) ;
439
435
if ( options . profileLocation ) {
440
436
this . logService . info ( 'Uninstalling extension from the profile:' , `${ extension . identifier . id } @${ extension . manifest . version } ` , options . profileLocation . toString ( ) ) ;
@@ -603,25 +599,6 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
603
599
}
604
600
}
605
601
606
- private createInstallExtensionTask ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask {
607
- const installTask = this . createDefaultInstallExtensionTask ( manifest , extension , options ) ;
608
- return options . profileLocation && this . userDataProfilesService . defaultProfile . extensionsResource ? new InstallExtensionInProfileTask ( installTask , options . profileLocation , this . userDataProfilesService . defaultProfile . extensionsResource , this . extensionsProfileScannerService ) : installTask ;
609
- }
610
-
611
- private createWaitUntilInstallExtensionTaskIsFinishedTask ( installTask : IInstallExtensionTask , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask {
612
- if ( ! options . profileLocation || ! this . userDataProfilesService . defaultProfile . extensionsResource ) {
613
- return installTask ;
614
- }
615
- if ( installTask instanceof InstallExtensionInProfileTask && this . uriIdenityService . extUri . isEqual ( installTask . profileLocation , options . profileLocation ) ) {
616
- return installTask ;
617
- }
618
- return new InstallExtensionInProfileTask ( installTask , options . profileLocation , this . userDataProfilesService . defaultProfile . extensionsResource , this . extensionsProfileScannerService ) ;
619
- }
620
-
621
- private createUninstallExtensionTask ( extension : ILocalExtension , options : ServerUninstallOptions , profile ?: URI ) : IUninstallExtensionTask {
622
- return profile && this . userDataProfilesService . defaultProfile . extensionsResource ? new UninstallExtensionFromProfileTask ( extension , profile , this . userDataProfilesService , this . extensionsProfileScannerService ) : this . createDefaultUninstallExtensionTask ( extension , options ) ;
623
- }
624
-
625
602
abstract getTargetPlatform ( ) : Promise < TargetPlatform > ;
626
603
abstract zip ( extension : ILocalExtension ) : Promise < URI > ;
627
604
abstract unzip ( zipLocation : URI ) : Promise < IExtensionIdentifier > ;
@@ -633,8 +610,8 @@ export abstract class AbstractExtensionManagementService extends Disposable impl
633
610
abstract updateMetadata ( local : ILocalExtension , metadata : IGalleryMetadata ) : Promise < ILocalExtension > ;
634
611
abstract updateExtensionScope ( local : ILocalExtension , isMachineScoped : boolean ) : Promise < ILocalExtension > ;
635
612
636
- protected abstract createDefaultInstallExtensionTask ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask ;
637
- protected abstract createDefaultUninstallExtensionTask ( extension : ILocalExtension , options : ServerUninstallOptions ) : IUninstallExtensionTask ;
613
+ protected abstract createInstallExtensionTask ( manifest : IExtensionManifest , extension : URI | IGalleryExtension , options : ServerInstallOptions & ServerInstallVSIXOptions ) : IInstallExtensionTask ;
614
+ protected abstract createUninstallExtensionTask ( extension : ILocalExtension , options : ServerUninstallOptions ) : IUninstallExtensionTask ;
638
615
}
639
616
640
617
export function joinErrors ( errorOrErrors : ( Error | string ) | ( Array < Error | string > ) ) : Error {
@@ -731,63 +708,3 @@ export abstract class AbstractExtensionTask<T> {
731
708
732
709
protected abstract doRun ( token : CancellationToken ) : Promise < T > ;
733
710
}
734
-
735
- class InstallExtensionInProfileTask implements IInstallExtensionTask {
736
-
737
- readonly identifier = this . task . identifier ;
738
- readonly source = this . task . source ;
739
- readonly operation = this . task . operation ;
740
-
741
- private readonly promise : Promise < { local : ILocalExtension ; metadata : Metadata } > ;
742
-
743
- constructor (
744
- private readonly task : IInstallExtensionTask ,
745
- readonly profileLocation : URI ,
746
- private readonly defaultProfileLocation : URI ,
747
- private readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
748
- ) {
749
- this . promise = this . waitAndAddExtensionToProfile ( ) ;
750
- }
751
-
752
- private async waitAndAddExtensionToProfile ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
753
- const result = await this . task . waitUntilTaskIsFinished ( ) ;
754
- const profileLocation = result . local . isApplicationScoped ? this . defaultProfileLocation : this . profileLocation ;
755
- await this . extensionsProfileScannerService . addExtensionsToProfile ( [ [ result . local , result . metadata ] ] , profileLocation ) ;
756
- return result ;
757
- }
758
-
759
- async run ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
760
- await this . task . run ( ) ;
761
- return this . promise ;
762
- }
763
-
764
- waitUntilTaskIsFinished ( ) : Promise < { local : ILocalExtension ; metadata : Metadata } > {
765
- return this . promise ;
766
- }
767
-
768
- cancel ( ) : void {
769
- return this . task . cancel ( ) ;
770
- }
771
- }
772
-
773
- class UninstallExtensionFromProfileTask extends AbstractExtensionTask < void > implements IUninstallExtensionTask {
774
-
775
- constructor (
776
- readonly extension : ILocalExtension ,
777
- private readonly profileLocation : URI ,
778
- private readonly userDataProfilesService : IUserDataProfilesService ,
779
- private readonly extensionsProfileScannerService : IExtensionsProfileScannerService ,
780
- ) {
781
- super ( ) ;
782
- }
783
-
784
- protected async doRun ( token : CancellationToken ) : Promise < void > {
785
- const promises : Promise < any > [ ] = [ ] ;
786
- promises . push ( this . extensionsProfileScannerService . removeExtensionFromProfile ( this . extension . identifier , this . profileLocation ) ) ;
787
- if ( this . extension . isApplicationScoped && this . userDataProfilesService . defaultProfile . extensionsResource ) {
788
- promises . push ( this . extensionsProfileScannerService . removeExtensionFromProfile ( this . extension . identifier , this . userDataProfilesService . defaultProfile . extensionsResource ) ) ;
789
- }
790
- await Promise . all ( promises ) ;
791
- }
792
-
793
- }
0 commit comments