public int ExcludeAssemblyTest(string exceptions, string wildcards) { var mockRepo = CreateMockRepository(); var stringMatches = !string.IsNullOrEmpty(exceptions) ? exceptions.Split(';').ToList() : new List <string>(); var regii = !string.IsNullOrEmpty(wildcards) ? wildcards.Split(';').Select(w => new Wildcard(w.ToLowerInvariant())).ToList() : new List <Wildcard>(); var auditor = new FeedAuditor(mockRepo, new List <String>(), new List <Regex>(), true, false, false, stringMatches, regii); var results = auditor.Audit(); return(results.SelectMany(r => r.UnresolvableReferences).Count()); }
public int ExcludePackageTest(string exceptions, string wildcards) { var mockRepo = CreateMockRepository(); var stringMatches = !string.IsNullOrEmpty(exceptions) ? exceptions.Split(';').ToList() : new List <string>(); var regii = !string.IsNullOrEmpty(wildcards) ? wildcards.Split(';').Select(w => new Wildcard(w.ToLowerInvariant())).ToList() : new List <Wildcard>(); var auditor = new FeedAuditor(mockRepo, stringMatches, regii, true, false, false, new List <String>(), new List <Regex>()); var ignoredCount = 0; auditor.PackageIgnored += (o, e) => ignoredCount++; auditor.Audit(); return(ignoredCount); }
public override void ExecuteCommand() { var excludedPackageIds = GetLowerInvariantExclusions(PackageExceptions); var excludedPackageWildcards = String.IsNullOrEmpty(PackageExceptions) ? new List <Regex>() : GetExcludedWildcards(PackageExceptions); var excludedAssembliesIds = GetLowerInvariantExclusions(AssemblyExceptions); var excludedAssemblyWildcards = String.IsNullOrEmpty(AssemblyExceptions) ? new List <Regex>() : GetExcludedWildcards(AssemblyExceptions); var repository = GetRepository(); var feedAuditor = new FeedAuditor(repository, excludedPackageIds, excludedPackageWildcards, Unlisted, CheckFeedForUnresolvedAssemblies, Gac, excludedAssembliesIds, excludedAssemblyWildcards); feedAuditor.StartPackageAudit += (o, e) => Console.WriteLine("Starting audit of package: {0}", e.Package.Id); feedAuditor.StartPackageListDownload += (o, e) => Console.WriteLine("Downloading package list..."); feedAuditor.FinishedPackageListDownload += (o, e) => Console.WriteLine("Finished downloading package list..."); feedAuditor.PackageIgnored += (o, e) => Console.WriteLine("Ignoring package: {0} based on {1}", e.IgnoredPackage.Id, e.Wildcard ? "wildcard..." : "string match..."); var results = RunAuditAndReturnResults(repository, feedAuditor); var auditFlags = GetAuditFlags(AllOutput, RunTimeFailOnly, CheckFeedForUnresolvedAssemblies, Gac, UnresolvableOnly); var outputer = new FeedAuditResultsOutputManager(results, auditFlags); outputer.Output(string.IsNullOrEmpty(Output) ? System.Console.Out : new StreamWriter(Path.GetFullPath(Output))); var unresolvableReferences = results.SelectMany(r => r.UnresolvableReferences).Distinct().ToList(); if (CheckFeedForUnresolvedAssemblies && unresolvableReferences.Count > 0) { var writer = !String.IsNullOrEmpty(UnresolvedOutput) ? new StreamWriter(Path.GetFullPath(UnresolvedOutput)) : System.Console.Out; writer.WriteLine("Following references are unresolvable:"); writer.WriteLine(); foreach (var assembly in unresolvableReferences) { writer.WriteLine("\t{0}", assembly.FullName); } writer.Close(); } if (RunTimeFailOnly && PossibleRuntimeFailuresExist(results)) { throw new CommandLineException("There were possible runtime failures, please check audit report"); } if (UnresolvableOnly && unresolvableReferences.Any()) { throw new CommandLineException("There were unresolvable reference failures, please check audit report"); } if (AnyPossibleFailuresExist(results)) { throw new CommandLineException("There were audit failures, please check audit report"); } }
private List <PackageAuditResult> RunAuditAndReturnResults(IPackageRepository repository, FeedAuditor feedAuditor) { List <PackageAuditResult> results = null; if (String.IsNullOrEmpty(Package)) { results = feedAuditor.Audit(); } else { var actualPackage = File.Exists(Package) ? new ZipPackage(Package) : repository.FindPackagesById(Package).FirstOrDefault(); if (actualPackage != null) { results = feedAuditor.Audit(actualPackage); } else { throw new ApplicationException(string.Format("Could not find package locally or on feed: {0}", Package)); } } return(results); }