コード例 #1
0
        public Methods(PackageOptions packageOptions)
        {
            if (_httpClient is null)
            {
                var httpClientHandler = new HttpClientHandler
                {
                    AllowAutoRedirect        = true,
                    MaxAutomaticRedirections = maxRedirects
                };

                if (!string.IsNullOrWhiteSpace(packageOptions.Proxy))
                {
                    httpClientHandler.Proxy = new WebProxy(new Uri(packageOptions.Proxy));
                }

                if (packageOptions.IgnoreSslCertificateErrors)
                {
                    httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => IgnoreSslCertificateErrorCallback(message, cert, chain, sslPolicyErrors);
                }

                _httpClient = new HttpClient(httpClientHandler)
                {
                    BaseAddress = new Uri(nugetUrl),
                    Timeout     = TimeSpan.FromSeconds(timeout)
                };
            }

            _serializer      = new XmlSerializer(typeof(Package));
            _packageOptions  = packageOptions;
            _licenseMappings = packageOptions.LicenseToUrlMappingsDictionary;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: MKuckert/nuget-license
        private static async Task <int> Execute(PackageOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.ProjectDirectory))
            {
                Console.WriteLine("ERROR(S):");
                Console.WriteLine("-i\tInput the Directory Path (csproj file)");

                return(1);
            }

            Methods methods = new Methods(options);
            var     projectsWithPackages = await methods.GetPackages();

            HandleInvalidLicenses(methods, projectsWithPackages, options.AllowedLicenseType);
            var mappedLibraryInfo = methods.MapPackagesToLibraryInfo(projectsWithPackages);

            if (options.Print == true)
            {
                Console.WriteLine();
                Console.WriteLine("Project Reference(s) Analysis...");
                methods.PrintLicenses(mappedLibraryInfo);
            }

            if (options.JsonOutput)
            {
                methods.SaveAsJson(mappedLibraryInfo);
            }
            else
            {
                methods.SaveAsTextFile(mappedLibraryInfo);
            }

            return(0);
        }
コード例 #3
0
ファイル: Methods.cs プロジェクト: rafntor/nuget-license
        public Methods(PackageOptions packageOptions)
        {
            if (_httpClient is null)
            {
                _httpClient = new HttpClient
                {
                    BaseAddress = new Uri(nugetUrl),
                    Timeout     = TimeSpan.FromSeconds(10)
                };
            }

            _serializer      = new XmlSerializer(typeof(Package));
            _packageOptions  = packageOptions;
            _licenseMappings = packageOptions.LicenseToUrlMappingsDictionary;
        }
コード例 #4
0
ファイル: PyPi.cs プロジェクト: AiimiLtd/nuget-license
        public PyPi(PackageOptions options)
        {
            this.options = options;
            this.files   = GetRelevantFilesInLocation();
            this.client  = new HttpClient();

            var userAndToken = options.GitHubToken?.Split(":");

            if (userAndToken.Length == 2)
            {
                this.gitCredentials = new Credentials(userAndToken[0], userAndToken[1]);
            }
            else
            {
                throw new Exception("Github token must be formatted \"user:token\". Get a token from Settings => Developer Settings => Personal Access Tokens");
            }
        }
コード例 #5
0
        public Methods(PackageOptions packageOptions)
        {
            if (_httpClient is null)
            {
                _httpClient = new HttpClient(new HttpClientHandler {
                    AllowAutoRedirect        = true,
                    MaxAutomaticRedirections = 20,
                });

                _httpClient.BaseAddress = new Uri(nugetUrl);
                _httpClient.Timeout     = TimeSpan.FromSeconds(10);
            }

            _serializer      = new XmlSerializer(typeof(Package));
            _packageOptions  = packageOptions;
            _licenseMappings = packageOptions.LicenseToUrlMappingsDictionary;
        }
コード例 #6
0
        private static async Task <int> Execute(PackageOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.ProjectDirectory))
            {
                Console.WriteLine("ERROR(S):");
                Console.WriteLine("-i\tInput the Directory Path (csproj file)");

                return(1);
            }

            await Program.CreateDirectories(options.OutputFileName);

            var baseOutput = options.OutputFileName;

            if (options.NugetLicenses)
            {
                Console.WriteLine("Beginning Nuget License Aggregation...");
                options.OutputFileName = Path.Combine(baseOutput, "nuget\\");
                Methods methods = new Methods(options);
                var     projectsWithPackages = await methods.GetPackages();

                var mappedLibraryInfo = methods.MapPackagesToLibraryInfo(projectsWithPackages);
                HandleInvalidLicenses(methods, mappedLibraryInfo, options.AllowedLicenseType);

                if (options.ExportLicenseTexts)
                {
                    await methods.ExportLicenseTexts(mappedLibraryInfo);
                }

                if (options.Print == true)
                {
                    Console.WriteLine();
                    Console.WriteLine("Project Reference(s) Analysis...");
                    methods.PrintLicenses(mappedLibraryInfo);
                }

                if (options.JsonOutput)
                {
                    methods.SaveAsJson(mappedLibraryInfo);
                }
                else
                {
                    methods.SaveAsTextFile(mappedLibraryInfo);
                }
            }

            if (options.PythonLicenses)
            {
                Console.WriteLine("Beginning Python License Aggregation...");
                options.OutputFileName = Path.Combine(baseOutput, "python\\");
                var python = new PyPi(options);
                await python.Run(options.OutputFileName);
            }

            if (options.NPMLicense)
            {
                Console.WriteLine("Beginning NPM License Aggregation...");
                options.OutputFileName = Path.Combine(baseOutput, "npm\\");
                var npm = new NPM(options.OutputFileName);
                await npm.Run(options.ProjectDirectory);
            }

            return(0);
        }
コード例 #7
0
        private static async Task <int> Execute(PackageOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.ProjectDirectory))
            {
                Console.WriteLine("ERROR(S):");
                Console.WriteLine("-i\tInput the Directory Path (csproj or fsproj file)");

                return(1);
            }

            if (options.UseProjectAssetsJson && !options.IncludeTransitive)
            {
                Console.WriteLine("ERROR(S):");
                Console.WriteLine("--use-project-assets-json\tThis option always includes transitive references, so you must also provide the -t option.");

                return(1);
            }

            if (options.Timeout < 1)
            {
                Console.WriteLine("ERROR(S):");
                Console.WriteLine("--timeout\tThe timeout must be a positive number.");

                return(1);
            }

            try
            {
                Methods methods = new Methods(options);
                var     projectsWithPackages = await methods.GetPackages();

                var mappedLibraryInfo = methods.MapPackagesToLibraryInfo(projectsWithPackages);
                HandleInvalidLicenses(methods, mappedLibraryInfo, options.AllowedLicenseType);

                if (options.ExportLicenseTexts)
                {
                    await methods.ExportLicenseTexts(mappedLibraryInfo);
                }

                mappedLibraryInfo = methods.HandleDeprecateMSFTLicense(mappedLibraryInfo);

                if (options.Print == true)
                {
                    Console.WriteLine();
                    Console.WriteLine("Project Reference(s) Analysis...");
                    methods.PrintLicenses(mappedLibraryInfo);
                }

                if (options.JsonOutput)
                {
                    methods.SaveAsJson(mappedLibraryInfo);
                }
                else if (options.MarkDownOutput)
                {
                    methods.SaveAsMarkdown(mappedLibraryInfo);
                }
                else
                {
                    methods.SaveAsTextFile(mappedLibraryInfo);
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(-1);
            }
        }