Exemple #1
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);
            }

            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);
        }
Exemple #2
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);
        }
Exemple #3
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);
            }
        }