diff --git a/Directory.Packages.props b/Directory.Packages.props
index d259de4..dd62278 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,29 +1,29 @@
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Promote.NuGet.Commands/Licensing/LicenseComplianceValidator.cs b/src/Promote.NuGet.Commands/Licensing/LicenseComplianceValidator.cs
index 03ec7d8..9fc861f 100644
--- a/src/Promote.NuGet.Commands/Licensing/LicenseComplianceValidator.cs
+++ b/src/Promote.NuGet.Commands/Licensing/LicenseComplianceValidator.cs
@@ -166,24 +166,22 @@ private async Task> CheckFileMatches(
PackageReaderBase packageReader,
CancellationToken cancellationToken)
{
- var filesInPackage = await packageReader.GetFilesAsync(cancellationToken);
- if (!filesInPackage.Contains(license))
- {
- return new LicenseComplianceViolation(packageId, PackageLicenseType.File, license, "There is no such file in the package.");
- }
-
- string actualLicenseText;
+ string? actualLicenseText;
try
{
- await using var stream = await packageReader.GetStreamAsync(license, cancellationToken);
- using var reader = new StreamReader(stream);
- actualLicenseText = await reader.ReadToEndAsync();
+ actualLicenseText = await TryGetFileContent(packageReader, license, cancellationToken)
+ ?? await TryGetFileContent(packageReader, license.Replace('\\', '/'), cancellationToken);
}
catch (Exception ex)
{
return new LicenseComplianceViolation(packageId, PackageLicenseType.File, license, $"Failed to open the license file: {ex.Message}");
}
+ if (actualLicenseText == null)
+ {
+ return new LicenseComplianceViolation(packageId, PackageLicenseType.File, license, "There is no such file in the package.");
+ }
+
var normalizedActualLicense = NormalizeLicenseText(actualLicenseText);
foreach (var acceptFile in acceptedFiles)
@@ -210,7 +208,21 @@ private async Task> CheckFileMatches(
return new LicenseComplianceViolation(packageId, PackageLicenseType.File, license, "No matching license files found in the whitelist.");
}
- private string NormalizeLicenseText(string license)
+ private static async Task TryGetFileContent(PackageReaderBase packageReader, string path, CancellationToken cancellationToken)
+ {
+ try
+ {
+ await using var stream = await packageReader.GetStreamAsync(path, cancellationToken);
+ using var reader = new StreamReader(stream);
+ return await reader.ReadToEndAsync(cancellationToken);
+ }
+ catch (FileNotFoundException)
+ {
+ return null;
+ }
+ }
+
+ private static string NormalizeLicenseText(string license)
{
var normalized = new StringBuilder(license);
diff --git a/tests/Promote.NuGet.Tests/Promote/FromConfiguration/PromoteFromConfigurationCommandIntegrationTests.cs b/tests/Promote.NuGet.Tests/Promote/FromConfiguration/PromoteFromConfigurationCommandIntegrationTests.cs
index b660c7b..14dd3e8 100644
--- a/tests/Promote.NuGet.Tests/Promote/FromConfiguration/PromoteFromConfigurationCommandIntegrationTests.cs
+++ b/tests/Promote.NuGet.Tests/Promote/FromConfiguration/PromoteFromConfigurationCommandIntegrationTests.cs
@@ -583,6 +583,9 @@ public async Task Checks_license_compliance_when_no_licenses_are_accepted()
- id: System.Runtime.CompilerServices.Unsafe
versions:
- 6.0.0
+ - id: LibGit2Sharp.NativeBinaries
+ versions:
+ - 2.0.322
"""
);
@@ -611,7 +614,10 @@ Resolving Microsoft.Data.SqlClient.SNI.runtime 5.2.0
Resolving System.Runtime.CompilerServices.Unsafe 6.0.0
Found 1 matching package:
└── 6.0.0
- Resolving 3 packages to promote...
+ Resolving LibGit2Sharp.NativeBinaries 2.0.322
+ Found 1 matching package:
+ └── 2.0.322
+ Resolving 4 packages to promote...
Processing System.Runtime 4.3.1
Package license: MICROSOFT .NET LIBRARY
(http://go.microsoft.com/fwlink/?LinkId=329770)
@@ -639,6 +645,13 @@ System.Runtime.CompilerServices.Unsafe 6.0.0 is not in the
destination.
System.Runtime.CompilerServices.Unsafe 6.0.0 has no
dependencies.
+ Processing LibGit2Sharp.NativeBinaries 2.0.322
+ Package license:
+ https://www.nuget.org/packages/LibGit2Sharp.NativeBinaries
+ /2.0.322/license
+ LibGit2Sharp.NativeBinaries 2.0.322 is not in the
+ destination.
+ LibGit2Sharp.NativeBinaries 2.0.322 has no dependencies.
Processing Microsoft.NETCore.Platforms 1.1.1
Package license: MICROSOFT .NET LIBRARY
(http://go.microsoft.com/fwlink/?LinkId=329770)
@@ -651,12 +664,17 @@ Processing Microsoft.NETCore.Targets 1.1.3
Microsoft.NETCore.Targets 1.1.3 is not in the destination.
Microsoft.NETCore.Targets 1.1.3 has no dependencies.
Resolved package tree:
+ ├── LibGit2Sharp.NativeBinaries 2.0.322
├── Microsoft.Data.SqlClient.SNI.runtime 5.2.0
├── System.Runtime 4.3.1
│ ├── Microsoft.NETCore.Platforms 1.1.1
│ └── Microsoft.NETCore.Targets 1.1.3
└── System.Runtime.CompilerServices.Unsafe 6.0.0
- Found 5 packages to promote:
+ Found 6 packages to promote:
+ ├── LibGit2Sharp.NativeBinaries 2.0.322
+ │ └── License:
+ │ https://www.nuget.org/packages/LibGit2Sharp.NativeBi
+ │ naries/2.0.322/license
├── Microsoft.Data.SqlClient.SNI.runtime 5.2.0
│ └── License:
│ https://www.nuget.org/packages/Microsoft.Data.SqlCli
@@ -676,10 +694,16 @@ Microsoft.NETCore.Targets 1.1.3 has no dependencies.
├── 3x: MICROSOFT .NET LIBRARY
│ (http://go.microsoft.com/fwlink/?LinkId=329770)
├── 1x:
+ │ https://www.nuget.org/packages/LibGit2Sharp.NativeBinari
+ │ es/2.0.322/license
+ ├── 1x:
│ https://www.nuget.org/packages/Microsoft.Data.SqlClient.
│ SNI.runtime/5.2.0/license
└── 1x: MIT (https://licenses.nuget.org/MIT)
Checking license compliance...
+ Checking LibGit2Sharp.NativeBinaries 2.0.322
+ License (file): libgit2\libgit2.license.txt
+ [x] No matching license files found in the whitelist.
Checking Microsoft.Data.SqlClient.SNI.runtime 5.2.0
License (file): LICENSE.txt
[x] No matching license files found in the whitelist.
@@ -698,7 +722,11 @@ [x] The license url is not whitelisted.
Checking System.Runtime.CompilerServices.Unsafe 6.0.0
License (expression): MIT
[x] The license expression is not whitelisted.
- 5 license violations found:
+ 6 license violations found:
+ ├── LibGit2Sharp.NativeBinaries.2.0.322
+ │ ├── License (file): libgit2\libgit2.license.txt
+ │ └── Reason: No matching license files found in the
+ │ whitelist.
├── Microsoft.Data.SqlClient.SNI.runtime.5.2.0
│ ├── License (file): LICENSE.txt
│ └── Reason: No matching license files found in the