public List <IInspector> CreateInspectors(InspectionOptions options, NugetSearchService nugetService) { var inspectors = new List <IInspector>(); if (Directory.Exists(options.TargetPath)) { Console.WriteLine("Searching for solution files to process..."); string[] solutionPaths = Directory.GetFiles(options.TargetPath, "*.sln"); if (solutionPaths != null && solutionPaths.Length >= 1) { foreach (var solution in solutionPaths) { Console.WriteLine("Found Solution {0}", solution); var solutionOp = new SolutionInspectionOptions(options); solutionOp.TargetPath = solution; inspectors.Add(new SolutionInspector(solutionOp, nugetService)); } } else { Console.WriteLine("No Solution file found. Searching for a project file..."); string[] projectPaths = SupportedProjectPatterns.SelectMany(pattern => Directory.GetFiles(options.TargetPath, pattern)).Distinct().ToArray(); if (projectPaths != null && projectPaths.Length > 0) { foreach (var projectPath in projectPaths) { Console.WriteLine("Found project {0}", projectPath); var projectOp = new ProjectInspectionOptions(options); projectOp.TargetPath = projectPath; inspectors.Add(new ProjectInspector(projectOp, nugetService)); } } else { Console.WriteLine("No Project file found. Finished."); } } } else if (File.Exists(options.TargetPath)) { if (options.TargetPath.Contains(".sln")) { var solutionOp = new SolutionInspectionOptions(options); solutionOp.TargetPath = options.TargetPath; inspectors.Add(new SolutionInspector(solutionOp, nugetService)); } else { var projectOp = new ProjectInspectionOptions(options); projectOp.TargetPath = options.TargetPath; inspectors.Add(new ProjectInspector(projectOp, nugetService)); } } return(inspectors); }
public ProjectInspectionOptions(InspectionOptions old) { this.TargetPath = old.TargetPath; this.Verbose = old.Verbose; this.PackagesRepoUrl = old.PackagesRepoUrl; this.OutputDirectory = old.OutputDirectory; this.ExcludedModules = old.ExcludedModules; this.IncludedModules = old.IncludedModules; this.IgnoreFailure = old.IgnoreFailure; }
public List <InspectionResult> Inspect(InspectionOptions options, NugetSearchService nugetService) { return(CreateInspectors(options, nugetService)?.Select(insp => insp.Inspect()).ToList()); }
public List<InspectionResult> Execute(string[] args) { RunOptions options = ParseArguments(args); if (options == null) return null; if (!string.IsNullOrWhiteSpace(options.AppSettingsFile)) { RunOptions appOptions = LoadAppSettings(options.AppSettingsFile); options.Override(appOptions); } if (string.IsNullOrWhiteSpace(options.TargetPath)) { options.TargetPath = Directory.GetCurrentDirectory(); } InspectionOptions opts = new InspectionOptions() { ExcludedModules = options.ExcludedModules, IncludedModules = options.IncludedModules, IgnoreFailure = options.IgnoreFailures == "true", OutputDirectory = options.OutputDirectory, PackagesRepoUrl = options.PackagesRepoUrl, NugetConfigPath = options.NugetConfigPath, TargetPath = options.TargetPath, Verbose = options.Verbose }; var searchService = new NugetSearchService(options.PackagesRepoUrl, options.NugetConfigPath); var inspectionResults = Dispatch.Inspect(opts, searchService); if (inspectionResults != null) { foreach (var result in inspectionResults) { try { if (result.ResultName != null) { Console.WriteLine("Inspection: " + result.ResultName); } if (result.Status == InspectionResult.ResultStatus.Success) { Console.WriteLine("Inspection Result: Success"); var writer = new InspectionResultJsonWriter(result); writer.Write(); Console.WriteLine("Info file created at {0}", writer.FilePath()); } else { Console.WriteLine("Inspection Result: Error"); if (result.Exception != null) { Console.WriteLine("Exception:"); Console.WriteLine(result.Exception); } } } catch (Exception e) { Console.WriteLine("Error processing inspection result."); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } } } if (inspectionResults.Where(result => result.Status == InspectionResult.ResultStatus.Error).Any()) { inspectionResults.Where(result => result.Status == InspectionResult.ResultStatus.Error) .Select(result => { if (result.Exception != null) return result.Exception.ToString(); else return result.ResultName + " encountered an unknown issue."; }).ToList().ForEach(Console.Error.Write); Console.Error.Write("One or more inspection results failed."); if (options.IgnoreFailures == "true") { Console.Error.Write("Ignoring failures, not exiting -1."); } else { Environment.Exit(-1); } } return inspectionResults; }