Skip to content

Commit 3997028

Browse files
committed
(#59) Add property to IChocolateyPackageSearchMetadata
This commit adds a new property to the IChocolateyPackageSearchMetadata interface, and implements this property on all instances of this interface. This is required, since we need a mechanism to store the information about _where_ a package was located. When running the FindPackage method in Chocolatey.CLI, the retured metadata class doesn't have this information, however, at the time of calling this method, we do know what source is being used, so we can record this information, we just need a property to store it. Once stored, it can then be retrieved furhter upstream as/when required. Typically, properties on the IChocolateyPackageSearchMetadata interface don't have a public set, since they are typically initialised when being created, however, since we are only setting this property once the meta data is returned, we need there to be a public set method for this property. Due to a failing build on GitHub Actions, the CA1416 entry has been added to the NoWarn attribute in the props file, so that the build does not fail. It is unclear why this is now causing a problem, when it wasn't before, but it was felt that this was a safe change, since an override for this warning already exists when running the build in a different environment.
1 parent 86f60fd commit 3997028

File tree

13 files changed

+54
-2
lines changed

13 files changed

+54
-2
lines changed

build/common.project.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<MicroBuildDirectory>$(SolutionPackagesFolder)microsoft.visualstudioeng.microbuild.core\1.0.0\build\</MicroBuildDirectory>
5151
<MicrosoftDotNetBuildTasksFeedFilePath>$(SolutionPackagesFolder)microsoft.dotnet.build.tasks.feed\6.0.0-beta.20528.5\tools\netcoreapp2.1\Microsoft.DotNet.Build.Tasks.Feed.dll</MicrosoftDotNetBuildTasksFeedFilePath>
5252
<MicrosoftDotNetMaestroTasksFilePath>$(SolutionPackagesFolder)microsoft.dotnet.maestro.tasks\1.1.0-beta.21378.2\tools\netcoreapp3.1\Microsoft.DotNet.Maestro.Tasks.dll</MicrosoftDotNetMaestroTasksFilePath>
53-
<NoWarn>$(NoWarn);NU5105;MSB3277</NoWarn>
53+
<NoWarn>$(NoWarn);NU5105;MSB3277;CA1416</NoWarn>
5454
<!-- additional warnings new in .NET 6 that we need to disable when building with source-build -->
5555
<NoWarn Condition="'$(DotNetBuildFromSource)' == 'true'">$(NoWarn);CS1998;CA1416;CS0618;CS1574</NoWarn>
5656
</PropertyGroup>
@@ -295,7 +295,7 @@
295295
$(RepositoryRootDirectory)src\NuGet.Core\NuGet.Versioning\NuGet.Versioning.csproj;
296296
$(RepositoryRootDirectory)src\NuGet.Core\NuGet.Credentials\NuGet.Credentials.csproj;
297297
$(RepositoryRootDirectory)src\NuGet.Core\NuGet.LibraryModel\\NuGet.LibraryModel.csproj;"/>
298-
298+
299299
<CoreUnitTestProjects Include="$(RepositoryRootDirectory)test\NuGet.Core.Tests\NuGet.Commands.Test\NuGet.Commands.Test.csproj;
300300
$(RepositoryRootDirectory)test\NuGet.Core.Tests\NuGet.Common.Test\NuGet.Common.Test.csproj;
301301
$(RepositoryRootDirectory)test\NuGet.Core.Tests\NuGet.Configuration.Test\NuGet.Configuration.Test.csproj;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
#nullable enable
2+
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.AvailableVersionSource.get -> string!
3+
NuGet.VisualStudio.Internal.Contracts.TransitivePackageSearchMetadata.AvailableVersionSource.set -> void

src/NuGet.Clients/NuGet.VisualStudio.Internal.Contracts/TransitivePackageSearchMetadata.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public partial class TransitivePackageSearchMetadata : IPackageSearchMetadata
6363

6464
public bool PrefixReserved => _packageSearchMetadata.PrefixReserved;
6565

66+
public string AvailableVersionSource
67+
{
68+
get => _packageSearchMetadata.AvailableVersionSource;
69+
set => _packageSearchMetadata.AvailableVersionSource = value;
70+
}
71+
6672
public LicenseMetadata LicenseMetadata => _packageSearchMetadata.LicenseMetadata;
6773

6874
public IEnumerable<PackageVulnerabilityMetadata> Vulnerabilities => _packageSearchMetadata.Vulnerabilities;

src/NuGet.Core/NuGet.Protocol/Model/ChocolateyLocalPackageSearchMetadata.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,10 @@ public Uri BugTrackerUrl
187187
/// Not applicable to local packages
188188
/// </remarks>
189189
public string PackageScanFlagResult => null;
190+
191+
/// <remarks>
192+
/// Not applicable to local packages
193+
/// </remarks>
194+
public string AvailableVersionSource { get; set; }
190195
}
191196
}

