This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update feed2catalog and catalog2registration to properly handle SemVe…
…r 2.0.0 (#145) * Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 * Add testing for NuGetVersionUtility * Add integration tests for creation of catalog items (feed2catalog) * Add tests for PackageCatalogItem * Add unit tests for RegistrationCatalogEntry and PackagesFolderPackagePathProvider * Only call the SemVer 2.0.0 storage factory if it was provided * Add tests for the SemVer 2.0.0 storage factory * Update Feed2Catalog tests to add a SemVer2 package * Add functional tests for registration collector * Addresses NuGet/NuGetGallery#3560 * Addresses NuGet/NuGetGallery#3680
- Loading branch information
1 parent
509525c
commit 47f4f0d
Showing
40 changed files
with
1,996 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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; | ||
using NuGet.Versioning; | ||
using VDS.RDF; | ||
using VDS.RDF.Query; | ||
|
||
namespace NuGet.Services.Metadata.Catalog.Helpers | ||
{ | ||
public static class NuGetVersionUtility | ||
{ | ||
public static string NormalizeVersion(string version) | ||
{ | ||
NuGetVersion parsedVersion; | ||
if (!NuGetVersion.TryParse(version, out parsedVersion)) | ||
{ | ||
return version; | ||
} | ||
|
||
return parsedVersion.ToNormalizedString(); | ||
} | ||
|
||
public static string NormalizeVersionRange(string versionRange) | ||
{ | ||
VersionRange parsedVersionRange; | ||
if (!VersionRange.TryParse(versionRange, out parsedVersionRange)) | ||
{ | ||
return versionRange; | ||
} | ||
|
||
return parsedVersionRange.ToNormalizedString(); | ||
} | ||
|
||
public static string GetFullVersionString(string version) | ||
{ | ||
NuGetVersion parsedVersion; | ||
if (!NuGetVersion.TryParse(version, out parsedVersion)) | ||
{ | ||
return version; | ||
} | ||
|
||
return parsedVersion.ToFullString(); | ||
} | ||
|
||
public static bool IsVersionSemVer2(string version) | ||
{ | ||
NuGetVersion parsedVersion; | ||
if (!NuGetVersion.TryParse(version, out parsedVersion)) | ||
{ | ||
return false; | ||
} | ||
|
||
return parsedVersion.IsSemVer2; | ||
} | ||
|
||
public static bool IsVersionRangeSemVer2(string versionRange) | ||
{ | ||
VersionRange parsedVersionRange; | ||
if (!VersionRange.TryParse(versionRange, out parsedVersionRange)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (parsedVersionRange.HasLowerBound && parsedVersionRange.MinVersion.IsSemVer2) | ||
{ | ||
return true; | ||
} | ||
|
||
if (parsedVersionRange.HasUpperBound && parsedVersionRange.MaxVersion.IsSemVer2) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static bool IsGraphSemVer2(string version, string resourceUri, IGraph graph) | ||
{ | ||
// Is the package version itself SemVer 2.0.0? | ||
if (IsVersionSemVer2(version)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (resourceUri == null) | ||
{ | ||
throw new ArgumentNullException(nameof(resourceUri)); | ||
} | ||
|
||
if (graph == null) | ||
{ | ||
throw new ArgumentNullException(nameof(graph)); | ||
} | ||
|
||
// Are any of the dependency version ranges SemVer 2.0.0? | ||
var sparql = new SparqlParameterizedString | ||
{ | ||
CommandText = Utils.GetResource("sparql.SelectDistinctDependencyVersionRanges.rq") | ||
}; | ||
sparql.SetUri("resourceUri", new Uri(resourceUri)); | ||
var query = sparql.ToString(); | ||
|
||
TripleStore store = new TripleStore(); | ||
store.Add(graph, true); | ||
foreach (SparqlResult row in SparqlHelpers.Select(store, query)) | ||
{ | ||
var unparsedVersionRange = row["versionRange"].ToString(); | ||
if (IsVersionRangeSemVer2(unparsedVersionRange)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/Catalog/Registration/PackagesFolderPackagePathProvider.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
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
Oops, something went wrong.