Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Use normalized semantic version in package path/name
Browse files Browse the repository at this point in the history
  • Loading branch information
troydai committed Jul 9, 2015
1 parent a44b5c4 commit cae8aab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public string GetManifestFilePath(string packageId, SemanticVersion version)
public string GetHashPath(string packageId, SemanticVersion version)
{
return Path.Combine(GetInstallPath(packageId, version),
$"{packageId}.{version}{Constants.HashFileExtension}");
$"{packageId}.{version.GetNormalizedVersionString()}{Constants.HashFileExtension}");
}

public virtual string GetPackageDirectory(string packageId, SemanticVersion version)
{
string directory = packageId;
if (_useSideBySidePaths)
{
directory = Path.Combine(directory, version.ToString());
directory = Path.Combine(directory, version.GetNormalizedVersionString());
}
return directory;
}
Expand All @@ -74,7 +74,7 @@ public virtual string GetPackageFileName(string packageId, SemanticVersion versi
string fileNameBase = packageId;
if (_useSideBySidePaths)
{
fileNameBase += "." + version;
fileNameBase += "." + version.GetNormalizedVersionString();
}
return fileNameBase + Constants.PackageExtension;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.Framework.Runtime/NuGet/SemanticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public string SpecialVersion

public string OriginalString { get; }

public string GetNormalizedVersionString()
{
var revision = Version.Revision > 0 ? ("." + Version.Revision.ToString(CultureInfo.InvariantCulture)) : string.Empty;
var specialVer = !string.IsNullOrEmpty(SpecialVersion) ? ("-" + SpecialVersion) : string.Empty;

// SemanticVersion normalizes the missing components to 0.
return $"{Version.Major}.{Version.Minor}.{Version.Build}{revision}{specialVer}";
}

public string[] GetOriginalVersionComponents()
{
if (!string.IsNullOrEmpty(OriginalString))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using NuGet;
using Xunit;

namespace Microsoft.Framework.Runtime.Tests.NuGet
{
public class SemanticVersionTests
{
public static IEnumerable<object[]> NormalizedVersionStringTestData
{
get
{
yield return new object[] { new SemanticVersion(1, 0, 0, 0), "1.0.0" };
yield return new object[] { new SemanticVersion(1, 5, 0, 0), "1.5.0" };
yield return new object[] { new SemanticVersion(1, 5, 1, 0), "1.5.1" };
yield return new object[] { new SemanticVersion(1, 5, 1, 1), "1.5.1.1" };
yield return new object[] { new SemanticVersion("1.0"), "1.0.0" };
yield return new object[] { new SemanticVersion("1.0.0"), "1.0.0" };
yield return new object[] { new SemanticVersion("1.0.0.0"), "1.0.0" };
yield return new object[] { new SemanticVersion("1.0.0.2"), "1.0.0.2" };
yield return new object[] { new SemanticVersion("1.0.0.2-beta"), "1.0.0.2-beta" };
yield return new object[] { new SemanticVersion("1.0.0.0-beta"), "1.0.0-beta" };
yield return new object[] { new SemanticVersion("1.0.0-beta"), "1.0.0-beta" };
}
}

[Theory]
[MemberData(nameof(NormalizedVersionStringTestData))]
public void TestGetNormalizeVersionString(SemanticVersion version, string expectation)
{
Assert.Equal(expectation, version.GetNormalizedVersionString());
}
}
}

0 comments on commit cae8aab

Please sign in to comment.