Skip to content

Commit 6b57052

Browse files
committed
Add support for NuGet components in containers
1 parent 079b805 commit 6b57052

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-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/LinuxContainerDetector.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ public class LinuxContainerDetector(ILinuxScanner linuxScanner, IDockerService d
3636
public IEnumerable<string> Categories => [
3737
Enum.GetName(typeof(DetectorClass), DetectorClass.Linux),
3838
Enum.GetName(typeof(DetectorClass), DetectorClass.Npm),
39-
Enum.GetName(typeof(DetectorClass), DetectorClass.Pip)
39+
Enum.GetName(typeof(DetectorClass), DetectorClass.Pip),
40+
Enum.GetName(typeof(DetectorClass), DetectorClass.NuGet)
4041
];
4142

4243
/// <inheritdoc/>
4344
public IEnumerable<ComponentType> SupportedComponentTypes => [
4445
ComponentType.Linux,
4546
ComponentType.Npm,
46-
ComponentType.Pip
47+
ComponentType.Pip,
48+
ComponentType.NuGet
4749
];
4850

4951
/// <inheritdoc/>

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

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

0 commit comments

Comments
 (0)