| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | using CloudPackageMapGenerator; |
| | using Newtonsoft.Json; |
| |
|
| | if (args.Length != 2) |
| | { |
| | Console.WriteLine("Required arguments: <path-to-google-api-dotnet-client root> <path-to-google-cloud-dotnet-root>"); |
| | return 1; |
| | } |
| |
|
| | |
| | string featuresFile = Path.Combine(args[0], "features.json"); |
| | string generatedDir = Path.Combine(args[0], "Src", "Generated"); |
| | string apiCatalogFile = Path.Combine(args[1], "apis", "apis.json"); |
| |
|
| | if (!File.Exists(featuresFile)) |
| | { |
| | Console.WriteLine($"Can't find '{featuresFile}'."); |
| | return 1; |
| | } |
| |
|
| | if (!Directory.Exists(generatedDir)) |
| | { |
| | Console.WriteLine($"Can't find '{generatedDir}'."); |
| | return 1; |
| | } |
| |
|
| | if (!File.Exists(apiCatalogFile)) |
| | { |
| | Console.WriteLine($"Can't find '{apiCatalogFile}'."); |
| | return 1; |
| | } |
| |
|
| | var allRestLibraries = Directory.GetDirectories(generatedDir).Select(Path.GetFileName).ToList(); |
| | var apiCatalogJson = File.ReadAllText(apiCatalogFile); |
| |
|
| | |
| | |
| | var featuresFileLines = File.ReadAllLines(featuresFile).ToList(); |
| | int packageMapStartIndex = featuresFileLines.IndexOf(" \"cloudPackageMap\": {"); |
| | if (packageMapStartIndex == -1) |
| | { |
| | Console.WriteLine("Can't find start of cloudPackageMap property in features.json"); |
| | return 1; |
| | } |
| |
|
| | int packageMapEndIndex = featuresFileLines.IndexOf(" },", packageMapStartIndex); |
| | if (packageMapEndIndex == -1) |
| | { |
| | Console.WriteLine("Can't find end of cloudPackageMap property in features.json"); |
| | return 1; |
| | } |
| |
|
| | var existingMappedRestLibraries = featuresFileLines |
| | .Skip(packageMapStartIndex + 1) |
| | .Take(packageMapEndIndex - packageMapStartIndex - 1) |
| | .Where(line => !line.Trim().StartsWith("//")) |
| | .Select(line => line.Split(':')[0].Trim(' ', '"')) |
| | .ToHashSet(); |
| |
|
| | |
| | |
| | var apiCatalog = JsonConvert.DeserializeObject<ApiCatalog>(apiCatalogJson); |
| | var gapicLibraries = apiCatalog.Apis |
| | .Where(api => api.Version != "1.0.0-beta00") |
| | .Select(api => api.Id) |
| | .ToDictionary(id => id.Replace(".", ""), id => id, StringComparer.OrdinalIgnoreCase); |
| |
|
| | |
| | |
| | int newlyMappedCount = 0; |
| | foreach (var library in allRestLibraries.Except(existingMappedRestLibraries)) |
| | { |
| | bool mapped = false; |
| | var noApis = library.Replace(".Apis.", "."); |
| | MaybeMap(noApis); |
| | MaybeMap(noApis.Replace("Service.", ".")); |
| | MaybeMap(noApis.Replace("Google.", "Google.Cloud.")); |
| | if (!mapped) |
| | { |
| | Console.WriteLine($"No mapping for {library}"); |
| | } |
| |
|
| | void MaybeMap(string candidate) |
| | { |
| | if (mapped) |
| | { |
| | return; |
| | } |
| | if (gapicLibraries.TryGetValue(candidate.Replace(".", ""), out var gapic)) |
| | { |
| | Console.WriteLine($"Mapping {library} to {gapic}"); |
| | mapped = true; |
| | newlyMappedCount++; |
| | featuresFileLines.Insert(packageMapEndIndex++, $" \"{library}\": \"{gapic}\","); |
| | } |
| | } |
| | } |
| |
|
| | |
| | Console.WriteLine(); |
| | Console.WriteLine($"Total REST libraries: {allRestLibraries.Count}"); |
| | Console.WriteLine($"Previously-mapped: {existingMappedRestLibraries.Count}"); |
| | Console.WriteLine($"Newly-mapped: {newlyMappedCount}"); |
| | Console.WriteLine($"Unmapped: {allRestLibraries.Count - existingMappedRestLibraries.Count - newlyMappedCount}"); |
| |
|
| | if (newlyMappedCount != 0) |
| | { |
| | File.WriteAllLines(featuresFile, featuresFileLines); |
| | } |
| |
|
| | return 0; |