Skip to content

Commit 098b031

Browse files
committed
Add support for NuGet components in containers
1 parent 32c05fb commit 098b031

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
2+
3+
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
5+
using Microsoft.ComponentDetection.Contracts.TypedComponent;
6+
using Microsoft.ComponentDetection.Detectors.Linux.Contracts;
7+
8+
/// <summary>
9+
/// Factory for creating <see cref="NuGetComponent"/> instances from .NET package artifacts.
10+
/// </summary>
11+
public class DotnetComponentFactory : ArtifactComponentFactoryBase
12+
{
13+
/// <inheritdoc/>
14+
public override IEnumerable<string> SupportedArtifactTypes => ["dotnet"];
15+
16+
/// <inheritdoc/>
17+
public override TypedComponent? CreateComponent([NotNull] ArtifactElement artifact, [NotNull] Distro distro)
18+
{
19+
if (string.IsNullOrWhiteSpace(artifact.Name) || string.IsNullOrWhiteSpace(artifact.Version))
20+
{
21+
return null;
22+
}
23+
24+
var author = GetAuthorFromArtifact(artifact);
25+
var authors = string.IsNullOrWhiteSpace(author) ? null : new[] { author };
26+
27+
return new NuGetComponent(
28+
name: artifact.Name,
29+
version: artifact.Version,
30+
authors: authors);
31+
}
32+
}

src/Microsoft.ComponentDetection.Detectors/linux/LinuxApplicationLayerDetector.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ ILogger<LinuxApplicationLayerDetector> logger
3030
Enum.GetName(typeof(DetectorClass), DetectorClass.Linux),
3131
Enum.GetName(typeof(DetectorClass), DetectorClass.Npm),
3232
Enum.GetName(typeof(DetectorClass), DetectorClass.Pip),
33+
Enum.GetName(typeof(DetectorClass), DetectorClass.NuGet),
3334
];
3435

3536
/// <inheritdoc/>
3637
public new IEnumerable<ComponentType> SupportedComponentTypes =>
37-
[ComponentType.Linux, ComponentType.Npm, ComponentType.Pip];
38+
[ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet];
3839

3940
/// <inheritdoc/>
4041
protected override ISet<ComponentType> GetEnabledComponentTypes() =>
41-
new HashSet<ComponentType> { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip };
42+
new HashSet<ComponentType> { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet };
4243
}

src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
105105
services.AddSingleton<IArtifactComponentFactory, LinuxComponentFactory>();
106106
services.AddSingleton<IArtifactComponentFactory, NpmComponentFactory>();
107107
services.AddSingleton<IArtifactComponentFactory, PipComponentFactory>();
108+
services.AddSingleton<IArtifactComponentFactory, DotnetComponentFactory>();
108109
services.AddSingleton<IArtifactFilter, Mariner2ArtifactFilter>();
109110
services.AddSingleton<IComponentDetector, LinuxContainerDetector>();
110111
services.AddSingleton<IComponentDetector, LinuxApplicationLayerDetector>();

0 commit comments

Comments
 (0)