Skip to content

Commit

Permalink
Bump System.Drawing.Common from 7.0.0 to 8.0.0 (#82)
Browse files Browse the repository at this point in the history
Remove System.Drawing.Common, update library documentation checker code
  • Loading branch information
dependabot[bot] committed Nov 17, 2023
1 parent e358c41 commit b7c766a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
Expand All @@ -13,9 +13,6 @@
<ItemGroup>
<Compile Include="..\..\SharedAssemblyInfo.cs" Link="SharedAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\RDMP\Rdmp.UI\Rdmp.UI.csproj" />
</ItemGroup>
Expand All @@ -33,4 +30,4 @@
<DependentUpon>DeAnonymiseAgainstCohortUI.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>
113 changes: 0 additions & 113 deletions LoadModules.Extensions.Tests/NuspecIsCorrectTests.cs

This file was deleted.

108 changes: 108 additions & 0 deletions LoadModules.Extensions.Tests/PackageListIsCorrectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;

namespace LoadModules.Extensions.Tests;

/// <summary>
/// Tests to confirm that the dependencies in csproj files (NuGet packages) match those in the .nuspec files and that packages.md
/// lists the correct versions (in documentation)
/// </summary>
public class PackageListIsCorrectTests
{
private static readonly EnumerationOptions EnumerationOptions = new() { RecurseSubdirectories = true,MatchCasing = MatchCasing.CaseInsensitive,IgnoreInaccessible = true};

//<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
private static readonly Regex RPackageRef = new(@"<PackageReference\s+Include=""(.*)""\s+Version=""([^""]*)""", RegexOptions.IgnoreCase|RegexOptions.Compiled|RegexOptions.CultureInvariant);

// | Org.SomePackage |
//
private static readonly Regex RMarkdownEntry = new(@"^\|\s*\[?([^ |\]]+)(\]\([^)]+\))?\s*\|", RegexOptions.IgnoreCase|RegexOptions.Compiled|RegexOptions.CultureInvariant);


/// <summary>
/// Enumerate non-test packages, check that they are listed in PACKAGES.md
/// </summary>
/// <param name="rootPath"></param>
[TestCase]
public void TestPackagesDocumentCorrect(string rootPath=null)
{
var root= FindRoot(rootPath);
var undocumented = new StringBuilder();

// Extract the named packages from PACKAGES.md
var packagesMarkdown = GetPackagesMarkdown(root).SelectMany(File.ReadAllLines)
.Select(line => RMarkdownEntry.Match(line))
.Where(m=>m.Success)
.Select(m => m.Groups[1].Value)
.Except(new[]{"Package", "-------" })
.ToHashSet(StringComparer.InvariantCultureIgnoreCase);

// Extract the named packages from csproj files
var usedPackages = GetCsprojFiles(root).Select(File.ReadAllText).SelectMany(s => RPackageRef.Matches(s))
.Select(m => m.Groups[1].Value).ToHashSet(StringComparer.InvariantCultureIgnoreCase);

// Then subtract those listed in PACKAGES.md (should be empty)
var undocumentedPackages = usedPackages.Except(packagesMarkdown).Select(BuildRecommendedMarkdownLine);
undocumented.AppendJoin(Environment.NewLine, undocumentedPackages);

var unusedPackages = packagesMarkdown.Except(usedPackages).ToArray();
Assert.IsEmpty(unusedPackages,
$"The following packages are listed in PACKAGES.md but are not used in any csproj file: {string.Join(", ", unusedPackages)}");
Assert.IsEmpty(undocumented.ToString());
}

/// <summary>
/// Generate the report entry for an undocumented package
/// </summary>
/// <param name="package"></param>
/// <returns></returns>
private static object BuildRecommendedMarkdownLine(string package) => $"Package {package} is not documented in PACKAGES.md. Recommended line is:\r\n| {package} | [GitHub]() | LICENCE GOES HERE | |";

/// <summary>
/// Find the root of this repo, which is usually the directory containing the .sln file
/// If the .sln file lives elsewhere, you can override this by passing in a path explicitly.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private static DirectoryInfo FindRoot(string path = null)
{
if (path != null)
{
if (!Path.IsPathRooted(path)) path = Path.Combine(TestContext.CurrentContext.TestDirectory, path);
return new DirectoryInfo(path);
}
var root = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
while (!root.EnumerateFiles("*.sln", SearchOption.TopDirectoryOnly).Any() && root.Parent != null)
root = root.Parent;
Assert.IsNotNull(root.Parent, "Could not find root of repository");
return root;
}

/// <summary>
/// Returns all csproj files in the repository, except those containing the string 'tests'
/// </summary>
/// <param name="root"></param>
/// <returns></returns>
private static IEnumerable<string> GetCsprojFiles(DirectoryInfo root)
{
return root.EnumerateFiles("*.csproj", EnumerationOptions).Select(f => f.FullName).Where(f => !f.Contains("tests", StringComparison.InvariantCultureIgnoreCase));
}

/// <summary>
/// Find the sole packages.md file wherever in the repo it lives. Error if multiple or none.
/// </summary>
/// <param name="root"></param>
/// <returns></returns>
private static string[] GetPackagesMarkdown(DirectoryInfo root)
{
var path = root.EnumerateFiles("packages.md", EnumerationOptions).Select(f => f.FullName).ToArray();
Assert.False(path.Length==0, "Could not find packages.md");
return path;
}

}
7 changes: 0 additions & 7 deletions Packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,4 @@

| Package | Source Code | Version | License | Purpose | Additional Risk Assessment |
| ------- | ------------| --------| ------- | ------- | -------------------------- |
| [Nunit](https://nunit.org/) |[GitHub](https://github.com/nunit/nunit) | [3.11.0](https://www.nuget.org/packages/NUnit/3.11.0) | [MIT](https://opensource.org/licenses/MIT) | Unit testing |
| NUnit3TestAdapter | [GitHub](https://github.com/nunit/nunit3-vs-adapter)| [3.13.0](https://www.nuget.org/packages/NUnit3TestAdapter/3.13.0) | [MIT](https://opensource.org/licenses/MIT) | Run unit tests from within Visual Studio |
| HIC.RDMP.Plugin | [GitHub](https://github.com/HicServices/RDMP) | [8.1.0-rc1](https://www.nuget.org/packages/HIC.RDMP.Plugin/8.1.0-rc1) | [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.html) | Interact with RDMP objects, base classes for plugin components etc | |
| HIC.RDMP.Plugin.UI | [GitHub](https://github.com/HicServices/RDMP) | [8.1.0-rc1](https://www.nuget.org/packages/HIC.RDMP.Plugin.UI/8.1.0-rc1) |[GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.html) | Interact with RDMP user interface API layer | |
| DotNetZip | [GitHub](https://github.com/DinoChiesa/DotNetZip) | [1.16.0](https://www.nuget.org/packages/DotNetZip/1.16.0) | [Ms-PL](https://github.com/DinoChiesa/DotNetZip/blob/master/License.txt) | Opens zip archives | |
| System.Drawing.Common | [GitHub](https://github.com/dotnet/corefx) | [7.0.0](https://www.nuget.org/packages/System.Drawing.Common/7.0.0) |[MIT](https://opensource.org/licenses/MIT) | Legacy wrapper for working with Windows 3.0 style BITMAP objects | |
| System.IO | [GitHub](https://github.com/dotnet/corefx) | [4.3.0](https://www.nuget.org/packages/System.IO/4.3.0) |[MIT](https://opensource.org/licenses/MIT) | Enables working with the file system | |
| System.Resources.ResourceManager | [GitHub](https://github.com/dotnet/corefx) | [4.3.0](https://www.nuget.org/packages/System.Resources.ResourceManager/4.3.0) |[MIT](https://opensource.org/licenses/MIT) | Enables working with embedded resources | |

0 comments on commit b7c766a

Please sign in to comment.