-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathVcpkgComponent.cs
More file actions
81 lines (64 loc) · 2.56 KB
/
Copy pathVcpkgComponent.cs
File metadata and controls
81 lines (64 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#nullable disable
namespace Microsoft.ComponentDetection.Contracts.TypedComponent;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using PackageUrl;
public class VcpkgComponent : TypedComponent
{
public VcpkgComponent()
{
/* Reserved for deserialization */
}
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);
this.SPDXID = this.ValidateRequiredInput(spdxid, nameof(this.SPDXID), nameof(ComponentType.Vcpkg));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Vcpkg));
this.Version = version;
this.PortVersion = port;
this.Triplet = triplet;
this.Description = description;
this.DownloadLocation = downloadLocation;
}
[JsonPropertyName("spdxid")]
public string SPDXID { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("downloadLocation")]
public string DownloadLocation { get; set; }
[JsonPropertyName("triplet")]
public string Triplet { get; set; }
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("description")]
public string Description { get; set; }
[JsonPropertyName("portVersion")]
public int PortVersion { get; set; }
[JsonIgnore]
public override ComponentType Type => ComponentType.Vcpkg;
[JsonPropertyName("packageUrl")]
public override PackageURL PackageUrl
{
get
{
var qualifiers = this.PortVersion > 0
? new SortedDictionary<string, string> { { "port_version", this.PortVersion.ToString() } }
: null;
return new PackageURL("vcpkg", null, this.Name, this.Version, qualifiers, null);
}
}
protected override string ComputeBaseId()
{
var componentLocationPrefix = string.Empty;
if (!string.IsNullOrWhiteSpace(this.DownloadLocation) && !this.DownloadLocation.Trim().Equals("NONE", System.StringComparison.InvariantCultureIgnoreCase))
{
componentLocationPrefix = $"{this.DownloadLocation} : ";
}
var componentPortVersionSuffix = " ";
if (this.PortVersion > 0)
{
componentPortVersionSuffix = $"#{this.PortVersion} ";
}
return $"{componentLocationPrefix}{this.Name} {this.Version}{componentPortVersionSuffix}- {this.Type}";
}
}