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

Add deprecations for component.author and metadata.manufacture #343

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/CycloneDX.Core/BomUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ internal static Bom CopyBomAndDowngrade(Bom bom)

EnumerateAllComponents(bomCopy, (component) =>
{
#pragma warning disable 618
component.Author = null;
#pragma warning restore 618
component.MimeType = null;
component.Supplier = null;
component.Swid = null;
Expand Down Expand Up @@ -477,7 +479,12 @@ public static void EnumerateAllLicenseChoices(Bom bom, Action<LicenseChoice> cal

public static void EnumerateAllOrganizationalEntity(Bom bom, Action<OrganizationalEntity> callback)
{
if (bom.Metadata?.Manufacture != null) callback(bom.Metadata.Manufacture);
#pragma warning disable 618
if (bom.Metadata?.Manufacture != null)
{
callback(bom.Metadata.Manufacture);
}
#pragma warning restore 618
if (bom.Metadata?.Supplier != null) callback(bom.Metadata.Supplier);

if (bom.Annotations != null)
Expand Down
12 changes: 11 additions & 1 deletion src/CycloneDX.Core/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ public enum ComponentScope
public List<OrganizationalContact> Authors { get; set; }
public bool ShouldSerializeAuthors() { return Authors?.Count > 0; }

[XmlElement("author")]
[Obsolete("This will be removed in a future version. Use @.authors or @.manufacturer instead.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should be manufacture like property name.

Copy link
Contributor Author

@andreas-hilti andreas-hilti Sep 7, 2024

Choose a reason for hiding this comment

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

@thompson-tomo Sorry, I don't understand your comment. The obsolete comment is a one-to-one copy from the specification:
https://cyclonedx.org/docs/1.6/json/#components_items_author

[XmlIgnore]
[ProtoMember(5)]
public string Author { get; set; }

#pragma warning disable 618
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlElement("author")]
[JsonIgnore]
public string Author_Xml { get { return Author; } set { Author = value; } }
public bool ShouldSerializeAuthor_Xml() { return Author != null; }
#pragma warning restore 618


[XmlElement("publisher")]
[ProtoMember(6)]
public string Publisher { get; set; }
Expand Down
12 changes: 11 additions & 1 deletion src/CycloneDX.Core/Models/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@ public List<Tool> ProtobufTools
public OrganizationalEntity Manufacturer { get; set; }
public bool ShouldSerializeManufacturer() { return Manufacturer != null; }

[XmlElement("manufacture")]
[Obsolete("This will be removed in a future version.Use the @.component.manufacturer instead.")]
[XmlIgnore]
[ProtoMember(5)]
public OrganizationalEntity Manufacture { get; set; }

#pragma warning disable 618
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlElement("manufacture")]
[JsonIgnore]
public OrganizationalEntity Manufacture_Xml { get { return Manufacture; } set { Manufacture = value; } }
public bool ShouldSerializeManufacture_Xml() { return Manufacture != null; }
#pragma warning restore 618


[XmlElement("supplier")]
[ProtoMember(6)]
public OrganizationalEntity Supplier { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ public static void AddSpdxPackages(this Bom bom, SpdxDocument doc)
var originatorMatch = originatorRegex.Match(package.Originator);
if (originatorMatch.Success)
{
#pragma warning disable 618
component.Author = originatorMatch.Groups["name"].ToString();
#pragma warning restore 618
if (package.Originator.ToLowerInvariant().StartsWith("organization:"))
{
#pragma warning disable 618
component.Properties.AddSpdxElement(PropertyTaxonomy.PACKAGE_ORIGINATOR_ORGANIZATION, component.Author);
#pragma warning restore 618
}
component.Properties.AddSpdxElement(PropertyTaxonomy.PACKAGE_ORIGINATOR_EMAIL, originatorMatch.Groups["email"].ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public static void AddCycloneDXComponents(this SpdxDocument doc, Bom bom)

// Package Originator
package.Originator = component.Properties?.GetSpdxElement(PropertyTaxonomy.PACKAGE_ORIGINATOR) ?? "NOASSERTION";
#pragma warning disable 618
if (component.Author != null)
{
if (component.Author == component.Properties?.GetSpdxElement(PropertyTaxonomy.PACKAGE_ORIGINATOR_ORGANIZATION))
Expand All @@ -147,7 +148,7 @@ public static void AddCycloneDXComponents(this SpdxDocument doc, Bom bom)
package.Originator = $"Person: {component.Author} ({component.Properties?.GetSpdxElement(PropertyTaxonomy.PACKAGE_ORIGINATOR_EMAIL) ?? ""})";
}
}

#pragma warning restore 618
package.Supplier = component.Properties?.GetSpdxElement(PropertyTaxonomy.PACKAGE_SUPPLIER) ?? "NOASSERTION";
if (component.Supplier != null)
{
Expand Down
Loading