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

Side by Side Diff: Tools/BuildRelease/Wiki/DownloadsPage.cs

Issue 12767046: Issue 377: New build for releasing a new version (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: david comments Created 10 years, 6 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:
View unified diff | Download patch
« no previous file with comments | « Tools/BuildRelease/Properties/AssemblyInfo.cs ('k') | Tools/BuildRelease/app.config » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 Copyright 2013 Google Inc
3
4 Licensed under the Apache License, Version 2.0 (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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 using System;
18 using System.IO;
19 using System.Linq;
20 using System.Text.RegularExpressions;
21
22 using Google.Apis.Samples.Helper;
23 using Google.Build.Utils.Text;
24
25 namespace BuildRelease.Wiki
26 {
27 /// <summary> Updator for the Downloads wiki page. </summary>
28 public class DownloadsPage
29 {
30 private const string StableStartTag = "<wiki:comment>GENERATED_STABLE_BE GIN</wiki:comment>";
31 private const string StableEndTag = "<wiki:comment>GENERATED_STABLE_END< /wiki:comment>";
32 private const string DownloadsStartTag = "<wiki:comment>GENERATED_DOWNLO ADS_BEGIN</wiki:comment>";
33 private const string DownloadsEndTag = "<wiki:comment>GENERATED_DOWNLOAD S_END</wiki:comment>";
34
35 private static readonly Regex LinkRegex = new Regex(@"\[([^ \]]*/)\S+ ([ ^\]]+)]", RegexOptions.Compiled);
36
37 /// <summary> The Samples repository used for generating the list of sam ples. </summary>
38 public string ReleaseNotes { get; private set; }
39
40 /// <summary> The directory containing the release .zip files. </summary >
41 public string ZipDir { get; private set; }
42
43 /// <summary> The Name of this release. </summary>
44 public string ReleaseName { get; private set; }
45
46 public DownloadsPage(string releaseNotes, string zipDir)
47 {
48 ReleaseNotes = releaseNotes;
49 ZipDir = zipDir;
50 ReleaseName = Path.GetFileName(Path.GetDirectoryName(Path.GetDirecto ryName(zipDir)));
51 }
52
53 /// <summary> Generates the Releases Notes section. </summary>
54 private string GenerateNotes()
55 {
56 return "{{{" + Environment.NewLine + ReleaseNotes + Environment.NewL ine + "}}}";
57 }
58
59 /// <summary>·
60 /// Replaces the download links references for binaries, source and samp les to the current version number.
61 /// </summary>
62 /// <param name="input">The text block containing the wiki links.</param >
63 /// <returns>Replaced & updated text.</returns>
64 private string ReplaceLinks(string input)
65 {
66 const string format =
67 "[http://contrib.google-api-dotnet-client.googlecode.com/hg/{0}/ Generated/ZipFiles/{1} {2}]";
68 return LinkRegex.Replace(input, (match) => string.Format(format,
69 ReleaseName ,
70 GetFileName (match.Groups[2].ToString()),
71 match.Group s[2].ToString()));
72 }
73
74 /// <summary>
75 /// Retrieves the filename of the release for the specified title/keywor d.
76 /// Example:
77 /// 'Binary Release' results in 'google-api-dotnet-client-1.0.0.Bina ry.zip'
78 /// </summary>
79 private string GetFileName(string title)
80 {
81 string keyword = title.Split(' ')[0];
82 return Path.GetFileName(Directory.GetFiles(ZipDir, "*" + keyword + " *").Single());
83 }
84
85 /// <summary> Modifies the existing Downloads wiki file by replacing the "generated" section. </summary>
86 private void InsertIntoFile(string file)
87 {
88 string content = File.ReadAllText(file);
89 content = TextUtils.InsertIntoText(content, StableStartTag, StableEn dTag, GenerateNotes());
90 content = TextUtils.ReplaceInText(content, DownloadsStartTag, Downlo adsEndTag, ReplaceLinks);
91 File.WriteAllText(file, content);
92 }
93
94 /// <summary> Updates the Wiki. </summary>
95 public void UpdateWiki(string workingDirectory)
96 {
97 if (ReleaseNotes != null)
98 {
99 CommandLine.WriteAction("Updating 'Downloads.wiki' ...");
100 InsertIntoFile(Path.Combine(workingDirectory, "Downloads.wiki")) ;
101 }
102 }
103 }
104 }
OLDNEW
« no previous file with comments | « Tools/BuildRelease/Properties/AssemblyInfo.cs ('k') | Tools/BuildRelease/app.config » ('j') | no next file with comments »

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