static void Main(string[] args) { Console.Write("NuGet packages path:"); var path = Console.ReadLine(); if (!Directory.Exists(path)) { Console.Write("Not Found."); return; } var log = new Logger(); //LicenseUtility.ClientId = "xxx"; //LicenseUtility.ClientSecret = "xxx"; var packages = PackageLicensesUtility.GetPackages(path, log); var list = new List <(LocalPackageInfo, License)>(); var t = Task.Run(async() => { foreach (var p in packages) { Console.WriteLine($"{p.Nuspec.GetId()}.{p.Nuspec.GetVersion()}"); var license = await p.GetLicenseAsync(log); list.Add((p, license)); } }); t.Wait(); CreateWorkbook(list); Console.WriteLine("Completed."); }
private async System.Threading.Tasks.Task <bool> TryListAsync(string solutionPath, string saveFolderPath) { var root = Path.Combine(solutionPath, "packages"); if (!Directory.Exists(root)) { ServiceProvider.WriteOnOutputWindow($"Not Found: '{root}'\n"); return(false); } ServiceProvider.WriteOnOutputWindow($"Packages Path: '{root}'\n"); // Get GitHub Client ID and Client Secret var query = Environment.GetEnvironmentVariable("PACKAGE-LICENSES-GITHUB-QUERY", EnvironmentVariableTarget.User); if (!string.IsNullOrWhiteSpace(query)) { var m = Regex.Match(query, "client_id=(?<id>.*?)&client_secret=(?<secret>.*)"); if (m.Success) { LicenseUtility.ClientId = m.Groups["id"].Value; LicenseUtility.ClientSecret = m.Groups["secret"].Value; } } // Get packages var packages = PackageLicensesUtility.GetPackages(root, Logger.Instance); if (packages.Count() == 0) { ServiceProvider.WriteOnOutputWindow($"No Packages\n"); return(false); } // Output metadata and get licenses var headers = string.Join("\t", _headers.Take(_headers.Count - 1)); var dividers = string.Join("\t", _headers.Take(_headers.Count - 1).Select(i => new string('-', i.Length))); ServiceProvider.WriteOnOutputWindow($"\n{headers}\n{dividers}\n"); var list = new List <(LocalPackageInfo, License)>(); foreach (var p in packages) { var nuspec = p.Nuspec; var license = await p.GetLicenseAsync(Logger.Instance); ServiceProvider.WriteOnOutputWindow($"{nuspec.GetId()}\t{nuspec.GetVersion()}\t{nuspec.GetAuthors()}\t{nuspec.GetTitle()}\t{nuspec.GetProjectUrl()}\t{nuspec.GetLicenseUrl()}\t{nuspec.GetRequireLicenseAcceptance()}\t{nuspec.GetCopyright()}\t{license?.Id}\t{license?.Name}\n"); list.Add((p, license)); } ServiceProvider.WriteOnOutputWindow($"\n"); // Save to files CreateFiles(list, saveFolderPath); ServiceProvider.WriteOnOutputWindow($"Saved to '{saveFolderPath}'\n"); return(true); }
private static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); if (string.IsNullOrWhiteSpace(env)) { env = "Development"; } if (env == "Development") { builder.AddUserSecrets <Program>(); } _configuration = builder.Build(); Console.Write("Change product and company name in the applicationSettings.json"); Console.WriteLine("----"); var path = _configuration["Path"]; if (!Directory.Exists(path)) { Console.Write("Path not Found: " + path); Environment.ExitCode = ERROR_PACKAGE_PATH; return; } _outputPath = _configuration["OutputPath"]; var log = new Logger(); // GitHub Client ID and Client Secret const string LicenseUtilityClientId = "LicenseUtility.ClientId"; // Add user-secretes with command line: dotnet user-secrets set LicenseUtility.ClientId XXXX-XX-ID... Console.WriteLine($"The Secret Id is {_configuration[LicenseUtilityClientId]}"); LicenseUtility.ClientId = _configuration[LicenseUtilityClientId]; const string LicenseUtilityClientSecret = "LicenseUtility.ClientSecret"; // Add user-secretes with command line: dotnet user-secrets set LicenseUtility.ClientSecret XYZ... LicenseUtility.ClientSecret = _configuration[LicenseUtilityClientSecret]; Console.WriteLine($"The Client secret is {_configuration[LicenseUtilityClientId]}"); var packages = PackageLicensesUtility.GetPackages(path, log); var list = new List <(LocalPackageInfo, License)>(); var t = Task.Run(async() => { foreach (var p in packages) { Console.WriteLine($"{p.Nuspec.GetId()}.{p.Nuspec.GetVersion()}"); if (p.Nuspec.GetAuthors().ToLower().StartsWith("microsoft")) { Console.WriteLine("Ignore Microsoft"); continue; } if (p.Nuspec.GetAuthors().ToLower().StartsWith("jetbrain")) { Console.WriteLine("Ignore Jetbrain"); continue; } if (p.Nuspec.GetAuthors().ToLower().StartsWith("xunit")) { Console.WriteLine("Ignore xUnit.net [Testing Framework]"); continue; } var license = await p.GetLicenseAsync(log); list.Add((p, license)); } }); t.Wait(); try { CreateWorkbook(list); } catch (Exception) { throw; } Console.WriteLine("Completed."); }