Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 #145

Merged
merged 16 commits into from
Mar 30, 2017
Merged

Update feed2catalog and catalog2registration to properly handle SemVer 2.0.0 #145

merged 16 commits into from
Mar 30, 2017

Conversation

joelverhagen
Copy link
Member

  1. Write full version to catalog entry JSON
  2. Use normalized version for catalog URLs
  3. Use normalized version for downloading packages from the gallery
  4. Use normalized version for registration URLs and min/max ranges
  5. Write full version to registration entry JSON
  6. Write SemVer 2.0.0 packages to a new registration container

Addresses NuGet/NuGetGallery#3560 and NuGet/NuGetGallery#3680.

@joelverhagen
Copy link
Member Author

🔔

@joelverhagen
Copy link
Member Author

Will rebase to fix merge conflict. 🔔

@joelverhagen
Copy link
Member Author

Rebased. Ready for some 👀

}

public static bool IsGraphSemVer2(string version, string resourceUri, IGraph graph)
{
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

: base(index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, handlerFunc)
{
_storageFactory = storageFactory;
_semVer1StorageFactory = semVer1StorageFactory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: technically, it is not a SemVer v1.0 storage factory, as it may also contain System.Versioning-style packages. Perhaps rename to legacyStorageFactory, or fallbackStorageFactory, or something along those lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy seems right. However I think our the definition in NuGet world is always going to be blurred. For example 1.0.0.1-alpha.1 is considered "SemVer 2.0.0" by NuGet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -40,22 +42,17 @@ public string LowerCase(string original)

public string NormalizeVersion(string original)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need those thin wrappers? Can use NuGetVersionUtility directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to wrap thinly here because XsltHelper needs to be called via an instance method. NuGetVersionUtility is static so it's easily consumable by different jobs.

using System;
using System.Collections.Generic;
using System.Linq;
using VDS.RDF;

namespace NuGet.Services.Metadata.Catalog.Registration
{
public delegate bool ShouldIncludeRegistrationPackage(RegistrationEntryKey key, string resourceUri, IGraph graph);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the delegate inside ShouldIncludeRegistrationPackage. Will make the code more readable.
Also, it's not clear how it's used. You can improve the name or add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by:

move the delegate inside ShouldIncludeRegistrationPackage

The delegate itself is called ShouldIncludeRegistrationPackage. I chose not to put it inside RegistrationCatalogEntry because this delegate is passed from a couple levels up, which do not have knowledge of RegistrationCatalogEntry.

In general, delegates are just types so I see no reason why they should be nested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to move it inside RegistrationCatalogEntry, but I agree with your logic. However, the name is still confusing and needs a comment/better name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest revision has XML docs now.

{
return RegistrationMaker.Process(
await RegistrationMaker.Process(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add named parameters to improve readability

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

: base(index, new Uri[] { Schema.DataTypes.PackageDetails, Schema.DataTypes.PackageDelete }, handlerFunc)
{
_storageFactory = storageFactory;
_semVer1StorageFactory = semVer1StorageFactory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null checks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@skofman1
Copy link
Contributor

:shipit:

Copy link

@scottbommarito scottbommarito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicks

@@ -60,10 +68,11 @@ protected override void Init(IDictionary<string, string> arguments, Cancellation

var contentBaseAddress = arguments.GetOrDefault<string>(Arguments.ContentBaseAddress);

StorageFactory storageFactoryToUse;
StorageFactory legacyStorageFactory;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be worthwhile to have a comment here (and potentially in RegistrationCollector as well) about what precisely is "legacy" about the legacyStorageFactory.

As far as I understand, the legacyStorageFactory writes non-gzipped non-semver2 registration blobs and gzipped non-semver2 registration blobs. These are considered legacy because vCurrent nuget.exe always reads the gzipped semver2 registration blobs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

{
// Arrange
var graph = InitializeGraph(ResourceUri, Id, Version);
var isDelegateInvoked = false;
Copy link

@scottbommarito scottbommarito Mar 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: use a helper function/class to share the delegate code between tests

private class IsDelegateInvokedHelper
{
    public IsDelegateInvokedHelper()
    {
        IsDelegateInvoked = false;
        ShouldInclude = (k, u, g) => { ... }
    }

    public ShouldIncludeRegistrationPackage ShouldInclude { get; private set; }
    public bool IsDelegateInvoked {get; private set; }
}

Listed = false,

Created = new DateTime(2015, 1, 1),
LastEdited = new DateTime(2015, 1, 1),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:

I understand the other ODataPackages do this as well, but I don't think it's possible to have a Created and LastEdited be the exact same. We should probably test realistic values rather than those that cannot happen.

public async Task CreatesRegistrationsWithSemVer2()
{
// Arrange
var catalogStorage = Catalogs.CreateTestCatalogWithSemVer2Package();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:

a lot of the code here is nearly identical to that in SharedInit, just with the added SemVer2 storage. I would suggest modifying SharedInit to support SemVer2 storage as well (private void SharedInit(bool useSemVer2).

public async Task IgnoresSemVer2Packages()
{
// Arrange
var catalogStorage = Catalogs.CreateTestCatalogWithSemVer2Package();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SharedInit?

{ Arguments.StorageType, storageType},
{ Arguments.UseCompressedStorage, "false"}
{ Arguments.StorageType, storageType },
{ Arguments.UseCompressedStorage, "false" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos in method names in this class
AzureCommpressedFactoryNull -> AzureCompressedFactoryNull
AzureCommpressedFactory -> AzureCompressedFactory

@@ -61,12 +61,12 @@ internal class TestLogger : ILogger
{
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{
Console.WriteLine($"{logLevel}: {formatter(state, exception)}");
// Console.WriteLine($"{logLevel}: {formatter(state, exception)}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing tests to have a lot of stdout (locally and on CI). 99% of the time, you only fail about the failure result, not the stdout.

@joelverhagen joelverhagen changed the base branch from dev to semver2 March 30, 2017 16:20
@joelverhagen joelverhagen merged commit 47f4f0d into NuGet:semver2 Mar 30, 2017
@joelverhagen joelverhagen deleted the semver2-reg branch March 30, 2017 16:21
@joelverhagen
Copy link
Member Author

Merged into "semver2" feature branch until I do some more validation.

joelverhagen added a commit that referenced this pull request Apr 3, 2017
…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
joelverhagen added a commit that referenced this pull request Apr 4, 2017
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants