Skip to content

Commit

Permalink
(NuGet#9) Add package information fields
Browse files Browse the repository at this point in the history
Extend Nuspec metadata to include:

- Project source url
- Package source url
- Docs url
- Wiki Url
- Mailing List Url
- Bug Tracker Url

Adding the following elements, reserving for future use with respect to
package relationships.
- Replaces
- Provides
- Conflicts

This brings forward these commits:
chocolatey/nuget-chocolatey@9b703a8
chocolatey/nuget-chocolatey@4e28997
chocolatey/nuget-chocolatey@b9c4bc5

Co-Authored-By: Rob Reynolds <[email protected]>
  • Loading branch information
2 people authored and gep13 committed Nov 21, 2022
1 parent 245be19 commit 895238f
Show file tree
Hide file tree
Showing 16 changed files with 751 additions and 11 deletions.
73 changes: 73 additions & 0 deletions src/NuGet.Core/NuGet.Packaging/ChocolateyNuspecReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////


using NuGet.Packaging.Core;

namespace NuGet.Packaging
{
/// <summary>
/// Reads .nuspec files
/// </summary>
public partial class NuspecReader : NuspecCoreReaderBase
{
public string GetProjectSourceUrl()
{
return GetMetadataValue("projectSourceUrl");
}

public string GetPackageSourceUrl()
{
return GetMetadataValue("packageSourceUrl");
}

public string GetDocsUrl()
{
return GetMetadataValue("docsUrl");
}

public string GetWikiUrl()
{
return GetMetadataValue("wikiUrl");
}

public string GetMailingListUrl()
{
return GetMetadataValue("mailingListUrl");
}

public string GetBugTrackerUrl()
{
return GetMetadataValue("bugTrackerUrl");
}

public string GetReplaces()
{
return GetMetadataValue("replaces");
}

public string GetProvides()
{
return GetMetadataValue("provides");
}

public string GetConflicts()
{
return GetMetadataValue("conflicts");
}

public string GetSoftwareDisplayName()
{
return GetMetadataValue("softwareDisplayName");
}

public string GetSoftwareDisplayVersion()
{
return GetMetadataValue("softwareDisplayVersion");
}
}
}
15 changes: 15 additions & 0 deletions src/NuGet.Core/NuGet.Packaging/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,18 @@
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The method that raised the warning returns an IDisposable object that wraps local disposable object", Scope = "member", Target = "~M:NuGet.Packaging.NuGetExtractionFileIO.DotnetCoreCreateFile(System.String)~System.IO.FileStream")]
[assembly: SuppressMessage("Security", "IA5352:Do Not Misuse Cryptographic APIs ", Justification = "A self-issued certificate cannot be revoked.", Scope = "member", Target = "~M:NuGet.Packaging.Signing.CertificateUtility.IsSelfIssued(System.Security.Cryptography.X509Certificates.X509Certificate2)~System.Boolean")]
[assembly: SuppressMessage("Security", "IA5352:Do Not Misuse Cryptographic APIs ", Justification = "NuGet builds a certificate chain for a certificate potentially several times. Sometimes the goal is to simply have a complete chain ignoring trust. Ultimately NuGet does build the certificate chain again with the default of RevocationMode.Online later.", Scope = "member", Target = "~M:NuGet.Packaging.Signing.SignatureUtility.GetCertificateChain(System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Certificate2Collection,System.Boolean)~NuGet.Packaging.Signing.IX509CertificateChain")]

//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetDocsUrl(System.String)")]
[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetPackageSourceUrl(System.String)")]
[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetProjectSourceUrl(System.String)")]
[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetWikiUrl(System.String)")]
[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetMailingListUrl(System.String)")]
[assembly: SuppressMessage("Design", "CA1054:Uri parameters should not be strings", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.ManifestMetadata.SetBugTrackerUrl(System.String)")]

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
13 changes: 11 additions & 2 deletions src/NuGet.Core/NuGet.Packaging/NuspecReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@

namespace NuGet.Packaging
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

/// <summary>
/// Reads .nuspec files
/// </summary>
public class NuspecReader : NuspecCoreReaderBase
public partial class NuspecReader : NuspecCoreReaderBase

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

{
// node names
private const string Dependencies = "dependencies";
Expand Down Expand Up @@ -427,7 +436,7 @@ public RepositoryMetadata GetRepositoryMetadata()
/// <summary>
/// Parses the license object if specified.
/// The metadata can be of 2 types, Expression and File.
/// The method will not fail if it sees values that invalid (empty/unparseable license etc), but it will rather add validation errors/warnings.
/// The method will not fail if it sees values that invalid (empty/unparseable license etc), but it will rather add validation errors/warnings.
/// </summary>
/// <remarks>This method never throws. Bad data is still parsed. </remarks>
/// <returns>The licensemetadata if specified</returns>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Packaging
{
public partial class ManifestMetadata : IPackageMetadata
{
private IEnumerable<string> _replaces = Enumerable.Empty<string>();
private IEnumerable<string> _provides = Enumerable.Empty<string>();
private IEnumerable<string> _conflicts = Enumerable.Empty<string>();

private string _projectSourceUrl;
private string _packageSourceUrl;
private string _docsUrl;
private string _wikiUrl;
private string _mailingListUrl;
private string _bugTrackerUrl;

private void FinishContruction(IPackageMetadata copy)
{
_projectSourceUrl = copy.ProjectSourceUrl?.OriginalString;
_packageSourceUrl = copy.PackageSourceUrl?.OriginalString;
_docsUrl = copy.DocsUrl?.OriginalString;
_wikiUrl = copy.WikiUrl?.OriginalString;
_mailingListUrl = copy.MailingListUrl?.OriginalString;
_bugTrackerUrl = copy.BugTrackerUrl?.OriginalString;
Replaces = copy.Replaces;
Provides = copy.Provides;
Conflicts = copy.Conflicts;
SoftwareDisplayName = copy.SoftwareDisplayName;
SoftwareDisplayVersion = copy.SoftwareDisplayVersion;
}

public void SetProjectSourceUrl(string projectSourceUrl)
{
_projectSourceUrl = projectSourceUrl;
}

public Uri ProjectSourceUrl
{
get
{
if (_projectSourceUrl == null)
{
return null;
}

return new Uri(_projectSourceUrl);
}
}

public void SetPackageSourceUrl(string packageSourceUrl)
{
_packageSourceUrl = packageSourceUrl;
}

public Uri PackageSourceUrl
{
get
{
if (_packageSourceUrl == null)
{
return null;
}

return new Uri(_packageSourceUrl);
}
}

public void SetDocsUrl(string docsUrl)
{
_docsUrl = docsUrl;
}

public Uri DocsUrl
{
get
{
if (_docsUrl == null)
{
return null;
}

return new Uri(_docsUrl);
}
}

public void SetWikiUrl(string wikiUrl)
{
_wikiUrl = wikiUrl;
}

public Uri WikiUrl
{
get
{
if (_wikiUrl == null)
{
return null;
}

return new Uri(_wikiUrl);
}
}

public void SetMailingListUrl(string mailingListUrl)
{
_mailingListUrl = mailingListUrl;
}

public Uri MailingListUrl
{
get
{
if (_mailingListUrl == null)
{
return null;
}

return new Uri(_mailingListUrl);
}
}

public void SetBugTrackerUrl(string bugTrackerUrl)
{
_bugTrackerUrl = bugTrackerUrl;
}

public Uri BugTrackerUrl
{
get
{
if (_bugTrackerUrl == null)
{
return null;
}

return new Uri(_bugTrackerUrl);
}
}

public IEnumerable<string> Replaces
{
get { return _replaces; }
set { _replaces = value ?? Enumerable.Empty<string>(); }
}

public IEnumerable<string> Provides
{
get { return _provides; }
set { _provides = value ?? Enumerable.Empty<string>(); }
}

public IEnumerable<string> Conflicts
{
get { return _conflicts; }
set { _conflicts = value ?? Enumerable.Empty<string>(); }
}

public string SoftwareDisplayName { get; set; }

public string SoftwareDisplayVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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.

//////////////////////////////////////////////////////////
// Chocolatey Specific Modification
//////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuGet.Packaging
{
public partial class PackageBuilder : IPackageMetadata
{
public Uri ProjectSourceUrl { get; set; }
public Uri PackageSourceUrl { get; set; }
public Uri DocsUrl { get; set; }
public Uri WikiUrl { get; set; }
public Uri MailingListUrl { get; set; }
public Uri BugTrackerUrl { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>")]
public ISet<string> Replaces { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>")]
public ISet<string> Provides { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>")]
public ISet<string> Conflicts { get; set; }
public string SoftwareDisplayName { get; set; }
public string SoftwareDisplayVersion { get; set; }

IEnumerable<string> IPackageMetadata.Replaces
{
get
{
return Replaces;
}
}

IEnumerable<string> IPackageMetadata.Provides
{
get
{
return Provides;
}
}

IEnumerable<string> IPackageMetadata.Conflicts
{
get
{
return Conflicts;
}
}

private void FinishPopulate(IPackageMetadata metadata)
{
ProjectSourceUrl = metadata.ProjectSourceUrl;
PackageSourceUrl = metadata.PackageSourceUrl;
DocsUrl = metadata.DocsUrl;
WikiUrl = metadata.WikiUrl;
MailingListUrl = metadata.MailingListUrl;
BugTrackerUrl = metadata.BugTrackerUrl;
SoftwareDisplayName = metadata.SoftwareDisplayName;
SoftwareDisplayVersion = metadata.SoftwareDisplayVersion;

Replaces.AddRange(metadata.Replaces);
Provides.AddRange(metadata.Provides);
Conflicts.AddRange(metadata.Conflicts);
}

private void FinishContruction()
{
Replaces = new HashSet<string>();
Provides = new HashSet<string>();
Conflicts = new HashSet<string>();
}
}
}
Loading

0 comments on commit 895238f

Please sign in to comment.