Skip to content

Commit

Permalink
Release/2.1 (#151)
Browse files Browse the repository at this point in the history
* feat: enable export to json file (#142)

* feat: enable export to json file

Closes #16

* docs: add documentation

* docs(readme): update readme

* chore(deps)!: upgrade SlnParser

Closes #148

* chore: enable trimmable

Closes #144

* feature: add the ability to filter projects using glob-patterns (#149)

* feat: implement project exclusion

Closes #5

* refactor(tool): rebuild Liz.Tool

as this no longer works like we want as we exceeeded the maximum amount of parameters

* docs: update documentation

* Feature/7 exclude packages (#150)

* feat: add the ability to filter packages using glob-patterns

Closes #7

* log: add log-message to make debugging easier
  • Loading branch information
wgnf authored Sep 2, 2023
1 parent c9039d6 commit 01867e0
Show file tree
Hide file tree
Showing 35 changed files with 1,528 additions and 827 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
- Validate the determined package-references and their license-types against a provided whitelist/blacklist
- Export license-information in various forms:
- license-texts into text-files in a given directory
- all the gathered information into a single JSON-file
- Filtering
- Exclude projects by file-path using [glob-patterns](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns)
- Exclude packages by name using [glob-patterns](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns)

### Planned features

- [#11](https://github.com/wgnf/liz/issues/11) & [#12](https://github.com/wgnf/liz/issues/12) Mapping from package-reference to license-information
- [#16](https://github.com/wgnf/liz/issues/16) Export license-information in various forms to a given directory/file
- [#5](https://github.com/wgnf/liz/issues/5) & [#7](https://github.com/wgnf/liz/issues/7) Filter for projects and dependencies
- [#6](https://github.com/wgnf/liz/issues/6) Ability to provide manual dependencies
- [#1](https://github.com/wgnf/liz/issues/1) Caching for even faster analyzation times
- [#28](https://github.com/wgnf/liz/issues/28) Sanitize HTML-Tags
Expand Down
37 changes: 37 additions & 0 deletions doc/documenation-cake-addin.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ The settings contain the following options which can be set according to your ne
| `LicenseTypeBlacklist` | A list of license-types, which are the only ones disallowed, when validating the determined license-types. Any license-type that is the same as within that blacklist will cause the validation to fail. Any other license-type is allowed. </br> This option is mutually exclusive with `LicenseTypeWhitelist` and `LicenseTypeWhitelistFilePath` |
| `LicenseTypeBlacklistFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of license-types, which are the only ones disallowed, when validating the determined license-types. Any license-type that is the same as within that blacklist will cause the validation to fail. Any other license-type is allowed. </br> This option is mutually exclusive with `LicenseTypeWhitelist` and `LicenseTypeWhitelistFilePath` </br> If both `LicenseTypeBlacklist` and `LicenseTypeBlacklistFilePath` are given, those two will be merged |
| `ExportLicenseTextsDirectory` | A path to a directory to where the determined license-texts will be exported </br> Each license-text will be written to an individual file with the file-name being: `<package-name>-<package-version>.txt`. If the license-text is the content of a website, the contents will be written into an ".html" file instead |
| `ExportJsonFile` | A path to a JSON-file to which the determined license- and package-information will be exported. All the information will be written to a single JSON-file. </br> If the file already exists it will be overwritten. |
| `RequestTimeout` | The timeout for a request (i.e. to get the license text from a website). </br> After this amount of time a request will be considered as failed and aborted. </br> This defaults to 10 seconds |
| `ProjectExclusionGlobs` | A list of glob-patterns to exclude certain projects. A project will be excluded when it matches at least one glob-pattern. The pattern will be matched against absolute path of the project-file. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |
| `ProjectExclusionGlobsFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain projects. A project will be excluded when it matches at least one glob-pattern The pattern will be matched against the absolute path of the project-file. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) </br> If both `ProjectExclusionGlobs` and `ProjectExclusionGlobsFilePath` are given, those two will be merged. |
| `PackageExclusionGlobs` | A list of glob-patterns to exclude certain packages. A package will be excluded when it matches at least one glob-pattern. The pattern will be matched against the name of the package. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |
| `PackageExclusionGlobsFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain packages. A package will be excluded when it matches at least one glob-pattern The pattern will be matched against the name of the package. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) </br> If both `PackageExclusionGlobs` and `PackageExclusionGlobsFilePath` are given, those two will be merged. |

## Example Usages

Expand Down Expand Up @@ -287,3 +292,35 @@ var settings = new ExtractLicensesSettings
LicenseTypeBlacklistFilePath = "http://path/to/file.json"
};
```

#### Excluding projects

If you want to for instance exclude all the test-projects when you're scanning a whole solution, you can use something like the following:

```cs
var settings = new ExtractLicensesSettings
{
ProjectExclusionGlobs = new
{
"*/**/*Tests.csproj"
}
}
```

when all your test-projects end with `Tests.csproj`.

#### Excluding packages

If you want to exclude certain packages, you can use something like the following:

```cs
var settings = new ExtractLicensesSettings
{
PackageExclusionGlobs = new
{
"YourCompany*"
}
}
```

When you i.e. want to exclude all packages from your company.
63 changes: 63 additions & 0 deletions doc/documentation-dotnet-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ To analyze a project your solution you have to use
| `--whitelist`, `-w` | Provide a path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of license-types, which are the only ones allowed, when validating the determined license-types. Any license-type which is not in the whitelist will cause the validation to fail. </br> `--whitelist` and `--blacklist` are mutually exclusive! |
| `--blacklist`, `-b` | Provide a path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of license-types, which are the only ones disallowed, when validating the determined license-types. Any license-type that is the same as within that blacklist will cause the validation to fail. Any other license-type is allowed. </br> `--whitelist` and `--blacklist` are mutually exclusive! |
| `--export-texts`, `-et` | A path to a directory to where the determined license-texts will be exported. </br> Each license-text will be written to an individual file with the file-name being: `<package-name>-<package-version>.txt`. If the license-text is the content of a website, the contents will be written into an \".html\" file instead |
| `--export-json`, `-ej` | A path to a JSON-file to which the determined license- and package-information will be exported. All the information will be written to a single JSON-file. </br> If the file already exists it will be overwritten. |
| `--timeout`, `-t` | The timeout for a request (i.e. to get the license text from a website) in **seconds**. </br> After this amount of time a request will be considered as failed and aborted. </br> This defaults to 10 seconds |
| `--project-excludes`, `-pe` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain projects. A project will be excluded when it matches at least one glob-pattern. The pattern will be matched against the absolute path of the project-file. All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |
| `--dependency-excludes`, `-de` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain packages. A package will be excluded when it matches at least one glob-pattern. The pattern will be matched against the name of the package. All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |

## Examples

Expand Down Expand Up @@ -264,3 +267,63 @@ You can also use files that are stored remotely. Just use the web link to the re
# local
> dotnet liz "path/to/project.csproj" --blacklist "http://path/to/blacklist.json"
```

#### Excluding projects

Create a JSON-File that contains your glob-patterns. If you want to exclude all your test-projects when you're scanning a whole solution, create a `project-excludes.json` (you can choose any other name of course) like this:

```json
[
"*/**/*Tests.csproj"
]
```

This will disallow every project whose file-name ends with `Tests.csproj`. You can then use it like this:

```bash
# global
> liz "path/to/solution.sln" --project-excludes "path/to/project-excludes.json"

# local
> dotnet liz "path/to/solution.sln" --project-excludes "path/to/project-excludes.json"
```

You can also use files that are stored remotely. Just usse the web link to the resource:

```bash
# global
> liz "path/to/solution.sln" --project-excludes "http://path/to/project-excludes.json"

# local
> dotnet liz "path/to/solution.sln" --project-excludes "http://path/to/project-excludes.json"
```

#### Excluding packages

Create a JSON-File that contains your glob-patterns. If you want to exclude all the packages of your company, create a `package-excludes.json` (you can choose any other name of course) like this:

```json
[
"YourCompany*"
]
```

This will disallow every package whose name starts with "YourCompany". You can then use it like this:

```bash
# global
> liz "path/to/project.csproj" --dependency-excludes "path/to/package-excludes.json"

# local
> dotnet liz "path/to/project.csproj" --dependency-excludes "path/to/package-excludes.json"
```

You can also use files that are stored remotely. Just usse the web link to the resource:

```bash
# global
> liz "path/to/project.csproj" --dependency-excludes "http://path/to/package-excludes.json"

# local
> dotnet liz "path/to/project.csproj" --dependency-excludes "http://path/to/package-excludes.json"
```
32 changes: 32 additions & 0 deletions doc/documentation-nuke-addon.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ The settings contain the following options which can be set according to your ne
| `LicenseTypeBlacklist` | A list of license-types, which are the only ones disallowed, when validating the determined license-types. Any license-type that is the same as within that blacklist will cause the validation to fail. Any other license-type is allowed. </br> This option is mutually exclusive with `LicenseTypeWhitelist` and `LicenseTypeWhitelistFilePath` |
| `LicenseTypeBlacklistFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of license-types, which are the only ones disallowed, when validating the determined license-types. Any license-type that is the same as within that blacklist will cause the validation to fail. Any other license-type is allowed. </br> This option is mutually exclusive with `LicenseTypeWhitelist` and `LicenseTypeWhitelistFilePath` </br> If both `LicenseTypeBlacklist` and `LicenseTypeBlacklistFilePath` are given, those two will be merged |
| `ExportLicenseTextsDirectory` | A path to a directory to where the determined license-texts will be exported </br> Each license-text will be written to an individual file with the file-name being: `<package-name>-<package-version>.txt`. If the license-text is the content of a website, the contents will be written into an ".html" file instead |
| `ExportJsonFile` | A path to a JSON-file to which the determined license- and package-information will be exported. All the information will be written to a single JSON-file. </br> If the file already exists it will be overwritten. |
| `RequestTimeout` | The timeout for a request (i.e. to get the license text from a website). </br> After this amount of time a request will be considered as failed and aborted. </br> This defaults to 10 seconds |
| `ProjectExclusionGlobs` | A list of glob-patterns to exclude certain projects. A project will be excluded when it matches at least one glob-pattern. The pattern will be matched against absolute path of the project-file. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |
| `ProjectExclusionGlobsFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain projects. A project will be excluded when it matches at least one glob-pattern The pattern will be matched against the absolute path of the project-file. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) </br> If both `ProjectExclusionGlobs` and `ProjectExclusionGlobsFilePath` are given, those two will be merged. |
| `PackageExclusionGlobs` | A list of glob-patterns to exclude certain packages. A package will be excluded when it matches at least one glob-pattern. The pattern will be matched against the name of the package. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) |
| `PackageExclusionGlobsFilePath` | A path to a JSON-File (local or remote - remote will be downloaded automatically if available) containing a list of glob-patterns to exclude certain packages. A package will be excluded when it matches at least one glob-pattern The pattern will be matched against the name of the package. </br> All available patterns can be found [here](https://github.com/dazinator/DotNet.Glob/tree/3.1.3#patterns) </br> If both `PackageExclusionGlobs` and `PackageExclusionGlobsFilePath` are given, those two will be merged. |

To support the Nuke-specific way of configuring the settings in a Fluent-API way, following extensions were added as well:

Expand Down Expand Up @@ -82,8 +87,15 @@ To support the Nuke-specific way of configuring the settings in a Fluent-API way
| `SetLicenseTypeBlacklistFilePath` | Sets the `LicenseTypeBlacklistFilePath` property to the given value |
| | |
| `SetExportLicenseTextsDirectory` | Sets the `ExportLicenseTextsDirectory` property to the given value |
| `SetExportJsonFileDirectory` | Sets the `ExportJsonFile` property to the given value |
| | |
| `SetRequestTimeout` | Sets the `RequestTimeout` property to the given value |
| | |
| `SetProjectExclusionGlobs` | Sets the `ProjectExclusionGlobs` property to the given value |
| `SetProjectExclusionGlobsFilePath` | Sets the `ProjectExclusionGlobsFilePath` property to the given value |
| | |
| `SetPackageExclusionGlobs` | Sets the `PackageExclusionGlobs` property to the given value |
| `SetPackageExclusionGlobsFilePath` | Sets the `PackageExclusionGlobsFilePath` property to the given value |

## Example Usages

Expand Down Expand Up @@ -264,3 +276,23 @@ await ExtractLicensesTasks.ExtractLicensesAsync(settings => settings
await ExtractLicensesTasks.ExtractLicensesAsync(settings => settings
.SetLicenseTypeBlacklistFilePath("http://path/to/file.json");
```

#### Exluding projects

If you want to for instance exclude all the test-projects when you're scanning a whole solution, you can use something like the following:

```cs
// this will specifically disallow any project that ends with "Tests.csproj"
await ExtractLicensesTasks.ExtractLicensesAsync(settings => settings
.SetProjectExclusionGlobs(new List<string>{ "*/**/*Tests.csproj" }));
```

#### Exluding packages

If you want to for instance exclude all the packages of your company, you can use something like the following:

```cs
// this will specifically disallow any project that ends with "Tests.csproj"
await ExtractLicensesTasks.ExtractLicensesAsync(settings => settings
.SetPackageExclusionGlobs(new List<string>{ "YourCompany*" }));
```
1 change: 1 addition & 0 deletions src/Cake/Liz.Cake/Liz.Cake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IsTrimmable>true</IsTrimmable>

<Authors>Martin Wagenführ</Authors>
<Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GetProjectReferencesTests
[Fact]
public void Gets_Project_References_Of_Liz_Tool_Project_Correctly()
{
const string lizToolProjectPath = "../../../../../Tool/Liz.Tool.Tests/Liz.Tool.Tests.csproj";
const string lizToolProjectPath = "../../../../../Tool/Liz.Tool/Liz.Tool.csproj";

var fileSystem = new FileSystem();
var lizToolProjectFile = fileSystem.FileInfo.FromFileName(lizToolProjectPath);
Expand Down
14 changes: 7 additions & 7 deletions src/Core/Liz.Core.Tests/Liz.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArrangeContext.Moq" Version="2.0.0"/>
<PackageReference Include="ArrangeContext.Moq" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.6.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0"/>
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.0.11"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.analyzers" Version="0.10.0"/>
<PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.0.11" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Liz.Core\Liz.Core.csproj"/>
<ProjectReference Include="..\Liz.Core\Liz.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Liz.Core.Projects.Contracts.Models;
using Moq;
using System.IO.Abstractions;
using FluentAssertions;
using Liz.Core.PackageReferences.Contracts.Models;
using Liz.Core.Settings;
using Xunit;

namespace Liz.Core.Tests.PackageReferences;
Expand Down Expand Up @@ -97,4 +100,47 @@ public async Task GetFromProject_And_Get_From_Packages_Config_On_Non_Sdk_Style_F
.Verify(getPackage => getPackage.GetFromProjectAsync(project, includeTransitive),
Times.Once);
}

[Fact]
public async Task GetFromProject_And_Exclude_Packages_According_To_Globs()
{
var settings = Mock.Of<ExtractLicensesSettingsBase>();
settings.PackageExclusionGlobs.Add("Test*");

var context = new ArrangeContext<GetPackageReferencesFacade>();
context.Use(settings);

var sut = context.Build();

var packages = new[]
{
new PackageReference("Test", "net6.0", "1.2.3"),
new PackageReference("Test.Core", "net6.0", "1.2.3"),
new PackageReference("Test.Utils.Core", "net6.0", "1.2.3"),
new PackageReference("Testinson", "net6.0", "1.2.3"),
new PackageReference("Martin", "net6.0", "1.2.3")
};

context
.For<IGetPackageReferencesViaDotnetCli>()
.Setup(getPackageReferences => getPackageReferences.GetFromProjectAsync(It.IsAny<Project>(), It.IsAny<bool>()))
.ReturnsAsync(packages);

var projectFileMock = new Mock<IFileInfo>();
projectFileMock
.SetupGet(file => file.Exists)
.Returns(true);

var project = new Project("Something", projectFileMock.Object, ProjectFormatStyle.SdkStyle);

var result = (await sut.GetFromProjectAsync(project, true)).ToList();

result
.Should()
.HaveCount(1);

result
.Should()
.OnlyContain(package => package.Name == "Martin");
}
}
Loading

0 comments on commit 01867e0

Please sign in to comment.