コード例 #1
0
        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.AsList.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 ProjectInspector(ProjectInspectionOptions options, NugetSearchService nugetService)
        {
            Options      = options;
            NugetService = nugetService;
            if (Options == null)
            {
                throw new Exception("Must provide a valid options object.");
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectDirectory))
            {
                Options.ProjectDirectory = Directory.GetParent(Options.TargetPath).FullName;
            }

            if (String.IsNullOrWhiteSpace(Options.PackagesConfigPath))
            {
                Options.PackagesConfigPath = CreateProjectPackageConfigPath(Options.ProjectDirectory);
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectJsonPath))
            {
                Options.ProjectJsonPath = CreateProjectJsonPath(Options.ProjectDirectory);
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectJsonLockPath))
            {
                Options.ProjectJsonLockPath = CreateProjectJsonLockPath(Options.ProjectDirectory);
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectAssetsJsonPath))
            {
                Options.ProjectAssetsJsonPath = CreateProjectAssetsJsonPath(Options.ProjectDirectory);
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectName))
            {
                Options.ProjectName = Path.GetFileNameWithoutExtension(Options.TargetPath);
            }

            if (String.IsNullOrWhiteSpace(Options.ProjectUniqueId))
            {
                Options.ProjectUniqueId = Path.GetFileNameWithoutExtension(Options.TargetPath);
            }

            if (String.IsNullOrWhiteSpace(Options.VersionName))
            {
                Options.VersionName = InspectorUtil.GetProjectAssemblyVersion(Options.ProjectDirectory);
            }
        }
コード例 #3
0
        public SolutionInspector(SolutionInspectionOptions options, NugetSearchService nugetService)
        {
            Options      = options;
            NugetService = nugetService;
            if (Options == null)
            {
                throw new Exception("Must provide a valid options object.");
            }

            if (String.IsNullOrWhiteSpace(Options.OutputDirectory))
            {
                string currentDirectory = Directory.GetCurrentDirectory();
                Options.OutputDirectory = PathUtil.Combine(currentDirectory, InspectorUtil.DEFAULT_OUTPUT_DIRECTORY);
            }
            if (String.IsNullOrWhiteSpace(Options.SolutionName))
            {
                Options.SolutionName = Path.GetFileNameWithoutExtension(Options.TargetPath);
            }
        }
コード例 #4
0
 public PackagesConfigResolver(string packagesConfigPath, NugetSearchService nugetSearchService)
 {
     PackagesConfigPath = packagesConfigPath;
     NugetSearchService = nugetSearchService;
 }
コード例 #5
0
 public List <InspectionResult> Inspect(InspectionOptions options, NugetSearchService nugetService)
 {
     return(CreateInspectors(options, nugetService)?.Select(insp => insp.Inspect()).ToList());
 }
 public ProjectReferenceResolver(string projectPath, NugetSearchService nugetSearchService)
 {
     ProjectPath        = projectPath;
     NugetSearchService = nugetSearchService;
 }
        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;
        }
コード例 #8
0
        static ExecutionResult ExecuteInspectors(InspectionOptions options)
        {
            bool anyFailed = false;

            try
            {
                var dispatch          = new InspectorDispatch();
                var searchService     = new NugetSearchService(options.PackagesRepoUrl, options.NugetConfigPath);
                var inspectionResults = dispatch.Inspect(options, 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);
                                    anyFailed = true;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error processing inspection result.");
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.StackTrace);
                            anyFailed = true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error iterating inspection results.");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                anyFailed = true;
            }

            if (anyFailed)
            {
                return(ExecutionResult.Failed());
            }
            else
            {
                return(ExecutionResult.Succeeded());
            }
        }