Skip to content

Commit

Permalink
Update the project (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
sensslen authored Nov 29, 2023
1 parent 84ac29e commit 9deb3cc
Show file tree
Hide file tree
Showing 261 changed files with 5,230 additions and 4,148 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Main workflow
name: "Main workflow"

on: [push, pull_request]

Expand Down Expand Up @@ -29,6 +29,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
- name: restore
run: dotnet restore

Expand All @@ -42,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
targetFramework: [net6.0, net7.0]
targetFramework: [net6.0, net7.0, net8.0]

include:
- targetFramework: net6.0
Expand All @@ -51,6 +55,9 @@ jobs:
- targetFramework: net7.0
dotnetVersion: "7.0.x"

- targetFramework: net8.0
dotnetVersion: "8.0.x"

steps:
- uses: actions/checkout@v3
- name: Setup dotnet ${{ matrix.dotnetVersion }}
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/assets/overwritePackageInformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"Version": "3.13.3",
"License": "MIT"
},
{
"Id": "NUnit",
"Version": "3.14.0",
"License": "MIT"
},
{
"Id": "NetArchTest.Rules",
"Version": "1.3.2",
Expand All @@ -19,6 +24,11 @@
"Version": "17.5.0",
"License": "MIT"
},
{
"Id": "Microsoft.TestPlatform.TestHost",
"Version": "17.8.0",
"License": "MIT"
},
{
"Id": "Microsoft.TestPlatform.ObjectModel",
"Version": "17.4.0",
Expand All @@ -29,6 +39,11 @@
"Version": "17.5.0",
"License": "MIT"
},
{
"Id": "Microsoft.TestPlatform.ObjectModel",
"Version": "17.8.0",
"License": "MIT"
},
{
"Id": "Microsoft.NET.Test.Sdk",
"Version": "17.4.0",
Expand All @@ -39,6 +54,11 @@
"Version": "17.5.0",
"License": "MIT"
},
{
"Id": "Microsoft.NET.Test.Sdk",
"Version": "17.8.0",
"License": "MIT"
},
{
"Id": "Microsoft.CodeCoverage",
"Version": "17.4.0",
Expand All @@ -49,6 +69,11 @@
"Version": "17.5.0",
"License": "MIT"
},
{
"Id": "Microsoft.CodeCoverage",
"Version": "17.8.0",
"License": "MIT"
},
{
"Id": "Fare",
"Version": "2.1.1",
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
- name: Setup dotnet 8.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

Expand All @@ -39,6 +43,8 @@ jobs:
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net6 -f net6.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Publish the application binaries (.net7)
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net7 -f net7.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Publish the application binaries (.net8)
run: dotnet publish ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-restore -o ./artifacts/net8 -f net8.0 -p:Version=${{ steps.version.outputs.full_without_prefix }}
- name: Create nuget package
run: dotnet pack ./src/NuGetUtility/NuGetUtility.csproj -c Release --no-build -o ./artifacts -p:Version=${{ steps.version.outputs.full_without_prefix }}

Expand Down
24 changes: 23 additions & 1 deletion src/NuGetUtility/LicenseValidator/LicenseInformationOrigin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,31 @@
{
public enum LicenseInformationOrigin
{
/// <summary>
/// The license information was provided by the package maintainer using a license expression
/// </summary>
Expression,

/// <summary>
/// The license information was provided by the package maintainer using a license url
/// that was then matched against a set of known license url's
/// </summary>
Url,

/// <summary>
/// The license has an unknown origin. This is always used in conjunction with a licensing error
/// which will give more information
/// </summary>
Unknown,
Ignored

/// <summary>
/// The license for this package was ignored via the ignore list provided
/// </summary>
Ignored,

/// <summary>
/// The license for this package was given by a custom override
/// </summary>
Overwrite
}
}
16 changes: 12 additions & 4 deletions src/NuGetUtility/LicenseValidator/LicenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<IEnumerable<LicenseValidationResult>> Validate(

private bool IsIgnoredPackage(PackageIdentity identity)
{
return _ignoredPackages.Any(ignored => identity.Id.Like(ignored));
return Array.Exists(_ignoredPackages, ignored => identity.Id.Like(ignored));
}

private void AddOrUpdateLicense(
Expand Down Expand Up @@ -123,19 +123,20 @@ private void ValidateLicenseByMetadata(IPackageMetadata info,
switch (info.LicenseMetadata!.Type)
{
case LicenseType.Expression:
case LicenseType.Overwrite:
string licenseId = info.LicenseMetadata!.License;
if (IsLicenseValid(licenseId))
{
AddOrUpdateLicense(result,
info,
LicenseInformationOrigin.Expression,
ToLicenseOrigin(info.LicenseMetadata.Type),
info.LicenseMetadata.License);
}
else
{
AddOrUpdateLicense(result,
info,
LicenseInformationOrigin.Expression,
ToLicenseOrigin(info.LicenseMetadata.Type),
new ValidationError(GetLicenseNotAllowedMessage(info.LicenseMetadata.License), context),
info.LicenseMetadata.License);
}
Expand Down Expand Up @@ -227,6 +228,13 @@ private string GetLicenseNotAllowedMessage(string license)
return $"License {license} not found in list of supported licenses";
}

private record LicenseNameAndVersion(string LicenseName, INuGetVersion Version);
private LicenseInformationOrigin ToLicenseOrigin(LicenseType type) => type switch
{
LicenseType.Overwrite => LicenseInformationOrigin.Overwrite,
LicenseType.Expression => LicenseInformationOrigin.Expression,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, $"This conversion method only supports the {nameof(LicenseType.Overwrite)} and {nameof(LicenseType.Expression)} types for conversion")
};

private sealed record LicenseNameAndVersion(string LicenseName, INuGetVersion Version);
}
}
19 changes: 12 additions & 7 deletions src/NuGetUtility/NuGetUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<PackageType>DotnetTool</PackageType>
Expand All @@ -24,18 +24,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageReference Include="NuGet.Commands" Version="6.5.0" />
<PackageReference Include="NuGet.Packaging" Version="6.5.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
<PackageReference Include="NuGet.Commands" Version="6.8.0" />
<PackageReference Include="NuGet.Packaging" Version="6.8.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.3.2" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.3.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.5.0" />
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.6.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Build" ExcludeAssets="runtime" Version="17.8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private PackageSearchResult TryGetPackageInfoFromCustomInformation(PackageIdenti
return new PackageSearchResult();
}

return new PackageSearchResult(new PackageMetadata(package, resolvedCustomInformation.License));
return new PackageSearchResult(new PackageMetadata(package, resolvedCustomInformation.License, LicenseType.Overwrite));
}

