Example #1
0
        public void ReverseDependencyWalkerUsersVersionAndIdToDetermineVisited()
        {
            // Arrange
            // A 1.0 -> B 1.0
            IPackage packageA1 = PackageUtility.CreatePackage("A",
                                                            "1.0",
                                                             dependencies: new List<PackageDependency> {
                                                                 PackageDependency.CreateDependency("B", "[1.0]")
                                                             });
            // A 2.0 -> B 2.0
            IPackage packageA2 = PackageUtility.CreatePackage("A",
                                                            "2.0",
                                                             dependencies: new List<PackageDependency> {
                                                                 PackageDependency.CreateDependency("B", "[2.0]")
                                                             });

            IPackage packageB1 = PackageUtility.CreatePackage("B", "1.0");
            IPackage packageB2 = PackageUtility.CreatePackage("B", "2.0");

            var mockRepository = new MockPackageRepository();
            mockRepository.AddPackage(packageA1);
            mockRepository.AddPackage(packageA2);
            mockRepository.AddPackage(packageB1);
            mockRepository.AddPackage(packageB2);

            // Act 
            IDependentsResolver lookup = new DependentsWalker(mockRepository);

            // Assert
            Assert.Equal(0, lookup.GetDependents(packageA1).Count());
            Assert.Equal(0, lookup.GetDependents(packageA2).Count());
            Assert.Equal(1, lookup.GetDependents(packageB1).Count());
            Assert.Equal(1, lookup.GetDependents(packageB2).Count());
        }
Example #2
0
        private IEnumerable <PackageOperation> ResolveOperationsToInstallProjectLevelPackage(Operation operation)
        {
            var projectRepo      = _virtualProjectRepos[operation.ProjectManager];
            var dependentsWalker = new DependentsWalker(
                operation.ProjectManager.PackageManager.LocalRepository,
                operation.ProjectManager.GetTargetFrameworkForPackage(operation.Package.Id))
            {
                DependencyVersion = DependencyVersion
            };
            var updateWalker = new UpdateWalker(
                projectRepo,
                operation.ProjectManager.PackageManager.DependencyResolver,
                dependentsWalker,
                operation.ProjectManager.ConstraintProvider,
                operation.ProjectManager.Project.TargetFramework,
                Logger ?? NullLogger.Instance,
                !IgnoreDependencies,
                AllowPrereleaseVersions)
            {
                AcceptedTargets   = PackageTargets.All,
                DependencyVersion = DependencyVersion
            };

            var operations = updateWalker.ResolveOperations(operation.Package);

            return(operations);
        }
Example #3
0
        public void ReverseDependencyWalkerUsersVersionAndIdToDetermineVisited()
        {
            // Arrange
            // A 1.0 -> B 1.0
            IPackage packageA1 = PackageUtility.CreatePackage("A",
                                                              "1.0",
                                                              dependencies: new List <PackageDependency> {
                PackageDependency.CreateDependency("B", "[1.0]")
            });
            // A 2.0 -> B 2.0
            IPackage packageA2 = PackageUtility.CreatePackage("A",
                                                              "2.0",
                                                              dependencies: new List <PackageDependency> {
                PackageDependency.CreateDependency("B", "[2.0]")
            });

            IPackage packageB1 = PackageUtility.CreatePackage("B", "1.0");
            IPackage packageB2 = PackageUtility.CreatePackage("B", "2.0");

            var mockRepository = new MockPackageRepository();

            mockRepository.AddPackage(packageA1);
            mockRepository.AddPackage(packageA2);
            mockRepository.AddPackage(packageB1);
            mockRepository.AddPackage(packageB2);

            // Act
            IDependentsResolver lookup = new DependentsWalker(mockRepository);

            // Assert
            Assert.AreEqual(0, lookup.GetDependents(packageA1).Count());
            Assert.AreEqual(0, lookup.GetDependents(packageA2).Count());
            Assert.AreEqual(1, lookup.GetDependents(packageB1).Count());
            Assert.AreEqual(1, lookup.GetDependents(packageB2).Count());
        }
