Skip to content

Commit

Permalink
support .net 7.0 (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchavakis authored Nov 29, 2022
1 parent 78d2be3 commit 0ef4280
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 40 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ jobs:
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x" # SDK Version to use (x uses the latest version).
include-prerelease: true
- name: Setup dotnet 7.0.x
uses: actions/setup-dotnet@v2
with:
dotnet-version: "7.0.x" # SDK Version to use (x uses the latest version).
# dotnet restore
- name: restore
run: dotnet restore
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
uses: actions/setup-dotnet@v2
with:
dotnet-version: "6.0.x" # SDK Version to use (x uses the latest version).
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Setup dotnet 7.0.x
uses: actions/setup-dotnet@v2
with:
dotnet-version: "7.0.x" # SDK Version to use (x uses the latest version).
include-prerelease: true
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -47,10 +53,10 @@ jobs:
run: dotnet pack --configuration Release
# publish the package
- name: Publish the artifact
run: dotnet publish -f net5.0 -c Release -o ./artifacts
run: dotnet publish -f net7.0 -c Release -o ./artifacts
# publish the package to package folder
- name: Publish the artifact
run: dotnet publish -f net5.0 -c Release -o ./package
run: dotnet publish -f net7.0 -c Release -o ./package
# Add nuget package
- name: Nuget package
run: dotnet pack -c Release -o ./artifacts
Expand Down
1 change: 0 additions & 1 deletion src/InvalidLicensesException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace NugetUtility
{
public class InvalidLicensesException<T> : Exception
Expand Down
2 changes: 1 addition & 1 deletion src/LibraryNameAndVersionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LibraryNameAndVersionComparer : IEqualityComparer<LibraryInfo>

public bool Equals([AllowNull] LibraryInfo x, [AllowNull] LibraryInfo y)
{
return x?.PackageName == y?.PackageName
return x?.PackageName == y?.PackageName
&& x?.PackageVersion == y?.PackageVersion;
}

Expand Down
1 change: 1 addition & 0 deletions src/LicenseToUrlMappings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;

namespace NugetUtility
{
Expand Down
74 changes: 42 additions & 32 deletions src/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Methods
private readonly PackageOptions _packageOptions;
private readonly XmlSerializer _serializer;

internal static bool IgnoreSslCertificateErrorCallback(HttpRequestMessage message, System.Security.Cryptography.X509Certificates.X509Certificate2 cert, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
public static bool IgnoreSslCertificateErrorCallback(HttpRequestMessage message, System.Security.Cryptography.X509Certificates.X509Certificate2 cert, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
=> true;

// Search nuspec in local cache (Fix for linux distro)
Expand All @@ -61,7 +61,7 @@ public Methods(PackageOptions packageOptions)
}
httpClientHandler.Proxy = myProxy;
}

if (packageOptions.IgnoreSslCertificateErrors)
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) => IgnoreSslCertificateErrorCallback(message, cert, chain, sslPolicyErrors);
Expand Down Expand Up @@ -92,9 +92,10 @@ public async Task<PackageList> GetNugetInformationAsync(string project, IEnumera
{
try
{
if (_packageOptions.PackageFilter.Any (p => string.Compare (p, packageWithVersion.Name, StringComparison.OrdinalIgnoreCase) == 0) ||
_packageOptions.PackageRegex?.IsMatch (packageWithVersion.Name) == true) {
WriteOutput (packageWithVersion.Name + " skipped by filter.", logLevel : LogLevel.Verbose);
if (_packageOptions.PackageFilter.Any(p => string.Compare(p, packageWithVersion.Name, StringComparison.OrdinalIgnoreCase) == 0) ||
_packageOptions.PackageRegex?.IsMatch(packageWithVersion.Name) == true)
{
WriteOutput(packageWithVersion.Name + " skipped by filter.", logLevel: LogLevel.Verbose);
continue;
}

Expand All @@ -108,7 +109,7 @@ public async Task<PackageList> GetNugetInformationAsync(string project, IEnumera

if (!string.IsNullOrEmpty(version))
{
WriteOutput($"Package '{packageWithVersion.Name}', version requirement {packageWithVersion.Version} resolved to version {version} from local cache", logLevel: LogLevel.Verbose);
WriteOutput($"Package '{packageWithVersion.Name}', version requirement {packageWithVersion.Version} resolved to version {version} from local cache", logLevel: LogLevel.Verbose);
var lookupKey = Tuple.Create(packageWithVersion.Name, version);

if (_requestCache.TryGetValue(lookupKey, out var package))
Expand All @@ -129,7 +130,7 @@ public async Task<PackageList> GetNugetInformationAsync(string project, IEnumera
await ReadNuspecFile(project, licenses, packageWithVersion.Name, version, lookupKey, textReader);
continue;
}
catch(Exception exc)
catch (Exception exc)
{
// Ignore errors in local cache, try online call
WriteOutput($"ReadNuspecFile error, package '{packageWithVersion.Name}', version {version}", exc, LogLevel.Verbose);
Expand Down Expand Up @@ -195,7 +196,7 @@ public async Task<PackageList> GetNugetInformationAsync(string project, IEnumera
throw;
}
}
}
}
else
{
WriteOutput($"Package '{packageWithVersion.Name}', version {packageWithVersion.Version} not found in NuGet", logLevel: LogLevel.Error);
Expand Down Expand Up @@ -240,7 +241,7 @@ private async Task<string> ResolvePackageVersionFromNugetServerAsync(string name
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
private async Task <IEnumerable<string>> GetVersionsFromLocalCacheAsync(string packageName)
private async Task<IEnumerable<string>> GetVersionsFromLocalCacheAsync(string packageName)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
{
// Nuget saves packages in lowercase format, and we should look for lowercase folders only to allow Linux case-sensitive folder enumeration to succeed
Expand All @@ -253,7 +254,7 @@ private async Task<string> ResolvePackageVersionFromNugetServerAsync(string name
{
return Enumerable.Empty<string>();
}

}

private async Task<IEnumerable<string>> GetVersionsFromNugetServerAsync(string packageName)
Expand Down Expand Up @@ -387,7 +388,7 @@ public IEnumerable<string> GetProjectReferences(string projectPath)
}

IEnumerable<string> references = Array.Empty<string>();

// First use project.assets.json, if this option is enabled.
if (_packageOptions.UseProjectAssetsJson)
{
Expand Down Expand Up @@ -669,29 +670,36 @@ private async Task HandleLicensing(Package package)
_licenseFileCache[key] = await GetNuGetPackageFileResult<string>(package.Metadata.Id, package.Metadata.Version, package.Metadata.License.Text);
}

private string GetOutputFilename (string defaultName) {
string outputDir = GetExportDirectory ();
private string GetOutputFilename(string defaultName)
{
string outputDir = GetExportDirectory();

return string.IsNullOrWhiteSpace (_packageOptions.OutputFileName) ?
Path.Combine (outputDir, defaultName) :
Path.Combine (outputDir, _packageOptions.OutputFileName);
return string.IsNullOrWhiteSpace(_packageOptions.OutputFileName) ?
Path.Combine(outputDir, defaultName) :
Path.Combine(outputDir, _packageOptions.OutputFileName);
}

public string GetExportDirectory () {
public string GetExportDirectory()
{
string outputDirectory = string.Empty;
if (!string.IsNullOrWhiteSpace (_packageOptions.OutputDirectory)) {
if (_packageOptions.OutputDirectory.EndsWith ('/')) {
outputDirectory = Path.GetDirectoryName (_packageOptions.OutputDirectory);
} else {
outputDirectory = Path.GetDirectoryName (_packageOptions.OutputDirectory + "/");
if (!string.IsNullOrWhiteSpace(_packageOptions.OutputDirectory))
{
if (_packageOptions.OutputDirectory.EndsWith('/'))
{
outputDirectory = Path.GetDirectoryName(_packageOptions.OutputDirectory);
}
else
{
outputDirectory = Path.GetDirectoryName(_packageOptions.OutputDirectory + "/");

}
if (!Directory.Exists (outputDirectory)) {
Directory.CreateDirectory (outputDirectory);
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
}

outputDirectory = string.IsNullOrWhiteSpace (outputDirectory) ? Environment.CurrentDirectory : outputDirectory;
outputDirectory = string.IsNullOrWhiteSpace(outputDirectory) ? Environment.CurrentDirectory : outputDirectory;

return outputDirectory;
}
Expand Down Expand Up @@ -935,9 +943,11 @@ public List<LibraryInfo> HandleDeprecateMSFTLicense(List<LibraryInfo> libraries)
return result;
}

public async Task ExportLicenseTexts (List<LibraryInfo> infos) {
var directory = GetExportDirectory ();
foreach (var info in infos.Where (i => !string.IsNullOrEmpty (i.LicenseUrl))) {
public async Task ExportLicenseTexts(List<LibraryInfo> infos)
{
var directory = GetExportDirectory();
foreach (var info in infos.Where(i => !string.IsNullOrEmpty(i.LicenseUrl)))
{
var source = info.LicenseUrl;
var outpath = Path.Combine(directory, $"{info.PackageName}_{info.PackageVersion}.txt");
var outpathhtml = Path.Combine(directory, $"{info.PackageName}_{info.PackageVersion}.html");
Expand Down Expand Up @@ -1054,10 +1064,10 @@ private string CorrectUri(string uri)
uri = uri.Replace("/blob/", "/raw/", StringComparison.Ordinal);
}

/* if (uri.Contains("/dotnet/corefx/", StringComparison.Ordinal))
{
uri = uri.Replace("/dotnet/corefx/", "/dotnet/runtime/", StringComparison.Ordinal);
}*/
/* if (uri.Contains("/dotnet/corefx/", StringComparison.Ordinal))
{
uri = uri.Replace("/dotnet/corefx/", "/dotnet/runtime/", StringComparison.Ordinal);
}*/

return uri;
}
Expand Down
7 changes: 5 additions & 2 deletions src/NugetUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<LangVersion>latest</LangVersion>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<PackageType>DotnetTool</PackageType>
<RepositoryType>git</RepositoryType>
<PackageId>dotnet-project-licenses</PackageId>
<ToolCommandName>dotnet-project-licenses</ToolCommandName>
<Version>2.4.0</Version>
<Version>2.5.0</Version>
<Authors>Tom Chavakis, Lexy2, senslen</Authors>
<Company>-</Company>
<Title>.NET Core Tool to print a list of the licenses of a projects</Title>
Expand Down
5 changes: 4 additions & 1 deletion tests/NugetUtility.Tests/NugetUtility.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0;</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down

0 comments on commit 0ef4280

Please sign in to comment.