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
Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 #145
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1f1a3bf
Update feed2catalog and catalog2registration to properly handle SemVe…
joelverhagen 8e38ffa
Add testing for NuGetVersionUtility
joelverhagen a6691f7
Add integration tests for creation of catalog items (feed2catalog)
joelverhagen 6e49f1d
Add tests for PackageCatalogItem
joelverhagen fa00cbf
Add unit tests for RegistrationCatalogEntry and PackagesFolderPackage…
joelverhagen 9b6acf0
Only call the SemVer 2.0.0 storage factory if it was provided
joelverhagen d9e3b5d
Add tests for the SemVer 2.0.0 storage factory
joelverhagen 43f283c
Include the new test assembly
joelverhagen 39a869f
Update Feed2Catalog tests to add a SemVer2 package
joelverhagen ee0f9cc
Add functional tests for registration collector
joelverhagen 37c7804
Fix merge
joelverhagen dbbb703
Address comments
joelverhagen 868e51b
Address comments
joelverhagen aa89b84
Polish comments
joelverhagen 7d19314
Add null checks
joelverhagen 0f5e4ce
Address comments
joelverhagen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
// 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 NuGet.Versioning; | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml; | ||
using System.Xml.XPath; | ||
using NuGet.Services.Metadata.Catalog.Helpers; | ||
using NuGet.Versioning; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
|
@@ -40,22 +42,17 @@ public string LowerCase(string original) | |
|
||
public string NormalizeVersion(string original) | ||
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. do we need those thin wrappers? Can use NuGetVersionUtility directly 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. I chose to wrap thinly here because |
||
{ | ||
NuGetVersion nugetVersion; | ||
if (NuGetVersion.TryParse(original, out nugetVersion)) | ||
{ | ||
return nugetVersion.ToNormalizedString(); | ||
} | ||
return original; | ||
return NuGetVersionUtility.NormalizeVersion(original); | ||
} | ||
|
||
public string GetFullVersionString(string original) | ||
{ | ||
return NuGetVersionUtility.GetFullVersionString(original); | ||
} | ||
|
||
public string NormalizeVersionRange(string original) | ||
{ | ||
VersionRange versionRange; | ||
if (VersionRange.TryParse(original, out versionRange)) | ||
{ | ||
return versionRange.ToString(); | ||
} | ||
return original; | ||
return NuGetVersionUtility.NormalizeVersionRange(original); | ||
} | ||
|
||
public string IsPrerelease(string original) | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
May need some argument checks on this utility class.
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.
Fixed.