Skip to content

Commit

Permalink
Print copyright and authors (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Tore Fuglestad <[email protected]>
  • Loading branch information
sensslen and notofug authored Apr 9, 2024
1 parent 01d461e commit fe99ca3
Show file tree
Hide file tree
Showing 2,623 changed files with 273,626 additions and 35,563 deletions.
2 changes: 2 additions & 0 deletions src/NuGetUtility/LicenseValidator/LicenseValidationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public record LicenseValidationResult(string PackageId,
string? PackageProjectUrl,
string? License,
string? LicenseUrl,
string? Copyright,
string? Authors,
LicenseInformationOrigin LicenseInformationOrigin,
List<ValidationError>? ValidationErrors = null)
{
Expand Down
4 changes: 4 additions & 0 deletions src/NuGetUtility/LicenseValidator/LicenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private void AddOrUpdateLicense(
info.ProjectUrl?.ToString(),
license,
info.LicenseUrl?.AbsoluteUri,
info.Copyright,
info.Authors,
origin,
new List<ValidationError> { error });
result.AddOrUpdate(new LicenseNameAndVersion(info.Identity.Id, info.Identity.Version),
Expand All @@ -100,6 +102,8 @@ private void AddOrUpdateLicense(
info.ProjectUrl?.ToString(),
license,
info.LicenseUrl?.AbsoluteUri,
info.Copyright,
info.Authors,
origin);
result.AddOrUpdate(new LicenseNameAndVersion(info.Identity.Id, info.Identity.Version),
newValue,
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetUtility/Output/Table/TableOutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public async Task Write(Stream stream, IList<LicenseValidationResult> results)
new ColumnDefinition("License Information Origin", license => license.LicenseInformationOrigin, license => true, true),
new ColumnDefinition("License Expression", license => license.License, license => license.License != null),
new ColumnDefinition("License Url", license => license.LicenseUrl, license => license.LicenseUrl != null),
new ColumnDefinition("Copyright", license => license.Copyright, license => license.Copyright != null),
new ColumnDefinition("Authors", license => license.Authors, license => license.Authors != null),
new ColumnDefinition("Package Project Url",license => license.PackageProjectUrl, license => license.PackageProjectUrl != null),
errorColumnDefinition,
new ColumnDefinition("Error Context", license => license.ValidationErrors.Select(e => e.Context), license => license.ValidationErrors.Any()),
Expand Down
4 changes: 4 additions & 0 deletions src/NuGetUtility/PackageInformationReader/PackageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public PackageMetadata(PackageIdentity identity, string licenseIdentifier, Licen

public string Summary => string.Empty;

public string Copyright => string.Empty;

public string Authors => string.Empty;

public LicenseMetadata? LicenseMetadata { get; } = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IPackageMetadata
string ProjectUrl { get; }
string Description { get; }
string Summary { get; }
string Copyright { get; }
string Authors { get; }
LicenseMetadata? LicenseMetadata { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public WrappedPackageSearchMetadata(IPackageSearchMetadata searchMetadata)

public string Summary => _searchMetadata.Summary;

public string Copyright => string.Empty;

public string Authors => _searchMetadata.Authors;

public LicenseMetadata? LicenseMetadata { get; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public WrappedPackageMetadata(ManifestMetadata metadata)

public string Summary => _metadata.Summary;

public string Copyright => _metadata.Copyright;

public string Authors => string.Join(",", _metadata.Authors); // https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors

public Packaging.LicenseMetadata? LicenseMetadata { get; }
}
}
128 changes: 128 additions & 0 deletions tests/NuGetUtility.Test/LicenseValidator/LicenseValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ private IPackageMetadata SetupPackageWithLicenseInformationOfType(string package
packageInfo.LicenseMetadata.Returns(new LicenseMetadata(type, license));
return packageInfo;
}
private IPackageMetadata SetupPackageWithCopyright(string packageId,
INuGetVersion packageVersion,
string copyrigth)
{
IPackageMetadata packageInfo = SetupPackage(packageId, packageVersion);
packageInfo.Copyright.Returns(copyrigth);
return packageInfo;
}
private IPackageMetadata SetupPackageWithAuthors(string packageId,
INuGetVersion packageVersion,
string authors)
{
IPackageMetadata packageInfo = SetupPackage(packageId, packageVersion);
packageInfo.Authors.Returns(authors);
return packageInfo;
}

private IPackageMetadata SetupPackageWithExpressionLicenseInformation(string packageId,
INuGetVersion packageVersion,
Expand Down Expand Up @@ -122,6 +138,8 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_PackageNameMatchesE
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -151,6 +169,8 @@ public async Task ValidatingLicenses_Should_NotIgnorePackage_If_PackageNameDoesN
_projectUrl.ToString(),
license,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -182,6 +202,8 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -213,6 +235,8 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -245,6 +269,8 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -273,6 +299,8 @@ public async Task ValidatingLicenses_Should_IgnorePackage_If_IgnoreWildcardMatch
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -302,6 +330,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
license,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -333,6 +363,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -364,6 +396,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -393,6 +427,8 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
_projectUrl.ToString(),
license,
null,
null,
null,
LicenseInformationOrigin.Overwrite)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -431,6 +467,8 @@ public async Task ValidatingLicensesWithMatchingLicenseUrl_Should_GiveCorrectVal
_projectUrl.ToString(),
mappingLicense.Value,
mappingLicense.Key.AbsoluteUri,
null,
null,
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -460,6 +498,8 @@ public async Task ValidatingLicensesWithMatchingLicenseUrl_Should_GiveCorrectVal
_projectUrl.ToString(),
licenseUrl.ToString(),
licenseUrl.ToString(),
null,
null,
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand Down Expand Up @@ -492,6 +532,8 @@ public async Task ValidatingLicensesWithNotSupportedLicenseMetadata_Should_GiveC
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Unknown,
new List<ValidationError>
{
Expand Down Expand Up @@ -525,6 +567,8 @@ public async Task ValidatingLicensesWithoutLicenseInformation_Should_GiveCorrect
_projectUrl.ToString(),
null,
null,
null,
null,
LicenseInformationOrigin.Unknown,
new List<ValidationError>
{
Expand Down Expand Up @@ -554,6 +598,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
license,
null,
null,
null,
LicenseInformationOrigin.Expression,
new List<ValidationError>
{
Expand Down Expand Up @@ -590,6 +636,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression,
new List<ValidationError>
{
Expand Down Expand Up @@ -628,6 +676,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression,
new List<ValidationError>
{
Expand Down Expand Up @@ -657,6 +707,8 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
_projectUrl.ToString(),
license,
null,
null,
null,
LicenseInformationOrigin.Overwrite,
new List<ValidationError>
{
Expand Down Expand Up @@ -686,6 +738,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
validLicense,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -711,6 +765,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -737,6 +793,8 @@ public async Task ValidatingLicensesWithExpressionLicenseInformation_Should_Give
_projectUrl.ToString(),
expression,
null,
null,
null,
LicenseInformationOrigin.Expression)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -761,6 +819,8 @@ public async Task ValidatingLicensesWithOverwriteLicenseInformation_Should_GiveC
_projectUrl.ToString(),
validLicense,
null,
null,
null,
LicenseInformationOrigin.Overwrite)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -785,6 +845,8 @@ public async Task ValidatingLicensesWithMatchingUrlInformation_Should_GiveCorrec
_projectUrl.ToString(),
urlMatch.Value,
urlMatch.Key.AbsoluteUri,
null,
null,
LicenseInformationOrigin.Url,
new List<ValidationError>
{
Expand Down Expand Up @@ -853,6 +915,8 @@ public async Task ValidatingLicensesWithMatchingUrlInformation_Should_GiveCorrec
_projectUrl.ToString(),
urlMatch.Value,
urlMatch.Key.AbsoluteUri,
null,
null,
LicenseInformationOrigin.Url)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
Expand All @@ -877,6 +941,8 @@ public async Task ValidatingLicensesWithNotMatchingUrlInformation_Should_GiveCor
_projectUrl.ToString(),
licenseUrl.ToString(),
licenseUrl.ToString(),
null,
null,
LicenseInformationOrigin.Url,
new List<ValidationError>
{
Expand All @@ -886,6 +952,68 @@ public async Task ValidatingLicensesWithNotMatchingUrlInformation_Should_GiveCor
})
.Using(new LicenseValidationResultValueEqualityComparer()));
}

[Test]
[ExtendedAutoData(typeof(NuGetVersionBuilder))]
public async Task ValidatingLicenses_ShouldContainCopyright(
string packageId,
INuGetVersion packageVersion,
string copyright)
{
_uut = new NuGetUtility.LicenseValidator.LicenseValidator(_licenseMapping,
Array.Empty<string>(),
_fileDownloader,
_ignoredLicenses.Append(packageId).ToArray());

IPackageMetadata package = SetupPackageWithCopyright(packageId, packageVersion, copyright);

IEnumerable<LicenseValidationResult> result = await _uut.Validate(CreateInput(package, _context), _token.Token);

Assert.That(result,
Is.EquivalentTo(new[]
{
new LicenseValidationResult(packageId,
packageVersion,
_projectUrl.ToString(),
null,
null,
copyright,
null,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
}

[Test]
[ExtendedAutoData(typeof(NuGetVersionBuilder))]
public async Task ValidatingLicenses_ShouldContainAuthors(
string packageId,
INuGetVersion packageVersion,
string authors)
{
_uut = new NuGetUtility.LicenseValidator.LicenseValidator(_licenseMapping,
Array.Empty<string>(),
_fileDownloader,
_ignoredLicenses.Append(packageId).ToArray());

IPackageMetadata package = SetupPackageWithAuthors(packageId, packageVersion, authors);

IEnumerable<LicenseValidationResult> result = await _uut.Validate(CreateInput(package, _context), _token.Token);

Assert.That(result,
Is.EquivalentTo(new[]
{
new LicenseValidationResult(packageId,
packageVersion,
_projectUrl.ToString(),
null,
null,
null,
authors,
LicenseInformationOrigin.Ignored)
})
.Using(new LicenseValidationResultValueEqualityComparer()));
}
}

}
Loading

0 comments on commit fe99ca3

Please sign in to comment.