/// <summary> /// Based on the provided product configuration and the new packages, returns a joint list of the packages /// </summary> /// <param name="packageGraph">Existing product configuration</param> /// <param name="newPackages">New packages to install. Some packages may be defined only by name, without version or using NuGet versioning notation</param> /// <returns>Combined list of the versioned packages</returns> /// <exception cref="System.ArgumentException">Package Id cannot be empty</exception> public async Task <ICollection <PackageId> > Discover(IPackageGraph packageGraph, ICollection <PackageId> newPackages) { var tasks = new List <Task <PackageId> >(); foreach (var packageId in newPackages) { if (string.IsNullOrWhiteSpace(packageId.Id)) { throw new ArgumentException("Package Id cannot be empty"); } tasks.Add(NuGetEngine.ResolvePackageVersion(packageId)); } var versionedPackages = (await Task.WhenAll(tasks)).ToList(); var productPackages = packageGraph.Packages.Select(x => x.Package); foreach (var productPackage in productPackages) { var addPackage = !versionedPackages.Any(x => string.Equals(x.Id, productPackage.Id, StringComparison.CurrentCultureIgnoreCase)); if (addPackage) { versionedPackages.Add(productPackage); } } return(versionedPackages); }
/// <summary> /// Generates an installation plan /// </summary> /// <param name="productPackages">Current product</param> /// <param name="packages">Packages to install</param> /// <returns><see cref="InstallationPlan" /></returns> public async Task <InstallationPlan> PlanInstallation(IPackageGraph productPackages, ICollection <PackageId> packages) { var plan = new InstallationPlan(); var resolvedPackagesDictionary = new Dictionary <PackageId, DeploymentPackageInfo>(); var resolvedPackages = await NuGetEngine.ResolvePackages(packages); NuGetEngine.AnalyzePackages(resolvedPackages); var graphBuilder = new PackageGraphBuilder(); foreach (var innerNode in resolvedPackages.InnerNodes) { TranslateNuGetGraphNode(innerNode, graphBuilder, resolvedPackagesDictionary); } plan.TargetPackageGraph = graphBuilder.Build(); var resolvedPackagesList = plan.TargetPackageGraph.FlattenMostDependentFirst(); var productPackagesList = productPackages.FlattenMostDependentFirst(); var deploymentActions = new List <DeploymentAction>(); foreach (var packageId in resolvedPackagesList) { var packageMatch = productPackagesList.FirstOrDefault(x => x.Id == packageId.Id); var isUpdate = (packageMatch != null) && (packageMatch.Version != packageId.Version); var install = (packageMatch == null) || isUpdate; if (isUpdate) { deploymentActions.Add(new DeletePackageAction(DeploymentContext, true, packageMatch)); plan.UpdateCount++; } if (install) { var packageInfo = resolvedPackagesDictionary[packageId]; deploymentActions.Add(new DownloadPackageAction(DeploymentContext, isUpdate, packageInfo, NuGetEngine, PackagesFolderPath)); deploymentActions.Add(new InstallPackageAction(DeploymentContext, isUpdate, packageInfo, DeploymentStrategyProvider)); if (!isUpdate) { plan.InstallCount++; } } else { plan.RemainingPackages.Add(packageId); } } plan.Actions = deploymentActions.Where(x => x is DownloadPackageAction) .Concat(deploymentActions.Where(x => x is DeletePackageAction)) .Concat(deploymentActions.Where(x => x is InstallPackageAction)) .ToList(); return(plan); }
/// <summary> /// Generates an uninstallation plan /// </summary> /// <param name="productPackages">Current product</param> /// <param name="packages">Packages to uninstall</param> /// <param name="removeDependencies">Defines whether the package dependencies shall be removed as well. When false, only the requested packages will be deleted</param> /// <returns><see cref="UninstallationPlan" /></returns> public async Task <UninstallationPlan> PlanUninstallation(IPackageGraph productPackages, ICollection <PackageId> packages, bool removeDependencies) { if (removeDependencies) { packages = productPackages.SliceWithDependencies(packages, true).FlattenMostDependentFirst(); } var plan = new UninstallationPlan { Actions = packages.Select(package => new DeletePackageAction(DeploymentContext, false, package)) .Cast <DeploymentAction>() .ToList() }; return(await Task.FromResult(plan)); }
public void Reconfigure(IEnumerable <IPackageConfiguration> packages, IPackageGraph packageGraph, IDictionary <PackageId, IEnumerable <string> > files) { Packages = packageGraph; ProductPackages.Clear(); foreach (var package in packages) { var info = new ProductPackageInfo { Configuration = package }; var packageFiles = files.FirstOrDefault(f => f.Key.IsSamePackage(package.Id)).Value; if (packageFiles != null) { info.Files.AddRange(packageFiles); } ProductPackages.Add(info); } }
private bool ReconfiguringPackages(IEnumerable <ProductPackageInfo> packagesInfo, IPackageGraph resolvedPackagesGraph) { var packages = new List <IPackageConfiguration>(); var packageFiles = new Dictionary <PackageId, IEnumerable <IPackageFile> >(); foreach (var packageInfo in packagesInfo) { packages.Add(packageInfo.Configuration); packageFiles.Add(packageInfo.Configuration.Id, packageInfo.Files); } DeploymentContext.ProductConfigurationProvider.Reconfigure(packages, resolvedPackagesGraph, packageFiles); DeploymentContext.ProductConfigurationProvider.Save(); return(true); }