-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
652 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2013 Imre Pühvel, AS Nortal | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
This file is from project https://github.com/NortalLTD/AssemblyVersioning, Nortal.Utilities.AssemblyVersioning, file 'GenerateExtendedAssemblyInfoTask.cs'. | ||
*/ | ||
|
||
using Nortal.Utilities.TextTemplating; | ||
using System; | ||
|
||
namespace Nortal.Utilities.AssemblyVersioning.Generators | ||
{ | ||
/// <summary> | ||
/// Version generator which takes a custom format from context argument and injects the placeholders in format with values from model. | ||
/// </summary> | ||
public sealed class CustomVersionGenerator : IVersionGenerator | ||
{ | ||
public string GenerateVersionInfoFrom(VersionGenerationContext context) | ||
{ | ||
if (context == null) { throw new ArgumentNullException("context"); } | ||
|
||
String customFormat = context.VersionGenerationArgument; | ||
if (String.IsNullOrEmpty(customFormat)) { throw new ArgumentException("Custom format requested but no format was provided in VersionGenerationArgument.", "context"); } | ||
|
||
var model = new CustomizedVersionModel(context); | ||
|
||
SyntaxSettings settings = new SyntaxSettings() | ||
{ | ||
BeginTag = "{", | ||
EndTag = "}", | ||
}; | ||
|
||
var templateEngine = new TemplateProcessingEngine(settings); | ||
String result = templateEngine.Process(customFormat, model); | ||
return result; | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
AssemblyVersioning/Generators/CustomVersionGeneratorModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2013 Imre Pühvel, AS Nortal | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
This file is from project https://github.com/NortalLTD/AssemblyVersioning, Nortal.Utilities.AssemblyVersioning, file 'GenerateExtendedAssemblyInfoTask.cs'. | ||
*/ | ||
|
||
using System; | ||
|
||
namespace Nortal.Utilities.AssemblyVersioning.Generators | ||
{ | ||
public sealed class CustomizedVersionModel | ||
{ | ||
public CustomizedVersionModel(VersionGenerationContext context) | ||
{ | ||
if (context == null) { throw new ArgumentNullException("context"); } | ||
this.Context = context; | ||
} | ||
|
||
// storage for model properties | ||
private VersionGenerationContext Context { get; set; } | ||
private DateTime FixedNow = DateTime.Now; // to ensure it does not change between multiple calls | ||
private DateTime FixedUtcNow = DateTime.UtcNow; // to ensure it does not change between multiple calls | ||
|
||
// BaseVersion parts: | ||
public int Major { get { return this.Context.BaseVersion.Major; } } | ||
public int Minor { get { return this.Context.BaseVersion.Minor; } } | ||
public int Build { get { return this.Context.BaseVersion.Build; } } | ||
public int Revision { get { return this.Context.BaseVersion.Revision; } } | ||
|
||
// date components: | ||
public DateTime Now { get { return this.FixedNow; } } | ||
public int DateNumber { get { return DateToVersionNumberCalculation.BuildDatePart(this.FixedNow); } } | ||
public int TimeNumber { get { return DateToVersionNumberCalculation.BuildTimePart(this.FixedNow); } } | ||
|
||
public DateTime UtcNow { get { return this.FixedUtcNow; } } | ||
public int UtcDateNumber { get { return DateToVersionNumberCalculation.BuildDatePart(this.FixedUtcNow); } } | ||
public int UtcTimeNumber { get { return DateToVersionNumberCalculation.BuildTimePart(this.FixedUtcNow); } } | ||
|
||
// user context: | ||
public String BuildConfiguration { get { return this.Context.BuildConfiguration; } } | ||
|
||
// Environment | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] | ||
public String Domain { get { return Environment.UserDomainName; } } | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] | ||
public String UserName { get { return Environment.UserName; } } | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] | ||
public String MachineName { get { return Environment.MachineName; } } | ||
|
||
//Custom fields that are filled from MsBuild side | ||
public String CustomField1 { get { return this.Context.CustomField1; } } | ||
public String CustomField2 { get { return this.Context.CustomField2; } } | ||
public String CustomField3 { get { return this.Context.CustomField3; } } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
AssemblyVersioning/Generators/DateToVersionNumberCalculation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Nortal.Utilities.AssemblyVersioning.Generators | ||
{ | ||
internal static class DateToVersionNumberCalculation | ||
{ | ||
internal static int BuildDatePart(DateTime forTime) | ||
{ | ||
//last digit mod 6 (max value in version component is 65536). Ex: 2016 -> 6; 2017 -> 0 | ||
int yearpart = forTime.Year % 10 % 7; | ||
return yearpart * 10000 + 100 * forTime.Month + forTime.Day; | ||
} | ||
|
||
internal static int BuildTimePart(DateTime forTime) | ||
{ | ||
return forTime.Hour * 100 + forTime.Minute; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.