OLD | NEW |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #region HelpText | 46 #region HelpText |
47 | 47 |
48 const string VersionHelpText = "The version number of this release -
<Major.Minor.Build> only."; | 48 const string VersionHelpText = "The version number of this release -
<Major.Minor.Build> only."; |
49 const string OutputHelpText = "Define the output directory for this
build. " + | 49 const string OutputHelpText = "Define the output directory for this
build. " + |
50 "Notice that it's relative to current directory."; | 50 "Notice that it's relative to current directory."; |
51 const string StepHelpText = "Two options: " + | 51 const string StepHelpText = "Two options: " + |
52 "'1' for building the core library. \n" + | 52 "'1' for building the core library. \n" + |
53 "'2' for compiling samples, updating wiki and push to contrib th
e new version."; | 53 "'2' for compiling samples, updating wiki and push to contrib th
e new version."; |
54 const string IsBetaHelpText = "Is this release beta?"; | 54 const string IsBetaHelpText = "Is this release beta?"; |
55 const string NuGetApiKeyHelpText = "Define the NuGet API key to publ
ish to NuGet main repository."; | 55 const string NuGetApiKeyHelpText = "Define the NuGet API key to publ
ish to NuGet main repository."; |
| 56 const string IsLocalHelpText = "Define if current default repository
will be used."; |
56 | 57 |
57 [HelpOption] | 58 [HelpOption] |
58 public string GetHelp() | 59 public string GetHelp() |
59 { | 60 { |
60 return HelpText.AutoBuild(this, c => HelpText.DefaultParsingErro
rsHandler(this, c)); | 61 return HelpText.AutoBuild(this, c => HelpText.DefaultParsingErro
rsHandler(this, c)); |
61 } | 62 } |
62 | 63 |
63 #endregion | 64 #endregion |
64 | 65 |
65 [Option('v', "version", Required = true, HelpText = VersionHelpText)
] | 66 [Option('v', "version", Required = true, HelpText = VersionHelpText)
] |
66 public string Version { get; set; } | 67 public string Version { get; set; } |
67 | 68 |
68 [Option('d', "dir", Required = true, HelpText = OutputHelpText)] | 69 [Option('d', "dir", HelpText = OutputHelpText)] |
69 public string OutputDirectory { get; set; } | 70 public string OutputDirectory { get; set; } |
70 | 71 |
| 72 [Option('l', "local", DefaultValue = false, HelpText = IsLocalHelpTe
xt)] |
| 73 public bool IsLocal { get; set; } |
| 74 |
71 [Option('s', "step", Required = true, HelpText = StepHelpText)] | 75 [Option('s', "step", Required = true, HelpText = StepHelpText)] |
72 public int Step { get; set; } | 76 public int Step { get; set; } |
73 | 77 |
74 [Option('b', "beta", DefaultValue = true, HelpText = IsBetaHelpText)
] | 78 [Option('b', "beta", DefaultValue = true, HelpText = IsBetaHelpText)
] |
75 public bool IsBeta { get; set; } | 79 public bool IsBeta { get; set; } |
76 | 80 |
77 [Option('k', "nuget_key", HelpText = NuGetApiKeyHelpText)] | 81 [Option('k', "nuget_key", HelpText = NuGetApiKeyHelpText)] |
78 public string NuGetApiKey { get; set; } | 82 public string NuGetApiKey { get; set; } |
79 } | 83 } |
80 | 84 |
81 private static readonly TraceSource TraceSource = new TraceSource("Googl
e.Apis"); | 85 private static readonly TraceSource TraceSource = new TraceSource("Googl
e.Apis"); |
82 | 86 |
83 /// <summary>Command line arguments.</summary> | 87 /// <summary>Command line arguments.</summary> |
84 private readonly Options options; | 88 private readonly Options options; |
85 | 89 |
| 90 /// <summary>The current repository (default) relative path.</summary> |
| 91 private readonly string LocalRepositoryRelativePath = "..\\..\\..\\..\\"
; |
| 92 |
86 private int MajorVersion { get; set; } | 93 private int MajorVersion { get; set; } |
87 private int MinorVersion { get; set; } | 94 private int MinorVersion { get; set; } |
88 private int BuildVersion { get; set; } | 95 private int BuildVersion { get; set; } |
89 | 96 |
90 private string Tag | 97 private string Tag |
91 { | 98 { |
92 get { return options.Version + (options.IsBeta ? "-beta" : ""); } | 99 get { return options.Version + (options.IsBeta ? "-beta" : ""); } |
93 } | 100 } |
94 | 101 |
95 /// <summary>Gets or sets the "default" repository.</summary> | 102 /// <summary>Gets or sets the "default" repository.</summary> |
(...skipping 29 matching lines...) Expand all Loading... |
125 { | 132 { |
126 TraceSource.TraceEvent(TraceEventType.Error, "Error in reading a
rguments"); | 133 TraceSource.TraceEvent(TraceEventType.Error, "Error in reading a
rguments"); |
127 return; | 134 return; |
128 } | 135 } |
129 | 136 |
130 if (options.Step > 2 || options.Step < 1) | 137 if (options.Step > 2 || options.Step < 1) |
131 { | 138 { |
132 TraceSource.TraceEvent(TraceEventType.Error, "Invalid Step. Vali
d step is '1' or '2'."); | 139 TraceSource.TraceEvent(TraceEventType.Error, "Invalid Step. Vali
d step is '1' or '2'."); |
133 valid = false; | 140 valid = false; |
134 } | 141 } |
| 142 if (options.IsLocal) |
| 143 { |
| 144 if (options.Step == 2) |
| 145 { |
| 146 TraceSource.TraceEvent(TraceEventType.Error, "You can run st
ep 2 using your local folder only."); |
| 147 valid = false; |
| 148 } |
| 149 else |
| 150 { |
| 151 TraceSource.TraceEvent(TraceEventType.Information, "Working
locally!"); |
| 152 } |
| 153 } |
| 154 else if (string.IsNullOrEmpty(options.OutputDirectory)) |
| 155 { |
| 156 TraceSource.TraceEvent(TraceEventType.Error, "Please specify out
put directory or run locally."); |
| 157 valid = false; |
| 158 } |
135 | 159 |
136 var match = Regex.Match(options.Version, @"^(\d+)\.(\d+)\.(\d)+$"); | 160 var match = Regex.Match(options.Version, @"^(\d+)\.(\d+)\.(\d)+$"); |
137 if (!match.Success) | 161 if (!match.Success) |
138 { | 162 { |
139 TraceSource.TraceEvent(TraceEventType.Error, | 163 TraceSource.TraceEvent(TraceEventType.Error, |
140 "Invalid version Number. Version should be in <Major>.<Minor
>.<Build> form."); | 164 "Invalid version Number. Version should be in <Major>.<Minor
>.<Build> form."); |
141 valid = false; | 165 valid = false; |
142 } | 166 } |
143 | 167 |
144 var program = new Program(options) | 168 var program = new Program(options) |
(...skipping 16 matching lines...) Expand all Loading... |
161 } | 185 } |
162 } | 186 } |
163 | 187 |
164 Console.WriteLine("Press any key to continue..."); | 188 Console.WriteLine("Press any key to continue..."); |
165 Console.ReadKey(); | 189 Console.ReadKey(); |
166 } | 190 } |
167 | 191 |
168 /// <summary>The main release logic for creating a new release of Google
.Apis.</summary> | 192 /// <summary>The main release logic for creating a new release of Google
.Apis.</summary> |
169 private void Run() | 193 private void Run() |
170 { | 194 { |
171 DefaultRepository = new Hg(new Uri(string.Format(CloneUrlFormat, "")
), "default"); | 195 DefaultRepository = new Hg(new Uri(string.Format(CloneUrlFormat, "")
), options.IsLocal ? null : "default"); |
172 | 196 |
173 // Step 1 is only for creating Google.Apis and Google.Apis.Authentic
ation packages | 197 // Step 1 is only for creating Google.Apis and Google.Apis.Authentic
ation packages |
174 if (options.Step == 1) | 198 if (options.Step == 1) |
175 { | 199 { |
176 DoStep1(); | 200 DoStep1(); |
177 } | 201 } |
178 // Step 2 should be done after the NuGet publisher generated all the
APIs and the samples repository was· | 202 // Step 2 should be done after the NuGet publisher generated all the
APIs and the samples repository was· |
179 // updated with the new packages | 203 // updated with the new packages |
180 else if (options.Step == 2) | 204 else if (options.Step == 2) |
181 { | 205 { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 if (Directory.Exists(destDirectory)) | 568 if (Directory.Exists(destDirectory)) |
545 { | 569 { |
546 Directory.Delete(destDirectory, true); | 570 Directory.Delete(destDirectory, true); |
547 } | 571 } |
548 | 572 |
549 FileInfo info = new FileInfo(Assembly.GetEntryAssembly().Location); | 573 FileInfo info = new FileInfo(Assembly.GetEntryAssembly().Location); |
550 DirectoryUtilities.CopyDirectory(Path.Combine(info.Directory.FullNam
e, "Resources"), destDirectory); | 574 DirectoryUtilities.CopyDirectory(Path.Combine(info.Directory.FullNam
e, "Resources"), destDirectory); |
551 | 575 |
552 var newVersion = options.Version + "-beta"; | 576 var newVersion = options.Version + "-beta"; |
553 | 577 |
554 // get the Google.Apis and Google.Apis.Authentication nuspec files a
nd replace the version in it | 578 foreach (var nuspec in new[] {· |
555 var apiNuspec = Path.Combine(destDirectory, "Google.Apis.VERSION.nus
pec"); | 579 "Google.Apis.VERSION.nuspec",· |
556 var newApiNuspec = apiNuspec.Replace("VERSION", newVersion); | 580 "Google.Apis.Authentication.VERSION.nuspec",· |
557 var authenticationNuspec = Path.Combine(destDirectory, "Google.Apis.
Authentication.VERSION.nuspec"); | 581 "Google.Apis.Auth.VERSION.nuspec",· |
558 var newAuthenticationNuspec = authenticationNuspec.Replace("VERSION"
, newVersion); | 582 "Google.Apis.Auth.Mvc4.VERSION.nuspec" }) |
| 583 { |
| 584 var pathNuspec = Path.Combine(destDirectory, nuspec); |
| 585 var newNuspec = pathNuspec.Replace("VERSION", newVersion); |
| 586 File.Move(pathNuspec, newNuspec); |
559 | 587 |
560 File.Move(apiNuspec, newApiNuspec); | 588 var allLines = File.ReadAllText(newNuspec).Replace("VERSION", ne
wVersion); |
561 File.Move(authenticationNuspec, newAuthenticationNuspec); | 589 File.WriteAllText(newNuspec, allLines); |
562 | 590 |
563 var allLines = File.ReadAllText(newApiNuspec).Replace("VERSION", new
Version); | 591 NuGetUtilities.CreateLocalNupkgFile(newNuspec, Environment.Curre
ntDirectory); |
564 File.WriteAllText(newApiNuspec, allLines); | 592 } |
565 | |
566 allLines = File.ReadAllText(newAuthenticationNuspec).Replace("VERSIO
N", newVersion); | |
567 File.WriteAllText(newAuthenticationNuspec, allLines); | |
568 | |
569 NuGetUtilities.CreateLocalNupkgFile(newApiNuspec, Environment.Curren
tDirectory); | |
570 NuGetUtilities.CreateLocalNupkgFile(newAuthenticationNuspec, Environ
ment.CurrentDirectory); | |
571 } | 593 } |
572 | 594 |
573 private IEnumerable<Project> releaseProjects; | 595 private IEnumerable<Project> releaseProjects; |
574 /// <summary>Gets the release projects of from the "default" repository.
</summary> | 596 /// <summary>Gets the release projects of from the "default" repository.
</summary> |
575 private IEnumerable<Project> ReleaseProjects | 597 private IEnumerable<Project> ReleaseProjects |
576 { | 598 { |
577 get | 599 get |
578 { | 600 { |
579 if (releaseProjects != null) | 601 if (releaseProjects != null) |
580 { | 602 { |
581 return releaseProjects; | 603 return releaseProjects; |
582 } | 604 } |
583 | 605 |
584 var releasePaths = new[]· | 606 var releasePaths = new[]· |
585 { | 607 { |
586 DefaultRepository.Combine("Src", "GoogleApis", "GoogleApis.c
sproj"), | 608 DefaultRepository.Combine("Src", "GoogleApis", "GoogleApis.c
sproj"), |
| 609 DefaultRepository.Combine("Src", "GoogleApis.Auth", "GoogleA
pis.Auth.csproj"), |
| 610 |
587 DefaultRepository.Combine("Src", "GoogleApis.DotNet4", "Goog
leApis.DotNet4.csproj"), | 611 DefaultRepository.Combine("Src", "GoogleApis.DotNet4", "Goog
leApis.DotNet4.csproj"), |
| 612 DefaultRepository.Combine("Src", "GoogleApis.WinRT", "Google
Apis.WinRT.csproj"), |
| 613 DefaultRepository.Combine("Src", "GoogleApis.WP", "GoogleApi
s.WP.csproj"), |
| 614 |
| 615 DefaultRepository.Combine("Src", "GoogleApis.Auth.DotNet4",
"GoogleApis.Auth.DotNet4.csproj"), |
| 616 DefaultRepository.Combine("Src", "GoogleApis.Auth.Mvc4", "Go
ogleApis.Auth.Mvc4.csproj"), |
| 617 DefaultRepository.Combine("Src", "GoogleApis.Auth.WinRT", "G
oogleApis.Auth.WinRT.csproj"), |
| 618 DefaultRepository.Combine("Src", "GoogleApis.Auth.WP", "Goog
leApis.Auth.WP.csproj"), |
| 619 |
588 DefaultRepository.Combine("Src", "GoogleApis.Authentication.
OAuth2",· | 620 DefaultRepository.Combine("Src", "GoogleApis.Authentication.
OAuth2",· |
589 "GoogleApis.Authentication.OAuth2.csproj") | 621 "GoogleApis.Authentication.OAuth2.csproj") |
590 }; | 622 }; |
591 return releaseProjects = (from path in releasePaths | 623 return releaseProjects = (from path in releasePaths |
592 select new Project(path)).ToList(); | 624 select new Project(path)).ToList(); |
593 } | 625 } |
594 } | 626 } |
595 | 627 |
596 /// <summary>Builds the "default" repository projects.</summary> | 628 /// <summary>Builds the "default" repository projects.</summary> |
597 /// <returns><c>true</c> if the default repository was build successfull
y</returns> | 629 /// <returns><c>true</c> if the default repository was build successfull
y</returns> |
598 private bool BuildDefaultRepository() | 630 private bool BuildDefaultRepository() |
599 { | 631 { |
600 TraceSource.TraceEvent(TraceEventType.Information, "Building project
s...."); | 632 TraceSource.TraceEvent(TraceEventType.Information, "Building project
s...."); |
601 | 633 |
602 var allProjects = new List<Project>(); | 634 var allProjects = new List<Project>(); |
603 allProjects.AddRange(ReleaseProjects); | 635 allProjects.AddRange(ReleaseProjects); |
604 allProjects.Add(new Project(DefaultRepository.Combine("Src", "Google
Apis.Tests", | 636 allProjects.Add(new Project(DefaultRepository.Combine("Src", "Google
Apis.Tests", |
605 "GoogleApis.Tests.csproj"))); | 637 "GoogleApis.Tests.csproj"))); |
606 allProjects.Add(new Project(DefaultRepository.Combine("Src", "Google
Apis.Authentication.OAuth2.Tests", | 638 allProjects.Add(new Project(DefaultRepository.Combine("Src", "Google
Apis.Authentication.OAuth2.Tests", |
607 "GoogleApis.Authentication.OAuth2.Tests.csproj"))); | 639 "GoogleApis.Authentication.OAuth2.Tests.csproj"))); |
| 640 allProjects.Add(new Project(DefaultRepository.Combine("Src", "Google
Apis.Auth.Tests", |
| 641 "GoogleApis.Auth.Tests.csproj"))); |
608 | 642 |
609 foreach (var project in allProjects) | 643 foreach (var project in allProjects) |
610 { | 644 { |
611 var name = project.GetName(); | 645 var name = project.GetName(); |
612 TraceSource.TraceEvent(TraceEventType.Information, "Replacing ve
rsion for {0}", name); | 646 TraceSource.TraceEvent(TraceEventType.Information, "Replacing ve
rsion for {0}", name); |
613 project.ReplaceVersion(options.Version); | 647 project.ReplaceVersion(options.Version); |
614 project.SetProperty("Configuration", "Release"); | 648 project.SetProperty("Configuration", "Release"); |
615 TraceSource.TraceEvent(TraceEventType.Information, "Building {0}
", name); | 649 TraceSource.TraceEvent(TraceEventType.Information, "Building {0}
", name); |
616 bool success = project.Build("Build", new[] { new ConsoleLogger(
LoggerVerbosity.Quiet) }); | 650 bool success = project.Build("Build", new[] { new ConsoleLogger(
LoggerVerbosity.Quiet) }); |
617 | 651 |
(...skipping 14 matching lines...) Expand all Loading... |
632 } | 666 } |
633 | 667 |
634 return true; | 668 return true; |
635 } | 669 } |
636 | 670 |
637 /// <summary>Constructs a new program with the given options.</summary> | 671 /// <summary>Constructs a new program with the given options.</summary> |
638 public Program(Options options) | 672 public Program(Options options) |
639 { | 673 { |
640 this.options = options; | 674 this.options = options; |
641 | 675 |
642 string path = Path.GetFullPath(options.OutputDirectory); | 676 string path = !string.IsNullOrEmpty(options.OutputDirectory) ? Path.
GetFullPath(options.OutputDirectory) : |
| 677 Path.Combine(Environment.CurrentDirectory, LocalRepositoryRela
tivePath); |
| 678 |
643 if (!Directory.Exists(path)) | 679 if (!Directory.Exists(path)) |
644 { | 680 { |
645 Directory.CreateDirectory(path); | 681 Directory.CreateDirectory(path); |
646 } | 682 } |
647 | 683 |
648 Environment.CurrentDirectory = path; | 684 Environment.CurrentDirectory = path; |
649 } | 685 } |
650 } | 686 } |
651 } | 687 } |
OLD | NEW |