Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1688)

Delta Between Two Patch Sets: Tools/Google.Apis.NuGet.Publisher/Google.Apis.NuGet.Publisher/Program.cs

Issue 12662047: Issue 376: Generate NuGet pacakges for generated APIs (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Left Patch Set: minor Created 11 years, 2 months ago
Right Patch Set: David final comments Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 Copyright 2013 Google Inc 2 Copyright 2013 Google Inc
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); 4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License. 5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at 6 You may obtain a copy of the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 /// The Google APIs NuGet publisher uses a local folder "C:\LocalNuGetFeed" to store all the NuGet packages 78 /// The Google APIs NuGet publisher uses a local folder "C:\LocalNuGetFeed" to store all the NuGet packages
79 /// locally. 79 /// locally.
80 /// Notice also the different between bundle and package: 80 /// Notice also the different between bundle and package:
81 /// A bundle is the zip file that contains the sources, and it's is download ed from 81 /// A bundle is the zip file that contains the sources, and it's is download ed from
82 /// "https://google-api-client-libraries.appspot.com/" 82 /// "https://google-api-client-libraries.appspot.com/"
83 /// A package is the NuGet package we use to build a solution. We can store NuGet packages locally (e.g. in 83 /// A package is the NuGet package we use to build a solution. We can store NuGet packages locally (e.g. in
84 /// "C:\LocalNuGetFeed") or use the main NuGet repository at "https://nuget. org/api/v2/" 84 /// "C:\LocalNuGetFeed") or use the main NuGet repository at "https://nuget. org/api/v2/"
85 /// </remarks> 85 /// </remarks>
86 class Program 86 class Program
87 { 87 {
88 static TraceSource TraceSource = new TraceSource("Google.Apis"); 88 private static TraceSource TraceSource = new TraceSource("Google.Apis");
89 89
90 /// <summary>The discovery URI to get all the public APIs.</summary> 90 /// <summary>The discovery URI to get all the public APIs.</summary>
91 static readonly Uri DiscoveryApiUri = new Uri(@"https://www.googleapis.c om/discovery/v1/apis"); 91 static readonly Uri DiscoveryApiUri = new Uri(@"https://www.googleapis.c om/discovery/v1/apis");
92 92
93 /// <summary>The download URI format to download a specific API format. Two parameters are expected the API· 93 /// <summary>The download URI format to download a specific API format. Two parameters are expected the API·
94 /// name and its version.</summary> 94 /// name and its version.</summary>
95 const string DownloadUriFormat = 95 const string DownloadUriFormat =
96 "https://google-api-client-libraries.appspot.com/resources/api-libra ries/download/stable/" + 96 "https://google-api-client-libraries.appspot.com/download/library/{0 }/{1}/csharp?deps=0";
97 "{0}/{1}/csharp?deps=0";
98 97
99 /// <summary>The template directory which contains the '.nuget' director y and the necessary·· 98 /// <summary>The template directory which contains the '.nuget' director y and the necessary··
100 /// 'Microsoft.Bcl.Build.targets' file.</summary> 99 /// 'Microsoft.Bcl.Build.targets' file.</summary>
101 readonly string TemplateDirectory; 100 readonly string TemplateDirectory;
102 101
103 /// <summary>The directory that the bundle will be downloaded to.</summa ry> 102 /// <summary>The directory that the bundle will be downloaded to.</summa ry>
104 readonly string DownloadBundleTempDirectory = Path.Combine(Path.GetTempP ath(), "GoogleAPIsPublisher"); 103 readonly string DownloadBundleTempDirectory = Path.Combine(Path.GetTempP ath(), "GoogleAPIsPublisher");
105 104
106 /// <summary>The program's options.</summary> 105 /// <summary>The program's options.</summary>
107 readonly Options options; 106 readonly Options options;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 174
176 IEnumerable<DiscoveryItem> apis; 175 IEnumerable<DiscoveryItem> apis;
177 if (options.AllApis) 176 if (options.AllApis)
178 { 177 {
179 apis = await new DiscoveryService().GetApis(DiscoveryApiUri); 178 apis = await new DiscoveryService().GetApis(DiscoveryApiUri);
180 } 179 }
181 else 180 else
182 { 181 {
183 apis = new List<DiscoveryItem> { new DiscoveryItem 182 apis = new List<DiscoveryItem> { new DiscoveryItem
184 { 183 {
185 Name = options.ApiName, 184 Name = options.ApiName.ToLower(),
186 Version = options.ApiVersion 185 Version = options.ApiVersion.ToLower()
187 }}; 186 }};
188 } 187 }
189 188
190 if (Directory.Exists(DownloadBundleTempDirectory)) 189 if (Directory.Exists(DownloadBundleTempDirectory))
191 { 190 {
192 Directory.Delete(DownloadBundleTempDirectory, true); 191 Directory.Delete(DownloadBundleTempDirectory, true);
193 } 192 }
194 Directory.CreateDirectory(DownloadBundleTempDirectory); 193 Directory.CreateDirectory(DownloadBundleTempDirectory);
195 194
196 try 195 try
(...skipping 20 matching lines...) Expand all
217 var workingDir = Path.Combine(DownloadBundleTempDirectory, 216 var workingDir = Path.Combine(DownloadBundleTempDirectory,
218 item.Name + "-" + item.Version); 217 item.Name + "-" + item.Version);
219 Directory.CreateDirectory(workingDir); 218 Directory.CreateDirectory(workingDir);
220 219
221 var bundleUri = string.Format(DownloadUriFormat, item.Name, item .Version); 220 var bundleUri = string.Format(DownloadUriFormat, item.Name, item .Version);
222 if (!string.IsNullOrEmpty(options.GoogleApisVersion)) 221 if (!string.IsNullOrEmpty(options.GoogleApisVersion))
223 { 222 {
224 bundleUri = bundleUri + "&lv=" + options.GoogleApisVersion; 223 bundleUri = bundleUri + "&lv=" + options.GoogleApisVersion;
225 } 224 }
226 225
227 var publisher = new ApiItemLogic(item) 226 var publisher = new NuGetApiPublisher(item)
228 { 227 {
229 BundleDirectory = workingDir, 228 BundleDirectory = workingDir,
230 BundleUri = new Uri(bundleUri), 229 BundleUri = new Uri(bundleUri),
231 TemplateDirectory = TemplateDirectory, 230 TemplateDirectory = TemplateDirectory,
232 NuGetApiKey = options.NuGetApiKey, 231 NuGetApiKey = options.NuGetApiKey,
233 }; 232 };
234 233
235 try 234 try
236 { 235 {
237 await publisher.Run(); 236 await publisher.Run();
238 } 237 }
239 catch (Exception ex) 238 catch (Exception ex)
240 { 239 {
241 TraceSource.TraceEvent(TraceEventType.Error, "{0}\t Exceptio n [{1}] occurred", item, ex.Message); 240 TraceSource.TraceEvent(TraceEventType.Error, "{0}\t Exceptio n [{1}] occurred", item, ex.Message);
242 } 241 }
243 } 242 }
244 } 243 }
245 244
246 /// <summary> 245 /// <summary>
247 /// Tests the main logic behave as expected. <see cref="ApiItemLogic.Tes t"/> for more details. 246 /// Tests the main logic behave as expected. <see cref="NuGetApiPublishe r.Test"/> for more details.
248 /// </summary> 247 /// </summary>
249 async Task TestAsync(IEnumerable<DiscoveryItem> apis) 248 async Task TestAsync(IEnumerable<DiscoveryItem> apis)
250 { 249 {
251 foreach (var item in apis) 250 foreach (var item in apis)
252 { 251 {
253 var publisher = new ApiItemLogic(item) 252 var publisher = new NuGetApiPublisher(item)
254 { 253 {
255 TemplateDirectory = TemplateDirectory, 254 TemplateDirectory = TemplateDirectory,
256 }; 255 };
257 try 256 try
258 { 257 {
259 await publisher.Test(options.ApisDirectory); 258 await publisher.Test(options.ApisDirectory);
260 } 259 }
261 catch (Exception ex) 260 catch (Exception ex)
262 { 261 {
263 TraceSource.TraceEvent(TraceEventType.Error, "{0}\t Exceptio n [{1}] occurred", item, ex.Message); 262 TraceSource.TraceEvent(TraceEventType.Error, "{0}\t Exceptio n [{1}] occurred", item, ex.Message);
264 } 263 }
265 } 264 }
266 } 265 }
267 } 266 }
268 } 267 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b