Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename types/variables in the product/test code to reflect package source mapping #4281

Merged
merged 16 commits into from
Sep 28, 2021

Conversation

kartheekp-ms
Copy link
Contributor

@kartheekp-ms kartheekp-ms commented Sep 27, 2021

Bug

Fixes: NuGet/Home#11216

Regression? Last working version:

Description

PR Checklist

@kartheekp-ms kartheekp-ms requested a review from a team as a code owner September 27, 2021 23:45

namespace NuGet.Configuration
{
internal class PackageNamespacesProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant to rename this file but I forgot what user actions in the IDE lead to deleting this file and creating a new one with the name PackageSourceMappingProvider.cs

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

Seems pretty thorough to me.
Some minor feedback.

@@ -7,7 +7,7 @@

namespace NuGet.Configuration
{
public class PackageNamespacesConfiguration
public class PackageSourceMappingConfiguration
Copy link
Member

Choose a reason for hiding this comment

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

naming: Should this simply be PackageSourceMapping ?

Configuration might be superfluous?
Hoping @zivkan can provide some feedback as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

PackageSourceMappingConfiguration is too long, so above suggestion is good for me. If we do above then need to do same for PackageSourceMappingConfigurationUtility and other variables too.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I like PackageSourceMapping. Pretending that I'm working on something in restore, unrelated to the package source mapping feature, I feel like it should be sufficiently obvious it's a class that holds a mapping between package prefixes are package sources. Therefore, I don't think the name Configuration adds clarification. I also can't think why there'd be any PackageSourceMapping class in any assembly other than NuGet.Configuration, so I think it passes all the naming tests I can think of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the type to PackageSourceMapping in the latest commit which already passed all CI checks.

@@ -121,11 +121,11 @@
<value>The feed '{0}' lists package '{1}' but multiple attempts to download the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in progress. Verify the package exists on the feed and try again.</value>
</data>
<data name="Log_MatchingSourceFoundForPackage" xml:space="preserve">
<value>Package namespace matches found for package ID '{0}' are: '{1}'.</value>
<value>Package source mapping pattern matches found for package ID '{0}' are: '{1}'.</value>
Copy link
Member

Choose a reason for hiding this comment

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

You might've already done it, but I'd rather provide the feedback than risk us missing something.

Consider search for the word namespace in all resx files in our repo.

My guess is that we shouldn't have any hits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did search for namespace in all the files in the repo (that includes resx files) and could not find a keyword namespaces in the context of source mapping feature.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome! Thanks for being so thorough! Very important with a PR like this.

<comment>{0} - Package id {1} - list of sources</comment>
</data>
<data name="Log_NoMatchingSourceFoundForPackage" xml:space="preserve">
<value>Package namespace match not found for package ID '{0}'.</value>
<value>Package source mapping pattern match not found for package ID '{0}'.</value>
Copy link
Member

Choose a reason for hiding this comment

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

Is pattern still necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the pattern from the log message

<data name="PackageNamespaceNoMatchFound" xml:space="preserve">
<value>Package namespace match not found for package ID '{0}'</value>
<data name="PackageSourceMappingPatternNoMatchFound" xml:space="preserve">
<value>Package source mapping pattern match not found for package ID '{0}'</value>
Copy link
Member

Choose a reason for hiding this comment

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

If you agree with my feedback on removing pattern above, it'd apply here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed pattern from the log message.


foreach (PackageNamespacesSourceItem packageSourceNamespaceItem in packageNamespacesProvider.GetPackageSourceNamespaces())
foreach (PackageSourceMappingSourceItem packageSourceNamespaceItem in packageSourceMappingProvider.GetPackageSourceMappingItems())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe GetPackageSourceMappingPatterns could be better description of what it does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PackageSourceMappingProvider is an internal type. I think GetPackageSourceMappingItems is more apt because it returns a list of type PackageSourceMappingSourceItem. Please let me know if you disagree.

/// </summary>
public IList<NamespaceItem> Namespaces { get; }
public IList<PackagePatternItem> Patterns { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public IList<PackagePatternItem> Patterns { get; }
public IList<PackagePatternItem> SourcePatterns { get; }

Copy link
Contributor Author

@kartheekp-ms kartheekp-ms Sep 28, 2021

Choose a reason for hiding this comment

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

Given that the type name PackageSourceMappingSourceItem has Source word twice, I think just Patterns seems okay to me. Earlier it was Namespaces and I just replaced it with Patterns because the XML element <packageSource> contains a list of patterns. Please let me know your feedback. cc @nkolev92

Copy link
Member

Choose a reason for hiding this comment

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

I like Patterns.
If we were going to make it verbose, I'd argue PackagePatterns is the right name over SourcePatterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like Patterns too. If I use PackagePatterns the term Package may be repeated twice once in the type name and in the property name.

Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

1 important comment and a bunch of little ones.

@@ -382,9 +382,9 @@ private async Task<IReadOnlyList<RestoreSummary>> PerformNuGetV2RestoreAsync(Pac
cacheContext.NoCache = NoCache;
cacheContext.DirectDownload = DirectDownload;

PackageNamespacesConfiguration packageNamespacesConfiguration = PackageNamespacesConfiguration.GetPackageNamespacesConfiguration(Settings);
PackageSourceMapping packageSourceMappingConfiguration = PackageSourceMapping.GetPackageSourceMappingConfiguration(Settings);
Copy link
Member

Choose a reason for hiding this comment

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

nit: var name. Not critical.

Copy link
Member

Choose a reason for hiding this comment

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

This applies in many spots. You can consider changing these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed it in all the places using find and replace.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like there's still a bunch of these instances. Can you please double check that you committed those changes?

Copy link
Member

Choose a reason for hiding this comment

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

Bumping this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got it right this time and fixed in other places too.

/// <exception cref="ArgumentNullException"> if <paramref name="settings"/> is null.</exception>
public static PackageNamespacesConfiguration GetPackageNamespacesConfiguration(ISettings settings)
public static PackageSourceMapping GetPackageSourceMappingConfiguration(ISettings settings)
Copy link
Member

Choose a reason for hiding this comment

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

This should be GetPackageSourceMapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it when I renamed PackageSourceMappingConfiguration type to PackageSourceMapping but forgot to update the method name. thanks, Nikolche. Fixed in the next commit.

/// </summary>
public IList<NamespaceItem> Namespaces { get; }
public IList<PackagePatternItem> Patterns { get; }
Copy link
Member

Choose a reason for hiding this comment

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

I like Patterns.
If we were going to make it verbose, I'd argue PackagePatterns is the right name over SourcePatterns.

Copy link
Member

@zivkan zivkan left a comment

Choose a reason for hiding this comment

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

I looked only at the PublicAPI txt files, as they're more or less the only breaking changes. Everything else we can refactor in the future without API changes.

NuGet.Configuration.PackagePatternItem.PackagePatternItem(string pattern) -> void
NuGet.Configuration.PackagePatternItem.Pattern.get -> string
NuGet.Configuration.PackageSourceMapping
NuGet.Configuration.PackageSourceMapping.GetConfiguredPackageSources(string term) -> System.Collections.Generic.IReadOnlyList<string>
Copy link
Member

Choose a reason for hiding this comment

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

I think packageId makes more sense than term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually mostly packagePrefix than packageId, but I'm ok with packageId.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't that API the package id exactly?
It's getting the sources for a specific package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Nikolche that is correct, exact packageId is passed as parameter to this method to find out package sources associated with the longest matching prefix.

NuGet.Configuration.PackageSourceMapping.IsEnabled.get -> bool
NuGet.Configuration.PackageSourceMappingSourceItem
NuGet.Configuration.PackageSourceMappingSourceItem.PackageSourceMappingSourceItem(string name, System.Collections.Generic.IEnumerable<NuGet.Configuration.PackagePatternItem> packagePatternItems) -> void
NuGet.Configuration.PackageSourceMappingSourceItem.Patterns.get -> System.Collections.Generic.IList<NuGet.Configuration.PackagePatternItem>
Copy link
Member

Choose a reason for hiding this comment

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

Does the order of patterns matter? If not, then ICollection<T> might be a more minimalist interface for how the result is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree with this.

Using too generic interfaces like that can lead to lots of accidental and unnecessary enumerations.
We should stick with IList imo.

Copy link
Contributor Author

@kartheekp-ms kartheekp-ms Sep 28, 2021

Choose a reason for hiding this comment

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

reverted the last commit where I changed the Patterns type to ICollection

@kartheekp-ms kartheekp-ms force-pushed the dev-kartheekp-ms-renametypes-packagenamespaces branch from cc2cf41 to 779e31f Compare September 28, 2021 18:50
@@ -371,9 +371,9 @@ private CommandLineSourceRepositoryProvider GetSourceRepositoryProvider()
resolutionContext.SourceCacheContext.NoCache = NoCache;
resolutionContext.SourceCacheContext.DirectDownload = DirectDownload;

PackageNamespacesConfiguration packageNamespacesConfiguration = PackageNamespacesConfiguration.GetPackageNamespacesConfiguration(Settings);
var packageSourceMappingConfiguration = PackageSourceMapping.GetPackageSourceMapping(Settings);
Copy link
Member

Choose a reason for hiding this comment

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

nit: var naming.

Note that searching for packageSourceMappingConfiguration reveals 27 hits just on GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't change the variable names but focused on using var keyword to avoid breaking references to it. I will create a follow-up PR and fix the variable names, if needed.

Copy link
Member

Choose a reason for hiding this comment

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

My comment is not about the var keyword, it's about the naming.

It's var packageSourceMappingConfiguration, but should be var packageSourceMapping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. I will fix the variable naming in the follow-up issue. https://github.com/NuGet/Client.Engineering/issues/1219

@aortiz-msft aortiz-msft merged commit e301669 into dev Sep 28, 2021
@aortiz-msft aortiz-msft deleted the dev-kartheekp-ms-renametypes-packagenamespaces branch September 28, 2021 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename types/variables in the product/test code to reflect new name for package namespaces feature
6 participants