Example #4
0
        private IEnumerable <PackageOperation> ResolveOperationsToInstallProjectLevelPackage(Operation operation)
        {
            DependentsWalker walker1 = new DependentsWalker(operation.ProjectManager.PackageManager.LocalRepository, operation.ProjectManager.GetTargetFrameworkForPackage(operation.Package.Id));

            walker1.DependencyVersion = this.DependencyVersion;
            DependentsWalker dependentsResolver = walker1;
            UpdateWalker     walker2            = new UpdateWalker(this._virtualProjectRepos[operation.ProjectManager], operation.ProjectManager.PackageManager.DependencyResolver, dependentsResolver, operation.ProjectManager.ConstraintProvider, operation.ProjectManager.Project.TargetFramework, this.Logger ?? NullLogger.Instance, !this.IgnoreDependencies, this.AllowPrereleaseVersions);

            walker2.AcceptedTargets   = PackageTargets.All;
            walker2.DependencyVersion = this.DependencyVersion;
            return(walker2.ResolveOperations(operation.Package));
        }
Example #5
0
        private IEnumerable <PackageOperation> ResolveOperationsToUpdateSolutionLevelPackage(Operation operation)
        {
            VirtualRepository repository         = this._virtualPackageRepos[operation.ProjectManager.PackageManager];
            DependentsWalker  dependentsResolver = new DependentsWalker(repository, null);

            dependentsResolver.DependencyVersion = this.DependencyVersion;
            UpdateWalker walker2 = new UpdateWalker(repository, operation.ProjectManager.PackageManager.DependencyResolver, dependentsResolver, NullConstraintProvider.Instance, null, this.Logger ?? NullLogger.Instance, !this.IgnoreDependencies, this.AllowPrereleaseVersions);

            walker2.AcceptedTargets   = PackageTargets.All;
            walker2.DependencyVersion = this.DependencyVersion;
            IEnumerable <PackageOperation> enumerable = walker2.ResolveOperations(operation.Package);

            using (IEnumerator <PackageOperation> enumerator = enumerable.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    enumerator.Current.Target = PackageOperationTarget.PackagesFolder;
                }
            }
            return(enumerable);
        }
Example #6
0
        public void UninstallPackage(IPackageDetails package)
        {
            Argument.IsNotNull(() => package);
            Argument.IsOfType(() => package, typeof(PackageDetails));

            var dependentsResolver = new DependentsWalker(_localRepository, null);

            var walker = new UninstallWalker(_localRepository, dependentsResolver, null,
                                             _logger, true, false);

            try
            {
                var nuGetPackage = ((PackageDetails)package).Package;
                walker.ResolveOperations(nuGetPackage);
                _packageManager.UninstallPackage(nuGetPackage, false, true);
            }
            catch (Exception exception)
            {
                _logger.Log(MessageLevel.Error, exception.Message);
                _packageOperationContextService.CurrentContext.CatchedExceptions.Add(exception);
            }
        }
Example #7
0
        protected void CheckDependentPackages(
            IPackage package,
            IPackageRepository localRepository,
            FrameworkName targetFramework)
        {
            // check if there is any other package depends on this package.
            // if there is, throw to cancel the uninstallation
            var dependentsWalker        = new DependentsWalker(localRepository, targetFramework);
            IList <IPackage> dependents = dependentsWalker.GetDependents(package).ToList();

            if (dependents.Count > 0)
            {
                ShowProgressWindow();
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Resources.PackageHasDependents,
                              package.GetFullName(),
                              String.Join(", ", dependents.Select(d => d.GetFullName()))
                              )
                          );
            }
        }
 protected void CheckDependentPackages(
     IPackage package,
     IPackageRepository localRepository,
     FrameworkName targetFramework)
 {
     // check if there is any other package depends on this package.
     // if there is, throw to cancel the uninstallation
     var dependentsWalker = new DependentsWalker(localRepository, targetFramework);
     IList<IPackage> dependents = dependentsWalker.GetDependents(package).ToList();
     if (dependents.Count > 0)
     {
         ShowProgressWindow();
         throw new InvalidOperationException(
             String.Format(
                 CultureInfo.CurrentCulture,
                 Resources.PackageHasDependents,
                 package.GetFullName(),
                 String.Join(", ", dependents.Select(d => d.GetFullName()))
             )
         );
     }
 }
