New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
if not specified in HOCON, set AppVersion to executing assembly version #4618
Changes from all commits
fd9416e
95e8afa
be5ac05
0620ddc
758f7c3
130f85b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using Akka.Configuration; | ||
using Newtonsoft.Json; | ||
|
||
namespace Akka.Util | ||
|
@@ -32,20 +34,50 @@ namespace Akka.Util | |
public class AppVersion : IComparable<AppVersion>, IEquatable<AppVersion> | ||
{ | ||
public static readonly AppVersion Zero = new AppVersion("0.0.0"); | ||
|
||
// made internal for testing purposes | ||
internal const string AssemblyVersionMarker = "assembly-version"; | ||
private const int Undefined = 0; | ||
|
||
private int[] numbers = Array.Empty<int>(); | ||
private string rest = ""; | ||
private int[] _numbers = Array.Empty<int>(); | ||
private string _rest = ""; | ||
|
||
[JsonConstructor] | ||
internal AppVersion(string version) | ||
{ | ||
this.Version = version; | ||
Version = version; | ||
} | ||
|
||
public static AppVersion Create(string version) | ||
{ | ||
var v = new AppVersion(version); | ||
// check to see if we're going to use the assembly-version | ||
if (version.Equals(AssemblyVersionMarker, StringComparison.InvariantCultureIgnoreCase)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check to see if we're using |
||
{ | ||
return AppVersionFromAssemblyVersion(); | ||
} | ||
|
||
var v2 = new AppVersion(version); | ||
return v2.Parse(); | ||
} | ||
|
||
/// <summary> | ||
/// INTERNAL API | ||
/// </summary> | ||
/// <remarks> | ||
/// Internal for testing purposes only. | ||
/// </remarks> | ||
internal static AppVersion AppVersionFromAssemblyVersion() | ||
{ | ||
// user hasn't specified AppVersion in HOCON | ||
// try looking it up via assembly | ||
var entryAssembly = Assembly.GetEntryAssembly(); | ||
|
||
// if the entryAssembly is null (which can happen when we're called from unmanaged code) | ||
// then fall back to the executing assembly for the version number. | ||
var targetAssembly = entryAssembly ?? Assembly.GetExecutingAssembly(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grab the |
||
|
||
var name = targetAssembly.GetName(); | ||
var v = new AppVersion($"{name.Version.Major}.{name.Version.Minor}.{name.Version.Build}"); | ||
return v.Parse(); | ||
} | ||
|
||
|
@@ -110,7 +142,7 @@ private AppVersion Parse() | |
} | ||
} | ||
|
||
if (numbers.Length == 0) | ||
if (_numbers.Length == 0) | ||
{ | ||
var nbrs = new int[4]; | ||
var segments = Version.Split('.'); | ||
|
@@ -168,8 +200,8 @@ private AppVersion Parse() | |
throw new ArgumentOutOfRangeException($"Only 3 digits separated with '.' are supported. [{Version}]"); | ||
} | ||
|
||
this.rest = rst; | ||
this.numbers = nbrs; | ||
this._rest = rst; | ||
this._numbers = nbrs; | ||
} | ||
return this; | ||
} | ||
|
@@ -183,24 +215,24 @@ public int CompareTo(AppVersion other) | |
Parse(); | ||
other.Parse(); | ||
var diff = 0; | ||
diff = numbers[0] - other.numbers[0]; | ||
diff = _numbers[0] - other._numbers[0]; | ||
if (diff == 0) | ||
{ | ||
diff = numbers[1] - other.numbers[1]; | ||
diff = _numbers[1] - other._numbers[1]; | ||
if (diff == 0) | ||
{ | ||
diff = numbers[2] - other.numbers[2]; | ||
diff = _numbers[2] - other._numbers[2]; | ||
if (diff == 0) | ||
{ | ||
diff = numbers[3] - other.numbers[3]; | ||
diff = _numbers[3] - other._numbers[3]; | ||
if (diff == 0) | ||
{ | ||
if (rest == "" && other.rest != "") | ||
if (_rest == "" && other._rest != "") | ||
diff = 1; | ||
if (other.rest == "" && rest != "") | ||
if (other._rest == "" && _rest != "") | ||
diff = -1; | ||
else | ||
diff = rest.CompareTo(other.rest); | ||
diff = _rest.CompareTo(other._rest); | ||
} | ||
} | ||
} | ||
|
@@ -235,11 +267,11 @@ public override int GetHashCode() | |
{ | ||
Parse(); | ||
var hashCode = 13; | ||
hashCode = (hashCode * 397) ^ numbers[0]; | ||
hashCode = (hashCode * 397) ^ numbers[1]; | ||
hashCode = (hashCode * 397) ^ numbers[2]; | ||
hashCode = (hashCode * 397) ^ numbers[3]; | ||
hashCode = (hashCode * 397) ^ rest.GetHashCode(); | ||
hashCode = (hashCode * 397) ^ _numbers[0]; | ||
hashCode = (hashCode * 397) ^ _numbers[1]; | ||
hashCode = (hashCode * 397) ^ _numbers[2]; | ||
hashCode = (hashCode * 397) ^ _numbers[3]; | ||
hashCode = (hashCode * 397) ^ _rest.GetHashCode(); | ||
return hashCode; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the default value here to
assembly-version
, which activates this assembly-scanning default behavior