/// <summary> /// detects issues and prints them to the log. use filterPackages if its wanted to filter the issues based on newly installed packages. /// </summary> public static Issue CheckInstalledPackages(string installDir) { var packages = new Installation(installDir).GetPackages(); var tree = DependencyAnalyzer.BuildAnalyzerContext(packages.ToList()); if (tree.BrokenPackages.Count == 0) { return(Issue.None); } log.Error("Package Dependency Warning"); foreach (var pkg in tree.BrokenPackages) { log.Warning("The Package '{0}' has the following dependency issues:", pkg.Name); foreach (var issue in tree.GetIssues(pkg)) { switch (issue.IssueType) { case DependencyIssueType.Missing: log.Info(" * The package depends on '{0}' (v{1}) which is not installed.", issue.PackageName, issue.ExpectedVersion); break; case DependencyIssueType.DependencyMissing: log.Info(" * The package depends on '{0} which has issues.", issue.PackageName); log.Info(" See message related to other packages."); break; case DependencyIssueType.IncompatibleVersion: log.Info(" * The package depends on '{0}' version '{1}', but '{2}' was installed.", issue.PackageName, issue.ExpectedVersion, issue.LoadedVersion); break; } } } return(Issue.BrokenPackages); }
protected override int LockedExecute(CancellationToken cancellationToken) { if (OS == null) { switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: OS = "OSX"; break; case PlatformID.Unix: OS = "Linux"; break; default: OS = "Windows"; break; } } List <IPackageRepository> repositories = new List <IPackageRepository>(); if (Installed == false) { if (Repository == null) { repositories.AddRange(PackageManagerSettings.Current.Repositories.Where(p => p.IsEnabled).Select(s => s.Manager)); } else { repositories.AddRange(Repository.Select(s => PackageRepositoryHelpers.DetermineRepositoryType(s))); } } if (Target == null) { Target = FileSystemHelper.GetCurrentInstallationDirectory(); } HashSet <PackageDef> installed = new Installation(Target).GetPackages().ToHashSet(); VersionSpecifier versionSpec = VersionSpecifier.Parse("^"); if (!String.IsNullOrWhiteSpace(Version)) { versionSpec = VersionSpecifier.Parse(Version); } if (string.IsNullOrEmpty(Name)) { var packages = installed.ToList(); packages.AddRange(PackageRepositoryHelpers.GetPackageNameAndVersionFromAllRepos(repositories, new PackageSpecifier("", versionSpec, Architecture, OS))); if (Installed) { packages = packages.Where(p => installed.Any(i => i.Name == p.Name)).ToList(); } PrintReadable(packages, installed); } else { IPackageIdentifier package = installed.FirstOrDefault(p => p.Name == Name); if (Installed) { if (package is null) { log.Info($"{Name} is not installed"); return(-1); } log.Info(package.Version.ToString()); return(0); } List <PackageVersion> versions = null; if (All) { versions = PackageRepositoryHelpers.GetAllVersionsFromAllRepos(repositories, Name).Distinct().ToList(); var versionsCount = versions.Count; if (versionsCount == 0) // No versions { log.Info($"No versions of '{Name}'."); return(0); } if (Version != null) // Version is specified by user { versions = versions.Where(v => versionSpec.IsCompatible(v.Version)).ToList(); } if (versions.Any() == false && versionsCount > 0) { log.Info($"Package '{Name}' does not exists with version '{Version}'."); log.Info($"Package '{Name}' exists in {versionsCount} other versions, please specify a different version."); return(0); } } else { var opentap = new Installation(Target).GetOpenTapPackage(); versions = PackageRepositoryHelpers.GetAllVersionsFromAllRepos(repositories, Name, opentap).Distinct().ToList(); versions = versions.Where(s => s.IsPlatformCompatible(Architecture, OS)).ToList(); if (versions.Any() == false) // No compatible versions { versions = PackageRepositoryHelpers.GetAllVersionsFromAllRepos(repositories, Name).ToList(); if (versions.Any()) { log.Warning($"There are no compatible versions of '{Name}'."); log.Info($"There are {versions.Count} incompatible versions available. Use '--all' to show these."); } else { log.Warning($"Package '{Name}' could not be found in any repository."); } return(0); } versions = versions.Where(v => versionSpec.IsCompatible(v.Version)).ToList(); if (versions.Any() == false) // No versions that are compatible { if (string.IsNullOrEmpty(Version)) { log.Warning($"There are no released versions of '{Name}'."); } else { log.Warning($"Package '{Name}' does not exists with version '{Version}'."); } var anyPrereleaseSpecifier = new VersionSpecifier(versionSpec.Major, versionSpec.Minor, versionSpec.Patch, versionSpec.PreRelease, versionSpec.BuildMetadata, VersionMatchBehavior.AnyPrerelease | versionSpec.MatchBehavior); versions = versions.Where(v => anyPrereleaseSpecifier.IsCompatible(v.Version)).ToList(); if (versions.Any()) { log.Info($"There are {versions.Count} pre-released versions available. Use '--version <pre-release>' (e.g. '--version rc') or '--all' to show these."); } return(0); } } PrintVersionsReadable(package, versions); } return(0); }