Example #9
0
        private IEnumerable<PackageOperation> ResolveOperationsToInstallProjectLevelPackage(Operation operation)
        {
            var projectRepo = _virtualProjectRepos[operation.ProjectManager];
            var dependentsWalker = new DependentsWalker(
                operation.ProjectManager.PackageManager.LocalRepository,
                operation.ProjectManager.GetTargetFrameworkForPackage(operation.Package.Id))
            {
                DependencyVersion = DependencyVersion
            };
            var updateWalker = new UpdateWalker(
                projectRepo,
                operation.ProjectManager.PackageManager.DependencyResolver,
                dependentsWalker,
                operation.ProjectManager.ConstraintProvider,
                operation.ProjectManager.Project.TargetFramework,
                Logger ?? NullLogger.Instance,
                !IgnoreDependencies,
                AllowPrereleaseVersions)
            {
                AcceptedTargets = PackageTargets.All,
                DependencyVersion = DependencyVersion
            };

            var operations = updateWalker.ResolveOperations(operation.Package);
            return operations;
        }
Example #10
0
        protected bool? AskRemoveDependencyAndCheckUninstallPSScript(IPackage package, bool checkDependents)
        {
            if (checkDependents)
            {
                // check if there is any other package depends on this package.
                // if there is, throw to cancel the uninstallation
                var dependentsWalker = new DependentsWalker(LocalRepository);
                IList<IPackage> dependents = dependentsWalker.GetDependents(package).ToList();
                if (dependents.Count > 0)
                {
                    ShowProgressWindow();
                    throw new InvalidOperationException(
                        String.Format(
                            CultureInfo.CurrentCulture,
                            Resources.PackageHasDependents,
                            package.GetFullName(),
                            String.Join(", ", dependents.Select(d => d.GetFullName()))
                        )
                    );
                }
            }

            var uninstallWalker = new UninstallWalker(
                LocalRepository,
                new DependentsWalker(LocalRepository),
                logger: NullLogger.Instance,
                removeDependencies: true,
                forceRemove: false)
                {
                    ThrowOnConflicts = false
                };
            IList<PackageOperation> operations = uninstallWalker.ResolveOperations(package).ToList();

            var uninstallPackageNames = (from o in operations
                                         where o.Action == PackageAction.Uninstall && !PackageEqualityComparer.IdAndVersion.Equals(o.Package, package)
                                         select o.Package.ToString()).ToList();

            bool? removeDependencies = false;
            if (uninstallPackageNames.Count > 0)
            {
                // show each dependency package on one line
                String packageNames = String.Join(Environment.NewLine, uninstallPackageNames);
                String message = String.Format(CultureInfo.CurrentCulture, Resources.Dialog_RemoveDependencyMessage, package)
                        + Environment.NewLine
                        + Environment.NewLine
                        + packageNames;

                removeDependencies = _userNotifierServices.ShowRemoveDependenciesWindow(message);
            }
            if (removeDependencies == null)
            {
                return removeDependencies;
            }

            bool hasScriptPackages;
            if (removeDependencies == true)
            {
                // if user wants to remove dependencies, we need to check all of them for PS scripts
                var scriptPackages = from o in operations
                                     where o.Package.HasPowerShellScript()
                                     select o.Package;
                hasScriptPackages = scriptPackages.Any();
            }
            else
            {
                // otherwise, just check the to-be-uninstalled package
                hasScriptPackages = package.HasPowerShellScript(new string[] { PowerShellScripts.Uninstall });
            }

            if (hasScriptPackages)
            {
                if (!RegistryHelper.CheckIfPowerShell2Installed())
                {
                    throw new InvalidOperationException(Resources.Dialog_PackageHasPSScript);
                }
            }

            return removeDependencies;
        }