Exemple #1
0
        protected async Task <PackageId> ResolvePackageVersion(PackageId packageId)
        {
            PackageId package = null;

            if (!string.IsNullOrWhiteSpace(packageId.Version))
            {
                var resolvedVer = VersionRange.Parse(packageId.Version);
                if (resolvedVer == null)
                {
                    throw LogException(new ArgumentException($"Provided package version is incorrect: {packageId.Version}"));
                }

                package = packageId;
            }
            else
            {
                var version = await NuGetEngine.ResolveNuGetVersion(packageId);

                if (version != null)
                {
                    package = new PackageId(packageId.Id, version, packageId.AllowPrereleaseVersions);
                }
            }

            if (package == null)
            {
                throw LogException(new ArgumentException($"Version for package {packageId.Id} cannot be resolved"));
            }

            Logger.Trace($"Package {packageId.Id} resolved as {package.Id}/{package.Version}");
            return(package);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        protected virtual void OnDownloadPackages(string path)
        {
            foreach (var package in WorkflowContext.PackagesForInstallation)
            {
                NuGetEngine.InstallPackage(package.Match, path).GetAwaiter().GetResult();
                package.PackagePath = NuGetEngine.GetPackageTargetPath(package.Match.Library.Name,
                                                                       package.Match.Library.Version, path);

                RaiseDeploymentEvent(new AfterPackageDownloadedEvent {
                    PackagePath = package.PackagePath
                }, package.Id);
            }
        }
        /// <summary>
        /// Called by <see cref="GetPackageFiles"/> method.
        /// </summary>
        /// <param name="packageId">The package identifier.</param>
        /// <param name="packagePath">The package path.</param>
        /// <returns>List of the files for deployment. <see cref="PackageFileDeploymentInfo"/></returns>
        protected IReadOnlyCollection <PackageFileDeploymentInfo> OnGetPackageFiles(PackageId packageId, string packagePath)
        {
            var files         = new List <PackageFileDeploymentInfo>();
            var toolsFolder   = Path.Combine(packagePath, "tools");
            var contentFolder = Path.Combine(packagePath, "content");
            var libFolder     = Path.Combine(packagePath, "lib");

            if (Directory.Exists(toolsFolder))
            {
                AddFiles(toolsFolder, _deploymentContext.ProductPath, FileAction.None, FileType.Tool, files);
            }

            if (Directory.Exists(contentFolder))
            {
                AddFiles(contentFolder, _deploymentContext.ProductPath, FileAction.Copy, FileType.Content, files);
            }

            if (Directory.Exists(libFolder))
            {
                var libFxFolder = Path.Combine(libFolder, _deploymentContext.TargetFramework);
                if (!Directory.Exists(libFxFolder))
                {
                    var fxName = NuGetEngine.GetMostCompatibleFramework(_deploymentContext.TargetFramework,
                                                                        Directory.EnumerateDirectories(libFolder).Select(Path.GetFileName));
                    if (fxName == null)
                    {
                        Console.WriteLine($"Skipping package {packageId.Id} because unkown framework present on PKG");
                        return(files);
                    }
                    libFxFolder = Path.Combine(libFolder, fxName);
                    if (!Directory.Exists(libFxFolder))
                    {
                        return(files);
                    }
                }

                AddFiles(libFxFolder, _deploymentContext.ProductPath, FileAction.Copy, FileType.LibFile, files);
            }

            return(files);
        }
Exemple #5
0
        protected virtual async Task OnResolvePackages()
        {
            MergeWithProductPackages();

            var resolvedPackages = await NuGetEngine.ResolvePackages(WorkflowContext.InputPackages);

            NuGetEngine.AnalysePackages(resolvedPackages);

            foreach (var innerNode in resolvedPackages.InnerNodes)
            {
                FlattenPackageNode(innerNode, null);
            }

            while (WorkflowContext.FlatteningCache.Any())
            {
                var nextNode = WorkflowContext.FlatteningCache.Dequeue();
                FlattenPackageNode(nextNode.Item1, nextNode.Item2);
            }

            PrepareInstallationAndDeletionLists();
        }
Exemple #6
0
        public DeploymentEngine(DeploymentContext deploymentContext,
                                IDeploymentStartegyProvider deploymentStartegyProvider, string packagesFolderPath,
                                List <string> remotePackagesSources, bool updatePackages, bool allowDowngrades)
        {
            DeploymentContext          = deploymentContext;
            DeploymentStartegyProvider = deploymentStartegyProvider;
            UpdatePackages             = updatePackages;
            AllowDowngrades            = allowDowngrades;

            if (string.IsNullOrWhiteSpace(packagesFolderPath))
            {
                PackagesFolderPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                DontCachePackages  = true;
            }
            else
            {
                PackagesFolderPath = packagesFolderPath;
            }


            NuGetEngine = new NuGetEngine(deploymentContext, PackagesFolderPath, remotePackagesSources, updatePackages,
                                          allowDowngrades);
        }
Exemple #7
0
        protected IEnumerable <PackageFileInfo> OnGetPackageFiles(PackageId packageId, string packagePath)
        {
            var files         = new List <PackageFileInfo>();
            var toolsFolder   = Path.Combine(packagePath, "tools");
            var contentFolder = Path.Combine(packagePath, "content");
            var libFolder     = Path.Combine(packagePath, "lib");

            if (Directory.Exists(toolsFolder))
            {
                AddFiles(toolsFolder, _deploymentContext.ProductPath, FileAction.None, FileType.Tool, files);
            }

            if (Directory.Exists(contentFolder))
            {
                AddFiles(contentFolder, _deploymentContext.ProductPath, FileAction.Copy, FileType.Content, files);
            }

            if (Directory.Exists(libFolder))
            {
                var libFxFolder = Path.Combine(libFolder, _deploymentContext.TargetFramework);
                if (!Directory.Exists(libFxFolder))
                {
                    var fxName = NuGetEngine.GetMostCompatibleFramework(_deploymentContext.TargetFramework,
                                                                        Directory.EnumerateDirectories(libFolder).Select(Path.GetFileName));
                    libFxFolder = Path.Combine(libFolder, fxName);
                    if (!Directory.Exists(libFxFolder))
                    {
                        return(files);
                    }
                }

                AddFiles(libFxFolder, _deploymentContext.ProductPath, FileAction.Copy, FileType.LibFile, files);
            }

            return(files);
        }
Exemple #8
0
 /// <summary>
 /// Allows to define a custom deployment workflow
 /// </summary>
 /// <param name="deploymentContext">Current deployment context</param>
 /// <param name="workflowContext">Workflow context to carry</param>
 /// <param name="nuGetEngine">Current NuGet engine</param>
 /// <returns>Custom deployment workflow</returns>
 protected virtual DeploymentWorkflow GetDeploymentWorkflow(DeploymentContext deploymentContext, WorkflowContext workflowContext, NuGetEngine nuGetEngine)
 {
     return(new DeploymentWorkflow(deploymentContext, workflowContext, nuGetEngine));
 }
Exemple #9
0
 public DeploymentWorkflow(DeploymentContext deploymentContext, WorkflowContext workflowContext, NuGetEngine nuGetEngine)
 {
     DeploymentContext = deploymentContext;
     WorkflowContext   = workflowContext;
     NuGetEngine       = nuGetEngine;
 }