src/NuGet.Core/NuGet.Protocol/Model/ChocolateyPackageSearchMetadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ public partial class PackageSearchMetadata : IPackageSearchMetadata
7676
public DateTime? PackageScanResultDate { get; set; }
7777
[JsonIgnore]
7878
public string PackageScanFlagResult { get; set; }
79+
[JsonIgnore]
80+
public string AvailableVersionSource { get; set; }
7981
}
8082
}

src/NuGet.Core/NuGet.Protocol/Model/ChocolateyPackageSearchMetadataV2Feed.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public IEnumerable<DownloadCache> DownloadCache
8585
public string PackageScanStatus { get; private set; }
8686
public DateTime? PackageScanResultDate { get; private set; }
8787
public string PackageScanFlagResult { get; private set; }
88+
public string AvailableVersionSource { get; set; }
8889

8990
private void FinishInitialization(V2FeedPackageInfo package)
9091
{

src/NuGet.Core/NuGet.Protocol/Model/IChocolateyPackageSearchMetadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ public partial interface IPackageSearchMetadata
4444
string PackageScanStatus { get; }
4545
DateTime? PackageScanResultDate { get; }
4646
string PackageScanFlagResult { get; }
47+
48+
string AvailableVersionSource { get; set; }
4749
}
4850
}

src/NuGet.Core/NuGet.Protocol/Model/PackageSearchMetadataBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public partial class ClonedPackageSearchMetadata : IPackageSearchMetadata
7777
[Obsolete("PackagePath is recommended in place of PackageReader")]
7878
public Func<PackageReaderBase> PackageReader { get; set; }
7979
public string PackagePath { get; set; }
80+
public string AvailableVersionSource { get; set; }
8081
}
8182

8283
private PackageSearchMetadataBuilder(IPackageSearchMetadata metadata)
@@ -168,6 +169,7 @@ public IPackageSearchMetadata Build()
168169
PackageScanStatus = _metadata.PackageScanStatus,
169170
PackageScanResultDate = _metadata.PackageScanResultDate,
170171
PackageScanFlagResult = _metadata.PackageScanFlagResult,
172+
AvailableVersionSource = _metadata.AvailableVersionSource
171173

172174
//////////////////////////////////////////////////////////
173175
// End - Chocolatey Specific Modification
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
NuGet.Protocol.Core.Types.IPackageSearchMetadata.AvailableVersionSource.get -> string
2+
NuGet.Protocol.Core.Types.IPackageSearchMetadata.AvailableVersionSource.set -> void
3+
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.AvailableVersionSource.get -> string
4+
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.AvailableVersionSource.set -> void
5+
NuGet.Protocol.LocalPackageSearchMetadata.AvailableVersionSource.get -> string
6+
NuGet.Protocol.LocalPackageSearchMetadata.AvailableVersionSource.set -> void
7+
NuGet.Protocol.PackageSearchMetadata.AvailableVersionSource.get -> string
8+
NuGet.Protocol.PackageSearchMetadata.AvailableVersionSource.set -> void
9+
NuGet.Protocol.PackageSearchMetadataV2Feed.AvailableVersionSource.get -> string
10+
NuGet.Protocol.PackageSearchMetadataV2Feed.AvailableVersionSource.set -> void
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
NuGet.Protocol.Core.Types.IPackageSearchMetadata.AvailableVersionSource.get -> string
2+
NuGet.Protocol.Core.Types.IPackageSearchMetadata.AvailableVersionSource.set -> void
3+
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.AvailableVersionSource.get -> string
4+
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.AvailableVersionSource.set -> void
5+
NuGet.Protocol.LocalPackageSearchMetadata.AvailableVersionSource.get -> string
6+
NuGet.Protocol.LocalPackageSearchMetadata.AvailableVersionSource.set -> void
7+
NuGet.Protocol.PackageSearchMetadata.AvailableVersionSource.get -> string
8+
NuGet.Protocol.PackageSearchMetadata.AvailableVersionSource.set -> void
9+
NuGet.Protocol.PackageSearchMetadataV2Feed.AvailableVersionSource.get -> string
10+
NuGet.Protocol.PackageSearchMetadataV2Feed.AvailableVersionSource.set -> void

0 commit comments

Comments
 (0)