Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Newtonsoft.Json;
Expand All @@ -24,6 +24,7 @@ public class TypedComponentConverter : JsonConverter
{ ComponentType.Linux, typeof(LinuxComponent) },
{ ComponentType.Conda, typeof(CondaComponent) },
{ ComponentType.DockerReference, typeof(DockerReferenceComponent) },
{ ComponentType.Vcpkg, typeof(VcpkgComponent) }
};

public override bool CanConvert(Type objectType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PackageUrl;
using PackageUrl;

namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
Expand All @@ -11,10 +11,12 @@ private VcpkgComponent()

public VcpkgComponent(string spdxid, string name, string version, string triplet = null, string portVersion = null, string description = null, string downloadLocation = null)
{
int.TryParse(portVersion, out var port);

SPDXID = ValidateRequiredInput(spdxid, nameof(SPDXID), nameof(ComponentType.Vcpkg));
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Vcpkg));
Version = version;
PortVersion = portVersion;
PortVersion = port;
Triplet = triplet;
Description = description;
DownloadLocation = downloadLocation;
Expand All @@ -32,15 +34,15 @@ public VcpkgComponent(string spdxid, string name, string version, string triplet

public string Description { get; set; }

public string PortVersion { get; set; }
public int PortVersion { get; set; }

public override ComponentType Type => ComponentType.Vcpkg;

public override string Id
{
get
{
if (PortVersion != null)
if (PortVersion > 0)
{
return $"{Name} {Version}#{PortVersion} - {Type}";
}
Expand All @@ -55,7 +57,7 @@ public override PackageURL PackageUrl
{
get
{
if (PortVersion != null)
if (PortVersion > 0)
{
return new PackageURL($"pkg:vcpkg/{Name}@{Version}?port_version={PortVersion}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task TestNlohmann()
{
""name"": ""nlohmann-json"",
""SPDXID"": ""SPDXRef-port"",
""versionInfo"": ""3.10.4"",
""versionInfo"": ""3.10.4#5"",
""downloadLocation"": ""git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json"",
""homepage"": ""https://github.com/nlohmann/json"",
""licenseConcluded"": ""NOASSERTION"",
Expand Down Expand Up @@ -67,10 +67,10 @@ public async Task TestNlohmann()
Assert.AreEqual(1, components.Count());
Assert.AreEqual("nlohmann-json", sbomComponent.Name);
Assert.AreEqual("3.10.4", sbomComponent.Version);
Assert.AreEqual("0", sbomComponent.PortVersion);
Assert.AreEqual(5, sbomComponent.PortVersion);
Assert.AreEqual("SPDXRef-port", sbomComponent.SPDXID);
Assert.AreEqual("git+https://github.com/Microsoft/vcpkg#ports/nlohmann-json", sbomComponent.DownloadLocation);
Assert.AreEqual("pkg:vcpkg/nlohmann-json@3.10.4?port_version=0", sbomComponent.PackageUrl.ToString());
Assert.AreEqual("pkg:vcpkg/nlohmann-json@3.10.4?port_version=5", sbomComponent.PackageUrl.ToString());
}

[TestMethod]
Expand Down