|
14 | 14 | /// </summary> |
15 | 15 | public class VersionOracle |
16 | 16 | { |
17 | | - /// <summary> |
18 | | - /// A regex that matches on numeric identifiers for prerelease or build metadata. |
19 | | - /// </summary> |
20 | | - private static readonly Regex NumericIdentifierRegex = new Regex(@"(?<![\w-])(\d+)(?![\w-])"); |
21 | | - |
22 | 17 | /// <summary> |
23 | 18 | /// The 0.0 version. |
24 | 19 | /// </summary> |
@@ -177,7 +172,7 @@ public IEnumerable<string> BuildMetadataWithCommitId |
177 | 172 | /// <summary> |
178 | 173 | /// Gets the version options used to initialize this instance. |
179 | 174 | /// </summary> |
180 | | - private VersionOptions VersionOptions { get; } |
| 175 | + public VersionOptions VersionOptions { get; } |
181 | 176 |
|
182 | 177 | /// <summary> |
183 | 178 | /// Gets the version string to use for the <see cref="System.Reflection.AssemblyVersionAttribute"/>. |
@@ -385,22 +380,6 @@ public IDictionary<string, string> CloudBuildVersionVars |
385 | 380 | /// </summary> |
386 | 381 | public int SemVer1NumericIdentifierPadding => this.VersionOptions?.SemVer1NumericIdentifierPaddingOrDefault ?? 4; |
387 | 382 |
|
388 | | - /// <summary> |
389 | | - /// Gets the SemVer 1 format without padding or the build metadata. |
390 | | - /// </summary> |
391 | | - public string SemVer1WithoutPaddingOrBuildMetadata => |
392 | | - $"{this.Version.ToStringSafe(3)}{MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, 0)}"; |
393 | | - |
394 | | - /// <summary> |
395 | | - /// Determines if it was likely the user misconfigured their the prerelease version options and |
396 | | - /// their semver setting. |
397 | | - /// </summary> |
398 | | - /// <returns>False when NuGet SemVer 1 explicitly set but the prerelease does not match.</returns> |
399 | | - public bool MisconfiguredPrereleaseAndSemVer1() |
400 | | - { |
401 | | - return this.VersionOptions != null && this.VersionOptions.NuGetPackageVersion != null && this.VersionOptions.NuGetPackageVersion.SemVer == 1 && this.PrereleaseVersion != MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, 0); |
402 | | - } |
403 | | - |
404 | 383 | /// <summary> |
405 | 384 | /// Gets the build metadata, compliant to the NuGet-compatible subset of SemVer 1.0. |
406 | 385 | /// </summary> |
@@ -437,7 +416,7 @@ public bool MisconfiguredPrereleaseAndSemVer1() |
437 | 416 | private string SemVer2BuildMetadata => |
438 | 417 | (this.PublicRelease ? string.Empty : this.GitCommitIdShortForNonPublicPrereleaseTag) + FormatBuildMetadata(this.BuildMetadata); |
439 | 418 |
|
440 | | - private string PrereleaseVersionSemVer1 => MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, this.SemVer1NumericIdentifierPadding); |
| 419 | + private string PrereleaseVersionSemVer1 => SemanticVersionExtensions.MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, this.SemVer1NumericIdentifierPadding); |
441 | 420 |
|
442 | 421 | private string GitCommitIdShortForNonPublicPrereleaseTag => (string.IsNullOrEmpty(this.PrereleaseVersion) ? "-" : ".") + this.GitCommitIdShort; |
443 | 422 |
|
@@ -474,32 +453,6 @@ private static Version GetAssemblyVersion(Version version, VersionOptions versio |
474 | 453 | /// <returns>The specified string, with macros substituted for actual values.</returns> |
475 | 454 | private string ReplaceMacros(string prereleaseOrBuildMetadata) => prereleaseOrBuildMetadata?.Replace("{height}", this.VersionHeightWithOffset.ToString(CultureInfo.InvariantCulture)); |
476 | 455 |
|
477 | | - /// <summary> |
478 | | - /// Converts a semver 2 compliant "-beta.5" prerelease tag to a semver 1 compatible one. |
479 | | - /// </summary> |
480 | | - /// <param name="prerelease">The semver 2 prerelease tag, including its leading hyphen.</param> |
481 | | - /// <param name="paddingSize">The minimum number of digits to use for any numeric identifier.</param> |
482 | | - /// <returns>A semver 1 compliant prerelease tag. For example "-beta-0005".</returns> |
483 | | - private static string MakePrereleaseSemVer1Compliant(string prerelease, int paddingSize) |
484 | | - { |
485 | | - if (string.IsNullOrEmpty(prerelease)) |
486 | | - { |
487 | | - return prerelease; |
488 | | - } |
489 | | - |
490 | | - string paddingFormatter = "{0:" + new string('0', paddingSize) + "}"; |
491 | | - |
492 | | - string semver1 = prerelease; |
493 | | - |
494 | | - // Identify numeric identifiers and pad them. |
495 | | - Assumes.True(prerelease.StartsWith("-")); |
496 | | - semver1 = "-" + NumericIdentifierRegex.Replace(semver1.Substring(1), m => string.Format(CultureInfo.InvariantCulture, paddingFormatter, int.Parse(m.Groups[1].Value))); |
497 | | - |
498 | | - semver1 = semver1.Replace('.', '-'); |
499 | | - |
500 | | - return semver1; |
501 | | - } |
502 | | - |
503 | 456 | private static int CalculateVersionHeight(string relativeRepoProjectDirectory, LibGit2Sharp.Commit headCommit, VersionOptions committedVersion, VersionOptions workingVersion) |
504 | 457 | { |
505 | 458 | var headCommitVersion = committedVersion?.Version?.Version ?? Version0; |
|
0 commit comments