private static async Task<IPackageMetadataResource?> TryGetPackageMetadataResource(ISourceRepository repository)
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetUtility/PackageInformationReader/PackageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public PackageMetadata(PackageIdentity identity)
Identity = identity;
}

public PackageMetadata(PackageIdentity identity, string licenseType)
public PackageMetadata(PackageIdentity identity, string licenseIdentifier, LicenseType licenseType)
{
Identity = identity;
LicenseMetadata = new LicenseMetadata(LicenseType.Expression, licenseType);
LicenseMetadata = new LicenseMetadata(licenseType, licenseIdentifier);
}

public PackageIdentity Identity { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public IProject GetProject(string projectPath)

public IEnumerable<string> GetProjectsFromSolution(string inputPath)
{
string absolutePath = Path.GetFullPath(inputPath, Environment.CurrentDirectory);
string absolutePath = Path.GetFullPath(inputPath, Environment.CurrentDirectory);
var sln = SolutionFile.Parse(absolutePath);
return sln.ProjectsInOrder.Select(p => p.AbsolutePath);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace NuGetUtility.Wrapper.NuGetWrapper.Frameworks
{
public interface INuGetFramework { }
public interface INuGetFramework
{
string? ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging
public enum LicenseType
{
File,
Expression
Expression,
Overwrite
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CachingPackageMetadataResource(PackageMetadataResource metadataResource,
{
try
{
IPackageSearchMetadata result = await _metadataResource.GetMetadataAsync(new NuGet.Packaging.Core.PackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString())),
IPackageSearchMetadata result = await _metadataResource.GetMetadataAsync(new NuGet.Packaging.Core.PackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString()!)),
_cacheContext,
new NullLogger(),
cancellationToken);
Expand All @@ -35,9 +35,9 @@ public CachingPackageMetadataResource(PackageMetadataResource metadataResource,
}
}

private class WrappedPackageSearchMetadata : IPackageMetadata
private sealed class WrappedPackageSearchMetadata : IPackageMetadata
{
private IPackageSearchMetadata _searchMetadata;
private readonly IPackageSearchMetadata _searchMetadata;

public WrappedPackageSearchMetadata(IPackageSearchMetadata searchMetadata)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GlobalPackagesFolderUtility(ISettings settings)

public IWrappedPackageMetadata? GetPackage(PackageIdentity identity)
{
DownloadResourceResult cachedPackage = OriginalGlobalPackagesFolderUtility.GetPackage(new OriginalPackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString())), _globalPackagesFolder);
DownloadResourceResult cachedPackage = OriginalGlobalPackagesFolderUtility.GetPackage(new OriginalPackageIdentity(identity.Id, new NuGetVersion(identity.Version.ToString()!)), _globalPackagesFolder);
if (cachedPackage == null)
{
return null;
Expand Down
Loading

0 comments on commit 9deb3cc

Please sign in to comment.