From 6393832c49dc28c06d9d10aa1f2b67fd09075050 Mon Sep 17 00:00:00 2001 From: Simon Ensslen Date: Mon, 8 Jul 2024 13:31:16 +0200 Subject: [PATCH] Allow most package information fields to be overwritten --- .../CustomPackageInformation.cs | 2 +- .../PackageInformationReader.cs | 2 +- .../PackageMetadata.cs | 19 +++++++++++-------- .../Packaging/IPackageMetadata.cs | 12 ++++++------ .../Types/CachingPackageMetadataResource.cs | 12 ++++++------ .../Protocol/WrappedPackageMetadata.cs | 12 ++++++------ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs b/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs index 3c93f68d..e19a45b5 100644 --- a/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs +++ b/src/NuGetUtility/PackageInformationReader/CustomPackageInformation.cs @@ -5,5 +5,5 @@ namespace NuGetUtility.PackageInformationReader { - public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License); + public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License, string? Copyright = null, string? Authors = null, string? Title = null, string? ProjectUrl = null, string? Summary = null, string? Description = null); } diff --git a/src/NuGetUtility/PackageInformationReader/PackageInformationReader.cs b/src/NuGetUtility/PackageInformationReader/PackageInformationReader.cs index 77c20c48..022666f8 100644 --- a/src/NuGetUtility/PackageInformationReader/PackageInformationReader.cs +++ b/src/NuGetUtility/PackageInformationReader/PackageInformationReader.cs @@ -95,7 +95,7 @@ private PackageSearchResult TryGetPackageInfoFromCustomInformation(PackageIdenti return new PackageSearchResult(); } - return new PackageSearchResult(new PackageMetadata(package, resolvedCustomInformation.License, LicenseType.Overwrite)); + return new PackageSearchResult(new PackageMetadata(package, LicenseType.Overwrite, resolvedCustomInformation)); } private static async Task TryGetPackageMetadataResource(ISourceRepository repository) diff --git a/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs b/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs index 063a93fb..ca4e3f93 100644 --- a/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs +++ b/src/NuGetUtility/PackageInformationReader/PackageMetadata.cs @@ -13,27 +13,30 @@ public PackageMetadata(PackageIdentity identity) Identity = identity; } - public PackageMetadata(PackageIdentity identity, string licenseIdentifier, LicenseType licenseType) + public PackageMetadata(PackageIdentity identity, LicenseType licenseType, CustomPackageInformation customPackageInformation) { Identity = identity; - LicenseMetadata = new LicenseMetadata(licenseType, licenseIdentifier); + LicenseMetadata = new LicenseMetadata(licenseType, customPackageInformation.License); + CustomPackageInformation = customPackageInformation; } + private CustomPackageInformation? CustomPackageInformation { get; } + public PackageIdentity Identity { get; } - public string Title { get; } = string.Empty; + public string? Title => CustomPackageInformation?.Title; public Uri? LicenseUrl => null; - public string ProjectUrl => string.Empty; + public string? ProjectUrl => CustomPackageInformation?.ProjectUrl; - public string Description => string.Empty; + public string? Description => CustomPackageInformation?.Description; - public string Summary => string.Empty; + public string? Summary => CustomPackageInformation?.Summary; - public string Copyright => string.Empty; + public string? Copyright => CustomPackageInformation?.Copyright; - public string Authors => string.Empty; + public string? Authors => CustomPackageInformation?.Authors; public LicenseMetadata? LicenseMetadata { get; } = null; } diff --git a/src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/IPackageMetadata.cs b/src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/IPackageMetadata.cs index 8f32fc24..0a251d64 100644 --- a/src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/IPackageMetadata.cs +++ b/src/NuGetUtility/Wrapper/NuGetWrapper/Packaging/IPackageMetadata.cs @@ -8,13 +8,13 @@ namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging public interface IPackageMetadata { PackageIdentity Identity { get; } - string Title { get; } + string? Title { get; } Uri? LicenseUrl { get; } - string ProjectUrl { get; } - string Description { get; } - string Summary { get; } - string Copyright { get; } - string Authors { get; } + string? ProjectUrl { get; } + string? Description { get; } + string? Summary { get; } + string? Copyright { get; } + string? Authors { get; } LicenseMetadata? LicenseMetadata { get; } } } diff --git a/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/Core/Types/CachingPackageMetadataResource.cs b/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/Core/Types/CachingPackageMetadataResource.cs index 13448189..3442185a 100644 --- a/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/Core/Types/CachingPackageMetadataResource.cs +++ b/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/Core/Types/CachingPackageMetadataResource.cs @@ -51,19 +51,19 @@ public WrappedPackageSearchMetadata(IPackageSearchMetadata searchMetadata) public PackageIdentity Identity { get; } - public string Title => _searchMetadata.Title; + public string? Title => _searchMetadata.Title; public Uri? LicenseUrl => _searchMetadata.LicenseUrl; - public string ProjectUrl => _searchMetadata.ProjectUrl?.ToString() ?? string.Empty; + public string? ProjectUrl => _searchMetadata.ProjectUrl?.ToString(); - public string Description => _searchMetadata.Description; + public string? Description => _searchMetadata.Description; - public string Summary => _searchMetadata.Summary; + public string? Summary => _searchMetadata.Summary; - public string Copyright => string.Empty; + public string? Copyright => null; - public string Authors => _searchMetadata.Authors; + public string? Authors => _searchMetadata.Authors; public LicenseMetadata? LicenseMetadata { get; } } diff --git a/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/WrappedPackageMetadata.cs b/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/WrappedPackageMetadata.cs index eeb38ae7..eabd69c0 100644 --- a/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/WrappedPackageMetadata.cs +++ b/src/NuGetUtility/Wrapper/NuGetWrapper/Protocol/WrappedPackageMetadata.cs @@ -21,19 +21,19 @@ public WrappedPackageMetadata(ManifestMetadata metadata) public PackageIdentity Identity { get; } - public string Title => _metadata.Title; + public string? Title => _metadata.Title; public Uri? LicenseUrl => _metadata.LicenseUrl; - public string ProjectUrl => _metadata.ProjectUrl?.ToString() ?? string.Empty; + public string? ProjectUrl => _metadata.ProjectUrl?.ToString(); - public string Description => _metadata.Description; + public string? Description => _metadata.Description; - public string Summary => _metadata.Summary; + public string? Summary => _metadata.Summary; - public string Copyright => _metadata.Copyright; + public string? Copyright => _metadata.Copyright; - public string Authors => string.Join(",", _metadata.Authors); // https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors + public string? Authors => string.Join(",", _metadata.Authors); // https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors public Packaging.LicenseMetadata? LicenseMetadata { get; } }