Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/Microsoft.Sbom.Targets/GenerateSbom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public partial class GenerateSbom
/// </summary>
public string ManifestDirPath { get; set; }

/// <summary>
/// Gets or sets additional arguments to pass to the Component Detector tool.
/// An appropriate usage of this would be a space-delimited list of `--key value` pairs, representing
/// command-line arguments. See the component-detection repository for a list of valid arguments
/// (https://github.com/microsoft/component-detection/blob/main/docs/detector-arguments.md).
/// </summary>
public string AdditionalComponentDetectorArgs { get; set; }

/// <summary>
/// Gets or sets the path to the SBOM CLI tool
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Sbom.Targets/GenerateSbomTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public override bool Execute()
NamespaceUriUniquePart = this.NamespaceUriUniquePart,
DeleteManifestDirectoryIfPresent = this.DeleteManifestDirIfPresent,
Verbosity = ValidateAndAssignVerbosity(),
AdditionComponentDetectorArgs = this.AdditionalComponentDetectorArgs,
};
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
var result = System.Threading.Tasks.Task.Run(() => this.Generator.GenerateSbomAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
Verbosity="$(SbomGenerationVerbosity)"
ManifestInfo="$(SbomGenerationManifestInfo)"
DeleteManifestDirIfPresent="$(SbomGenerationDeleteManifestDirIfPresent)"
AdditionalComponentDetectorArgs="$(SbomGenerationAdditionalComponentDetectorArgs)"
SbomToolPath="$(SbomToolPath)"
ContinueOnError="ErrorAndContinue">
</GenerateSbom>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Sbom.Targets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The custom MSBuild task accepts most of the arguments available for the [SBOM CL
| `<SbomGenerationVerbosity>` | `Information` | No |
| `<SbomGenerationManifestInfo>` | `SPDX:2.2` | No |
| `<SbomGenerationDeleteManifestDirIfPresent>` | `true` | No |
| `<SbomGenerationAdditionalComponentDetectorArgs>` | N/A | No |

## Local SBOM Generation Workflow

Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.Sbom.Targets/SbomCLIToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ protected override string GenerateCommandLineCommands()
builder.AppendSwitchIfNotNull("-ManifestInfo ", this.ManifestInfo);
}

if (!string.IsNullOrWhiteSpace(this.AdditionalComponentDetectorArgs))
{
builder.AppendSwitchIfNotNull("-AdditionalComponentDetectorArgs ", this.AdditionalComponentDetectorArgs);
}

return builder.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,33 @@ public void Sbom_Generation_Fails_With_NotFound_ManifestDirPath()
Assert.IsFalse(Directory.Exists(DefaultManifestDirectory));
}

[TestMethod]
public void Sbom_Is_Successfully_Generated_With_AdditionalComponentDetectorArgs()
{
// Arrange
var task = new GenerateSbom
{
BuildDropPath = TestBuildDropPath,
PackageSupplier = PackageSupplier,
PackageName = PackageName,
PackageVersion = PackageVersion,
NamespaceBaseUri = NamespaceBaseUri,
AdditionalComponentDetectorArgs = "--DirectoryExclusionList **/test/**",
BuildEngine = this.BuildEngine.Object,
ManifestInfo = this.SbomSpecification,
#if NET472
SbomToolPath = SbomToolPath,
#endif
};

// Act
var result = task.Execute();

// Assert
Assert.IsTrue(result);
this.GeneratedSbomValidator.AssertSbomIsValid(this.ManifestPath, TestBuildDropPath, PackageName, PackageVersion, PackageSupplier, NamespaceBaseUri);
}

[TestMethod]
public void Sbom_Is_Successfully_Generated_With_Component_Path()
{
Expand Down