public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { var nugetAware = action.Target.TryGetFeature <NuGetAwareProject>(); if (nugetAware != null) { var task = nugetAware.UninstallPackage( action.PackageIdentity, context, cancelToken); task.Wait(); return; } // Get the project manager var projectManager = action.Target.GetRequiredFeature <IProjectManager>(); // Get the package out of the project manager var package = projectManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // Add the package to the project projectManager.Logger = new ShimLogger(context); projectManager.Project.Logger = projectManager.Logger; projectManager.Execute(new PackageOperation( package, NuGet.PackageAction.Uninstall)); // Run uninstall.ps1 if present ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "uninstall.ps1", action.Target, package, projectManager.PackageManager.PathResolver.GetInstallPath(package), context); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { // Use the core-interop feature to execute the action var packageManager = action.Target.GetRequiredFeature<IPackageManager>(); // Preconditions: Debug.Assert(!packageManager.LocalRepository.IsReferenced( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)), "Expected the purge operation would only be executed AFTER the package was no longer referenced!"); // Get the package out of the project manager var package = packageManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // Purge the package from the local repository packageManager.Logger = new ShimLogger(context); packageManager.Execute(new PackageOperation( package, NuGet.PackageAction.Uninstall)); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { var nugetAware = action.Target.TryGetFeature<NuGetAwareProject>(); if (nugetAware != null) { var task = nugetAware.UninstallPackage( action.PackageIdentity, context, cancelToken); task.Wait(); return; } // Get the project manager var projectManager = action.Target.GetRequiredFeature<IProjectManager>(); // Get the package out of the project manager var package = projectManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // Add the package to the project projectManager.Logger = new ShimLogger(context); projectManager.Project.Logger = projectManager.Logger; projectManager.Execute(new PackageOperation( package, NuGet.PackageAction.Uninstall)); // Run uninstall.ps1 if present ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "uninstall.ps1", action.Target, package, projectManager.PackageManager.PathResolver.GetInstallPath(package), context); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { // Use the core-interop feature to execute the action var packageManager = action.Target.GetRequiredFeature <IPackageManager>(); // Preconditions: Debug.Assert(!packageManager.LocalRepository.IsReferenced( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)), "Expected the purge operation would only be executed AFTER the package was no longer referenced!"); // Get the package out of the project manager var package = packageManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // Purge the package from the local repository packageManager.Logger = new ShimLogger(context); packageManager.Execute(new PackageOperation( package, NuGet.PackageAction.Uninstall)); }
public void Rollback(NewPackageAction action, IExecutionContext context) { // Just run the uninstall action to undo a install new UninstallActionHandler().Execute(action, context, CancellationToken.None); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { var nugetAware = action.Target.TryGetFeature<NuGetAwareProject>(); if (nugetAware != null) { // TODO: this is a hack to get the supported frameworks. Since action.Package // does not contain this info for now, we have to download the package to // get this info. var packageContent = action.Package[Properties.PackageContent].ToString(); var downloadUri = new Uri(packageContent); IPackage package; if (downloadUri.IsFile) { package = new OptimizedZipPackage(packageContent); } else { var packageCache = action.Target.GetRequiredFeature<IPackageCacheRepository>(); package = DownloadActionHandler.GetPackage( packageCache, action.PackageIdentity, downloadUri); } var frameworks = package.GetSupportedFrameworks(); var task = nugetAware.InstallPackage( action.PackageIdentity, frameworks, context, cancelToken); task.Wait(); } else { // TODO: PMC - Write Disclamer Texts // TODO: Dialog & PMC - open Readme.txt // Get the package manager and project manager from the target var packageManager = action.Target.GetRequiredFeature<IPackageManager>(); var projectManager = action.Target.GetRequiredFeature<IProjectManager>(); // Get the package from the shared repository var package = packageManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // The package had better be in the local repository!! // Ping the metrics service action.Source.RecordMetric( action.ActionType, action.PackageIdentity, action.DependentPackage, action.IsUpdate, action.Target); // Add the package to the project projectManager.Logger = new ShimLogger(context); projectManager.Project.Logger = projectManager.Logger; projectManager.Execute(new PackageOperation( package, NuGet.PackageAction.Install)); // Run install.ps1 if present ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "install.ps1", action.Target, package, packageManager.PathResolver.GetInstallPath(package), context); } }
private bool RestorePackage( IFileSystem packagesFolderFileSystem, PackageIdentity packageIdentity, bool packageRestoreConsent, ConcurrentQueue<JObject> satellitePackages) { // BUGBUG: Looks like we are creating PackageManager for every single restore. This is likely done to support execution in parallel var packageManager = CreatePackageManager(packagesFolderFileSystem, useSideBySidePaths: true); if (IsPackageInstalled(packageManager.LocalRepository, packagesFolderFileSystem, packageIdentity)) { return false; } // BUGBUG: Investigate if the following lock is needed EnsurePackageRestoreConsent(packageRestoreConsent); if (RequireConsent && _outputOptOutMessage) { lock (_outputOptOutMessageLock) { if (_outputOptOutMessage) { string message = String.Format( CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("RestoreCommandPackageRestoreOptOutMessage"), NuGet.Resources.NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", "")); Console.WriteLine(message); _outputOptOutMessage = false; } } } SourceRepository = SourceRepositoryHelper.CreateSourceRepository(SourceProvider, Source); // BUGBUG: TO BE REMOVED AFTER INVESTIGATION using (packageManager.SourceRepository.StartOperation( RepositoryOperationNames.Restore, packageIdentity.Id, packageIdentity.Version == null ? null : packageIdentity.Version.ToString())) { // BUGBUG: Satellite packages should only be restored at the end. Find out Why first?? // And, then, handle it here var filesystemInstallationTarget = new FilesystemInstallationTarget(packageManager); // BUGBUG: Should consider using async method and await var task = SourceRepository.GetPackageMetadata(packageIdentity.Id, packageIdentity.Version); task.Wait(); var packageJSON = task.Result; if (IsSatellitePackage(packageJSON)) { // Satellite packages would necessarily have to be installed later than the corresponding package. // We'll collect them in a list to keep track and then install them later. satellitePackages.Enqueue(packageJSON); return true; } var packageAction = new NewPackageAction(NuGet.Client.PackageActionType.Download, packageIdentity, packageJSON, filesystemInstallationTarget, SourceRepository, null); // BUGBUG: See PackageExtractor.cs for locking mechanism used to handle concurrency NuGet.Client.Installation.ActionExecutor actionExecutor = new Client.Installation.ActionExecutor(); // BUGBUG: This is likely inefficient. Consider collecting all actions first and executing them in 1 shot var packageActions = new List<NewPackageAction>() { packageAction }; actionExecutor.ExecuteActions(packageActions, Console); return true; } }
public void Rollback(NewPackageAction action, IExecutionContext context) { // Just run the download action to undo a purge new DownloadActionHandler().Execute(action, context, CancellationToken.None); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { string downloadUriStr = action.Package[Properties.PackageContent].ToString(); Uri downloadUri; if (String.IsNullOrEmpty(downloadUriStr)) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.DownloadActionHandler_NoDownloadUrl, action.PackageIdentity)); } else if (!Uri.TryCreate(downloadUriStr, UriKind.Absolute, out downloadUri)) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.DownloadActionHandler_InvalidDownloadUrl, action.PackageIdentity, downloadUriStr)); } // Get required features from the target var packageManager = action.Target.GetRequiredFeature <IPackageManager>(); var packageCache = action.Target.TryGetFeature <IPackageCacheRepository>(); // Load the package IPackage package = null; if (downloadUri.IsFile) { // To keep feature backward-compatbility. The .nupkg file on disk may have a shorter name than semantic version. // For example: TestPackage 2.0.0.0 may be saved as TestPackage.2.0.nupkg on disk. SemanticVersion originalVersion = new SemanticVersion(action.PackageIdentity.Version.ToString()); IEnumerable <SemanticVersion> possibleVersions = VersionUtility.GetPossibleVersions(originalVersion); foreach (SemanticVersion version in possibleVersions) { // Get other alternative download path string downloadPath = downloadUri.LocalPath.Replace(originalVersion.ToString(), version.ToString()); try { package = new OptimizedZipPackage(downloadPath); break; } catch (ArgumentException) { } } // Verify the version of OptimizedZipPackage is expected. if (package == null || package.Version != originalVersion) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.FileDoesNotExit, downloadUri.LocalPath)); } } else { package = GetPackage(packageCache, action.PackageIdentity, downloadUri); } NuGetTraceSources.ActionExecutor.Verbose( "download/loadedpackage", "[{0}] Loaded package.", action.PackageIdentity); // Now convert the action and use the V2 Execution logic since we // have a true V2 IPackage (either from the cache or an in-memory ZipPackage). packageManager.Logger = new ShimLogger(context); packageManager.Execute(new PackageOperation( package, NuGet.PackageAction.Install)); // Run init.ps1 if present. Init is run WITHOUT specifying a target framework. ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "init.ps1", action.Target, package, packageManager.PathResolver.GetInstallPath(package), context); }
public void Rollback(NewPackageAction action, IExecutionContext context) { // Just run the purge action to undo a download new PurgeActionHandler().Execute(action, context, CancellationToken.None); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { string downloadUriStr = action.Package[Properties.PackageContent].ToString(); Uri downloadUri; if (String.IsNullOrEmpty(downloadUriStr)) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.DownloadActionHandler_NoDownloadUrl, action.PackageIdentity)); } else if (!Uri.TryCreate(downloadUriStr, UriKind.Absolute, out downloadUri)) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, Strings.DownloadActionHandler_InvalidDownloadUrl, action.PackageIdentity, downloadUriStr)); } // Get required features from the target var packageManager = action.Target.GetRequiredFeature<IPackageManager>(); var packageCache = action.Target.TryGetFeature<IPackageCacheRepository>(); // Load the package IPackage package = null; if (downloadUri.IsFile) { // To keep feature backward-compatbility. The .nupkg file on disk may have a shorter name than semantic version. // For example: TestPackage 2.0.0.0 may be saved as TestPackage.2.0.nupkg on disk. SemanticVersion originalVersion = new SemanticVersion(action.PackageIdentity.Version.ToString()); IEnumerable<SemanticVersion> possibleVersions = VersionUtility.GetPossibleVersions(originalVersion); foreach (SemanticVersion version in possibleVersions) { // Get other alternative download path string downloadPath = downloadUri.LocalPath.Replace(originalVersion.ToString(), version.ToString()); try { package = new OptimizedZipPackage(downloadPath); break; } catch (ArgumentException) { } } // Verify the version of OptimizedZipPackage is expected. if (package == null || package.Version != originalVersion) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.FileDoesNotExit, downloadUri.LocalPath)); } } else { package = GetPackage(packageCache, action.PackageIdentity, downloadUri); } NuGetTraceSources.ActionExecutor.Verbose( "download/loadedpackage", "[{0}] Loaded package.", action.PackageIdentity); // Now convert the action and use the V2 Execution logic since we // have a true V2 IPackage (either from the cache or an in-memory ZipPackage). packageManager.Logger = new ShimLogger(context); packageManager.Execute(new PackageOperation( package, NuGet.PackageAction.Install)); // Run init.ps1 if present. Init is run WITHOUT specifying a target framework. ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "init.ps1", action.Target, package, packageManager.PathResolver.GetInstallPath(package), context); }
public void Rollback(NewPackageAction action, IExecutionContext context) { // Just run the install action to undo a uninstall new InstallActionHandler().Execute(action, context, CancellationToken.None); }
public void Execute(NewPackageAction action, IExecutionContext context, CancellationToken cancelToken) { var nugetAware = action.Target.TryGetFeature <NuGetAwareProject>(); if (nugetAware != null) { // TODO: this is a hack to get the supported frameworks. Since action.Package // does not contain this info for now, we have to download the package to // get this info. var packageContent = action.Package[Properties.PackageContent].ToString(); var downloadUri = new Uri(packageContent); IPackage package; if (downloadUri.IsFile) { package = new OptimizedZipPackage(packageContent); } else { var packageCache = action.Target.GetRequiredFeature <IPackageCacheRepository>(); package = DownloadActionHandler.GetPackage( packageCache, action.PackageIdentity, downloadUri); } var frameworks = package.GetSupportedFrameworks(); var task = nugetAware.InstallPackage( action.PackageIdentity, frameworks, context, cancelToken); task.Wait(); } else { // TODO: PMC - Write Disclamer Texts // TODO: Dialog & PMC - open Readme.txt // Get the package manager and project manager from the target var packageManager = action.Target.GetRequiredFeature <IPackageManager>(); var projectManager = action.Target.GetRequiredFeature <IProjectManager>(); // Get the package from the shared repository var package = packageManager.LocalRepository.FindPackage( action.PackageIdentity.Id, CoreConverters.SafeToSemanticVersion(action.PackageIdentity.Version)); Debug.Assert(package != null); // The package had better be in the local repository!! // Ping the metrics service action.Source.RecordMetric( action.ActionType, action.PackageIdentity, action.DependentPackage, action.IsUpdate, action.Target); // Add the package to the project projectManager.Logger = new ShimLogger(context); projectManager.Project.Logger = projectManager.Logger; projectManager.Execute(new PackageOperation( package, NuGet.PackageAction.Install)); // Run install.ps1 if present ActionHandlerHelpers.ExecutePowerShellScriptIfPresent( "install.ps1", action.Target, package, packageManager.PathResolver.GetInstallPath(package), context); } }
private bool RestorePackage( IFileSystem packagesFolderFileSystem, PackageIdentity packageIdentity, bool packageRestoreConsent, ConcurrentQueue <JObject> satellitePackages) { // BUGBUG: Looks like we are creating PackageManager for every single restore. This is likely done to support execution in parallel var packageManager = CreatePackageManager(packagesFolderFileSystem, useSideBySidePaths: true); if (IsPackageInstalled(packageManager.LocalRepository, packagesFolderFileSystem, packageIdentity)) { return(false); } // BUGBUG: Investigate if the following lock is needed EnsurePackageRestoreConsent(packageRestoreConsent); if (RequireConsent && _outputOptOutMessage) { lock (_outputOptOutMessageLock) { if (_outputOptOutMessage) { string message = String.Format( CultureInfo.CurrentCulture, LocalizedResourceManager.GetString("RestoreCommandPackageRestoreOptOutMessage"), NuGet.Resources.NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", "")); Console.WriteLine(message); _outputOptOutMessage = false; } } } SourceRepository = SourceRepositoryHelper.CreateSourceRepository(SourceProvider, Source); // BUGBUG: TO BE REMOVED AFTER INVESTIGATION using (packageManager.SourceRepository.StartOperation( RepositoryOperationNames.Restore, packageIdentity.Id, packageIdentity.Version == null ? null : packageIdentity.Version.ToString())) { // BUGBUG: Satellite packages should only be restored at the end. Find out Why first?? // And, then, handle it here var filesystemInstallationTarget = new FilesystemInstallationTarget(packageManager); // BUGBUG: Should consider using async method and await var task = SourceRepository.GetPackageMetadata(packageIdentity.Id, packageIdentity.Version); task.Wait(); var packageJSON = task.Result; if (IsSatellitePackage(packageJSON)) { // Satellite packages would necessarily have to be installed later than the corresponding package. // We'll collect them in a list to keep track and then install them later. satellitePackages.Enqueue(packageJSON); return(true); } var packageAction = new NewPackageAction(NuGet.Client.PackageActionType.Download, packageIdentity, packageJSON, filesystemInstallationTarget, SourceRepository, null); // BUGBUG: See PackageExtractor.cs for locking mechanism used to handle concurrency NuGet.Client.Installation.ActionExecutor actionExecutor = new Client.Installation.ActionExecutor(); // BUGBUG: This is likely inefficient. Consider collecting all actions first and executing them in 1 shot var packageActions = new List <NewPackageAction>() { packageAction }; actionExecutor.ExecuteActions(packageActions, Console); return(true); } }