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

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 10 years, 7 months ago
Right Patch Set: David final comments Created 10 years, 7 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
11 distributed under the License is distributed on an "AS IS" BASIS, 11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and 13 See the License for the specific language governing permissions and
14 limitations under the License. 14 limitations under the License.
15 */ 15 */
16 16
17 using System; 17 using System;
18 using System.Collections.Generic; 18 using System.Collections.Generic;
19 using System.Diagnostics; 19 using System.Diagnostics;
20 using System.IO; 20 using System.IO;
21 using System.Linq; 21 using System.Linq;
22 using System.Reflection; 22 using System.Reflection;
23 using System.Threading.Tasks; 23 using System.Threading.Tasks;
24 24
25 using CommandLine; 25 using CommandLine;
26 using CommandLine.Text; 26 using CommandLine.Text;
27
28 using Google.Apis.NuGet.Publisher.Discovery;
29 using Google.Apis.Utils;
27 30
28 namespace Google.Apis.NuGet.Publisher 31 namespace Google.Apis.NuGet.Publisher
29 { 32 {
30 /// <summary>The options class which contains the different options to this utility.</summary> 33 /// <summary>The options class which contains the different options to this utility.</summary>
31 class Options 34 class Options
32 { 35 {
33 public const string ModeTest = "test"; 36 public const string ModeTest = "test";
34 public const string ModePublish = "publisher"; 37 public const string ModePublish = "publisher";
35 38
36 [Option('a', "all_apis", HelpText = "Define if NuGet publisher works on all Google APIs")] 39 [Option('a', "all_apis", HelpText = "Define if NuGet publisher works on all Google APIs")]
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 /// 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
76 /// locally. 79 /// locally.
77 /// Notice also the different between bundle and package: 80 /// Notice also the different between bundle and package:
78 /// 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
79 /// "https://google-api-client-libraries.appspot.com/" 82 /// "https://google-api-client-libraries.appspot.com/"
80 /// 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
81 /// "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/"
82 /// </remarks> 85 /// </remarks>
83 class Program 86 class Program
84 { 87 {
85 static TraceSource TraceSource = new TraceSource("Google.Apis"); 88 private static TraceSource TraceSource = new TraceSource("Google.Apis");
86 89
87 /// <summary>The discovery URI to get all the public APIs.</summary> 90 /// <summary>The discovery URI to get all the public APIs.</summary>
88 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");
89 92
90 /// <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·
91 /// name and its version.</summary> 94 /// name and its version.</summary>
92 const string DownloadUriFormat = 95 const string DownloadUriFormat =
93 "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";
94 "{0}/{1}/csharp?deps=0";
95 97
96 /// <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··
97 /// 'Microsoft.Bcl.Build.targets' file.</summary> 99 /// 'Microsoft.Bcl.Build.targets' file.</summary>
98 readonly string TemplateDirectory; 100 readonly string TemplateDirectory;
99 101
100 /// <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>
101 readonly string DownloadBundleTempDirectory = Path.Combine(Path.GetTempP ath(), "GoogleAPIsPublisher"); 103 readonly string DownloadBundleTempDirectory = Path.Combine(Path.GetTempP ath(), "GoogleAPIsPublisher");
102 104
103 /// <summary>The program's options.</summary> 105 /// <summary>The program's options.</summary>
104 readonly Options options; 106 readonly Options options;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return RunAsync("TEST", TestAsync); 160 return RunAsync("TEST", TestAsync);
159 case Options.ModePublish: 161 case Options.ModePublish:
160 return RunAsync("PUBLISH", PublishAsync); 162 return RunAsync("PUBLISH", PublishAsync);
161 default: 163 default:
162 throw new ArgumentException(string.Format("Mode should be {0 } or {1}", 164 throw new ArgumentException(string.Format("Mode should be {0 } or {1}",
163 Options.ModePublish, Options.ModeTest)); 165 Options.ModePublish, Options.ModeTest));
164 } 166 }
165 } 167 }
166 168
167 /// <summary>The main wrapper to run, gets a function to run which conta ins the main logic.</summary> 169 /// <summary>The main wrapper to run, gets a function to run which conta ins the main logic.</summary>
168 async Task RunAsync(string header, Func<IEnumerable<DiscoveryDoc.Item>, Task> core) 170 async Task RunAsync(string header, Func<IEnumerable<DiscoveryItem>, Task > core)
169 { 171 {
170 TraceSource.TraceEvent(TraceEventType.Information, "=============== {0} ===============", header); 172 TraceSource.TraceEvent(TraceEventType.Information, "=============== {0} ===============", header);
171 TraceSource.TraceEvent(TraceEventType.Information, "Entering Google. Apis.Nuget.Publihser"); 173 TraceSource.TraceEvent(TraceEventType.Information, "Entering Google. Apis.Nuget.Publihser");
172 174
173 IEnumerable<DiscoveryDoc.Item> apis; 175 IEnumerable<DiscoveryItem> apis;
174 if (options.AllApis) 176 if (options.AllApis)
175 { 177 {
176 apis = await new DiscoveryService().GetApis(DiscoveryApiUri); 178 apis = await new DiscoveryService().GetApis(DiscoveryApiUri);
177 } 179 }
178 else 180 else
179 { 181 {
180 apis = new List<DiscoveryDoc.Item> { new DiscoveryDoc.Item 182 apis = new List<DiscoveryItem> { new DiscoveryItem
181 { 183 {
182 Name = options.ApiName, 184 Name = options.ApiName.ToLower(),
183 Version = options.ApiVersion 185 Version = options.ApiVersion.ToLower()
184 }}; 186 }};
185 } 187 }
186 188
187 if (Directory.Exists(DownloadBundleTempDirectory)) 189 if (Directory.Exists(DownloadBundleTempDirectory))
188 { 190 {
189 Directory.Delete(DownloadBundleTempDirectory, true); 191 Directory.Delete(DownloadBundleTempDirectory, true);
190 } 192 }
191 Directory.CreateDirectory(DownloadBundleTempDirectory); 193 Directory.CreateDirectory(DownloadBundleTempDirectory);
192 194
193 try 195 try
194 { 196 {
195 TraceSource.TraceEvent(TraceEventType.Information, "\"{0}\" fold er was created", 197 TraceSource.TraceEvent(TraceEventType.Information, "\"{0}\" fold er was created",
196 DownloadBundleTempDirectory); 198 DownloadBundleTempDirectory);
197 199
198 await core(apis); 200 await core(apis);
199 201
200 TraceSource.TraceEvent(TraceEventType.Information, 0, "Exiting G oogle.Apis.Nuget.Publihser"); 202 TraceSource.TraceEvent(TraceEventType.Information, 0, "Exiting G oogle.Apis.Nuget.Publihser");
201 } 203 }
202 finally 204 finally
203 { 205 {
204 Directory.Delete(DownloadBundleTempDirectory); 206 Directory.Delete(DownloadBundleTempDirectory, true);
205 } 207 }
206 } 208 }
207 209
208 /// <summary>Publishes new APIs to NuGet main repository.</summary> 210 /// <summary>Publishes new APIs to NuGet main repository.</summary>
209 async Task PublishAsync(IEnumerable<DiscoveryDoc.Item> apis) 211 async Task PublishAsync(IEnumerable<DiscoveryItem> apis)
210 { 212 {
211 // TODO(peleyal): validate NuGetApiKey 213 // TODO(peleyal): validate NuGetApiKey
212 foreach (var item in apis) 214 foreach (var item in apis)
213 { 215 {
214 var workingDir = Path.Combine(DownloadBundleTempDirectory, 216 var workingDir = Path.Combine(DownloadBundleTempDirectory,
215 item.Name + "-" + item.Version); 217 item.Name + "-" + item.Version);
216 Directory.CreateDirectory(workingDir); 218 Directory.CreateDirectory(workingDir);
217 219
218 var bundleUri = string.Format(DownloadUriFormat, item.Name, item .Version); 220 var bundleUri = string.Format(DownloadUriFormat, item.Name, item .Version);
219 if (!string.IsNullOrEmpty(options.GoogleApisVersion)) 221 if (!string.IsNullOrEmpty(options.GoogleApisVersion))
(...skipping 16 matching lines...) Expand all
236 catch (Exception ex) 238 catch (Exception ex)
237 { 239 {
238 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);
239 } 241 }
240 } 242 }
241 } 243 }
242 244
243 /// <summary> 245 /// <summary>
244 /// Tests the main logic behave as expected. <see cref="NuGetApiPublishe r.Test"/> for more details. 246 /// Tests the main logic behave as expected. <see cref="NuGetApiPublishe r.Test"/> for more details.
245 /// </summary> 247 /// </summary>
246 async Task TestAsync(IEnumerable<DiscoveryDoc.Item> apis) 248 async Task TestAsync(IEnumerable<DiscoveryItem> apis)
247 { 249 {
248 foreach (var item in apis) 250 foreach (var item in apis)
249 { 251 {
250 var publisher = new NuGetApiPublisher(item) 252 var publisher = new NuGetApiPublisher(item)
251 { 253 {
252 TemplateDirectory = TemplateDirectory, 254 TemplateDirectory = TemplateDirectory,
253 }; 255 };
254 try 256 try
255 { 257 {
256 await publisher.Test(options.ApisDirectory); 258 await publisher.Test(options.ApisDirectory);
257 } 259 }
258 catch (Exception ex) 260 catch (Exception ex)
259 { 261 {
260 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);
261 } 263 }
262 } 264 }
263 } 265 }
264 } 266 }
265 } 267 }
LEFTRIGHT

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