Ejemplo n.º 1
0
        public async Task <int> OnExecute(CommandLineApplication app, IConsole console)
        {
            try
            {
                // If no path is set, use the current directory
                if (string.IsNullOrEmpty(Path))
                {
                    Path = _fileSystem.Directory.GetCurrentDirectory();
                }

                // Get all the projects
                console.Write("Discovering projects...");

                string projectPath = _projectDiscoveryService.DiscoverProject(Path);

                if (!console.IsOutputRedirected)
                {
                    ClearCurrentConsoleLine();
                }
                else
                {
                    console.WriteLine();
                }

                // Analyze the projects
                console.Write("Analyzing project and restoring packages...");

                var projects = _projectAnalysisService.AnalyzeProject(projectPath, Transitive, TransitiveDepth);

                if (!console.IsOutputRedirected)
                {
                    ClearCurrentConsoleLine();
                }
                else
                {
                    console.WriteLine();
                }

                // Analyze the dependencies
                await AnalyzeDependencies(projects, console);

                // Report on the outdated dependencies
                ReportOutdatedDependencies(projects, console);

                // Upgrade the packages
                await UpgradePackages(projects, console);

                return(0);
            }
            catch (CommandValidationException e)
            {
                _reporter.Error(e.Message);

                return(1);
            }
        }
Ejemplo n.º 2
0
        public async Task <int> OnExecute(CommandLineApplication app, IConsole console)
        {
            try
            {
                // If no path is set, use the current directory
                if (string.IsNullOrEmpty(Path))
                {
                    Path = _fileSystem.Directory.GetCurrentDirectory();
                }

                // Get all the projects
                string projectPath = _projectDiscoveryService.DiscoverProject(Path);

                // Analyze the projects
                var projects = _projectAnalysisService.AnalyzeProject(projectPath);

                foreach (var project in projects)
                {
                    int indentLevel = 1;

                    WriteProjectName(console, project);

                    // Increase indent if we have dependencies at project level
                    if (project.Dependencies.Any())
                    {
                        indentLevel++;
                    }

                    // Process each target framework with its related dependencies
                    foreach (var targetFramework in project.TargetFrameworks)
                    {
                        WriteTargetFramework(console, targetFramework, indentLevel);

                        foreach (var dependency in targetFramework.Dependencies)
                        {
                            await ReportDependency(console, dependency.Name, dependency.VersionRange, project.Sources, indentLevel, targetFramework);
                        }
                    }

                    console.WriteLine();
                }

                return(0);
            }
            catch (CommandValidationException e)
            {
                _reporter.Error(e.Message);

                return(1);
            }
        }
Ejemplo n.º 3
0
        public async Task <int> OnExecute(CommandLineApplication app, IConsole console)
        {
            try
            {
                // If no path is set, use the current directory
                if (string.IsNullOrEmpty(Path))
                {
                    Path = _fileSystem.Directory.GetCurrentDirectory();
                }

                // Get all the projects
                string projectPath = _projectDiscoveryService.DiscoverProject(Path);

                // Analyze the projects
                var projects = _projectAnalysisService.AnalyzeProject(projectPath);

                foreach (var project in projects)
                {
                    WriteProjectName(console, project);

                    foreach (var dependency in project.Dependencies)
                    {
                        await ReportDependency(console, dependency, 1);
                    }

                    foreach (var targetFramework in project.TargetFrameworks)
                    {
                        WriteTargetFramework(console, targetFramework);

                        foreach (var dependency in targetFramework.Dependencies)
                        {
                            await ReportDependency(console, dependency, 2);
                        }
                    }

                    console.WriteLine();
                }

                return(0);
            }
            catch (CommandValidationException e)
            {
                _reporter.Error(e.Message);

                return(1);
            }
        }
Ejemplo n.º 4
0
        public async Task <int> OnExecute(CommandLineApplication app, IConsole console)
        {
            string path           = _fileSystem.Directory.GetCurrentDirectory();
            string configFilePath = Path.Combine(path, ".depguard.json");

            if (!File.Exists(configFilePath))
            {
                console.WriteLine("Configuration file .depguard.json does not exist");
                return(-1);
            }

            string configText = await File.ReadAllTextAsync(configFilePath);

            Config config = JsonConvert.DeserializeObject <Config>(configText);

            if (!config.Packages.Any())
            {
                console.WriteLine("No blacklisted packages configured, nothing to do");
                return(0);
            }

            _blacklistedDependencies = config.Packages.ToDictionary(k => k.ToLowerInvariant());

            string projectPath = _projectDiscoveryService.DiscoverProject(path);
            var    projects    = _projectAnalysisService.AnalyzeProject(projectPath, true, 1);

            var matchedProjects = AnalyzeDependencies(projects, console);

            if (matchedProjects.Any())
            {
                ReportDependencies(matchedProjects, console);
                return(1);
            }
            else
            {
                console.WriteLine("No blacklisted dependencies were detected");
            }

            return(0);
        }
Ejemplo n.º 5
0
        public async Task <int> OnExecute(CommandLineApplication app, IConsole console)
        {
            try
            {
                // If no path is set, use the current directory
                if (string.IsNullOrEmpty(Path))
                {
                    Path = _fileSystem.Directory.GetCurrentDirectory();
                }

                // Get all the projects
                if (!console.IsOutputRedirected)
                {
                    console.Write("Discovering projects...");
                }

                string projectPath = _projectDiscoveryService.DiscoverProject(Path);

                if (!console.IsOutputRedirected)
                {
                    ClearCurrentConsoleLine();
                }

                // Analyze the projects
                if (!console.IsOutputRedirected)
                {
                    console.Write("Analyzing project and restoring packages...");
                }

                var projects = _projectAnalysisService.AnalyzeProject(projectPath, Transitive, TransitiveDepth);

                if (!console.IsOutputRedirected)
                {
                    ClearCurrentConsoleLine();
                }

                foreach (var project in projects)
                {
                    int indentLevel = 1;

                    WriteProjectName(console, project);

                    // Process each target framework with its related dependencies
                    foreach (var targetFramework in project.TargetFrameworks)
                    {
                        WriteTargetFramework(console, targetFramework, indentLevel);

                        var dependencies = targetFramework.Dependencies;

                        if (!IncludeAutoReferences)
                        {
                            dependencies = dependencies.Where(d => d.AutoReferenced == false).ToList();
                        }

                        if (dependencies.Count > 0)
                        {
                            foreach (var dependency in dependencies)
                            {
                                await ReportDependency(console, dependency, dependency.VersionRange, project.Sources, indentLevel, targetFramework, project.FilePath);
                            }
                        }
                        else
                        {
                            console.WriteIndent(indentLevel);
                            console.WriteLine("-- No dependencies --");
                        }
                    }

                    console.WriteLine();
                }

                return(0);
            }
            catch (CommandValidationException e)
            {
                _reporter.Error(e.Message);

                return(1);
            }
        }