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
@@ -0,0 +1,32 @@
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Microsoft.ComponentDetection.Detectors.Linux.Contracts;

/// <summary>
/// Factory for creating <see cref="NuGetComponent"/> instances from .NET package artifacts.
/// </summary>
public class DotnetComponentFactory : ArtifactComponentFactoryBase
{
/// <inheritdoc/>
public override IEnumerable<string> SupportedArtifactTypes => ["dotnet"];

/// <inheritdoc/>
public override TypedComponent? CreateComponent([NotNull] ArtifactElement artifact, [NotNull] Distro distro)
{
if (string.IsNullOrWhiteSpace(artifact.Name) || string.IsNullOrWhiteSpace(artifact.Version))
{
return null;
}

var author = GetAuthorFromArtifact(artifact);
var authors = string.IsNullOrWhiteSpace(author) ? null : new[] { author };

return new NuGetComponent(
name: artifact.Name,
version: artifact.Version,
authors: authors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ ILogger<LinuxApplicationLayerDetector> logger
Enum.GetName(typeof(DetectorClass), DetectorClass.Linux),
Enum.GetName(typeof(DetectorClass), DetectorClass.Npm),
Enum.GetName(typeof(DetectorClass), DetectorClass.Pip),
Enum.GetName(typeof(DetectorClass), DetectorClass.NuGet),
];

/// <inheritdoc/>
public new IEnumerable<ComponentType> SupportedComponentTypes =>
[ComponentType.Linux, ComponentType.Npm, ComponentType.Pip];
[ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet];

/// <inheritdoc/>
protected override ISet<ComponentType> GetEnabledComponentTypes() =>
new HashSet<ComponentType> { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip };
new HashSet<ComponentType> { ComponentType.Linux, ComponentType.Npm, ComponentType.Pip, ComponentType.NuGet };
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static IServiceCollection AddComponentDetection(this IServiceCollection s
services.AddSingleton<IArtifactComponentFactory, LinuxComponentFactory>();
services.AddSingleton<IArtifactComponentFactory, NpmComponentFactory>();
services.AddSingleton<IArtifactComponentFactory, PipComponentFactory>();
services.AddSingleton<IArtifactComponentFactory, DotnetComponentFactory>();
services.AddSingleton<IArtifactFilter, Mariner2ArtifactFilter>();
services.AddSingleton<IComponentDetector, LinuxContainerDetector>();
services.AddSingleton<IComponentDetector, LinuxApplicationLayerDetector>();
Expand Down