Skip to content

Commit

Permalink
Enhancements for building licenses for applications (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcdavid authored May 4, 2020
1 parent 2764582 commit f79e4b8
Show file tree
Hide file tree
Showing 26 changed files with 1,310 additions and 395 deletions.
64 changes: 39 additions & 25 deletions NugetUtility.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NugetUtility", "src\\NugetUtility.csproj", "{03100542-3DCF-4DFF-8357-9862CCB7EDC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {700E1E7A-220C-47D2-9D2B-EF080CD42ACA}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NugetUtility", "src\NugetUtility.csproj", "{03100542-3DCF-4DFF-8357-9862CCB7EDC4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NugetUtility.Tests", "tests\NugetUtility.Tests\NugetUtility.Tests.csproj", "{469490F0-DD86-4FAD-ADBD-D8D151F9EADA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_SolutionItems", "_SolutionItems", "{5BF8EC73-735D-4349-97E6-CA1B8C4B758B}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
.travis.yml = .travis.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03100542-3DCF-4DFF-8357-9862CCB7EDC4}.Release|Any CPU.Build.0 = Release|Any CPU
{469490F0-DD86-4FAD-ADBD-D8D151F9EADA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{469490F0-DD86-4FAD-ADBD-D8D151F9EADA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{469490F0-DD86-4FAD-ADBD-D8D151F9EADA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{469490F0-DD86-4FAD-ADBD-D8D151F9EADA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {700E1E7A-220C-47D2-9D2B-EF080CD42ACA}
EndGlobalSection
EndGlobal
71 changes: 49 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,77 @@

A .net core tool to print the licenses of a project. This tool support .NET Core and .NET Standard Projects.

## Usage

Usage: dotnet-project-licenses [options]

** Options:

| Option | Description |
|------|-------------|
| `-i` | Project Folder |

## dotnet-project-licenses tool

**Install tool**
### Install tool

```
```ps
dotnet tool install --global dotnet-project-licenses
```

**Uninstall tool**
### Uninstall tool

```
```ps
dotnet tool uninstall --global dotnet-project-licenses
```

## Using tool
## Usage

```
Usage: dotnet-project-licenses [options]

** Options:

| Option | Description |
|------|-------------|
| `-i, --input` | Project Folder |
| `--allowed-license-types` | Simple json file of a text array of allowable licenses, if no file is given, all are assumed allowed |
| `-j, --json` | (Default: false) Saves licenses list in a json file (licenses.json) |
| `--include-project-file` | (Default: false) Adds project file path to information when enabled. |
| `-l, --log-level` | (Default: Error) Sets log level for output display. Options: Error,Warning,Information,Verbose. |
| `--manual-package-information` | Simple json file of an array of LibraryInfo objects for manually determined packages. |
| `--licenseurl-to-license-mappings` | Simple json file of Dictinary<string,string> to override default mappings |
| `-o, --output` | (Default: false) Saves as text file (licenses.txt) |
| `--outfile` | Output filename |
| `--projects-filter` | Simple json file of a text array of projects to skip. Supports Ends with matching such as 'Tests.csproj' |
| `--packages-filter` | Simple json file of a text array of packages to skip. |
| `-u, --unique` | (Default: false) Unique licenses list by Id/Version |
| `-p, --print` | (Default: true) Print licenses. |
| `--help` | Display this help screen. |
| `--version` | Display version information. |

## Example tool commands

```ps
dotnet-project-licenses --help
```

```ps
dotnet-project-licenses -i projectFolder
```

**Print unique licenses:**
```
### Print unique licenses

Values for the input may include a folder path, a Visual Studio '.sln' file, or a '.csproj' file.

```ps
dotnet-project-licenses -i projectFolder -u
```

** Create output file
```
### Creates output file of unique licenses in a plain text 'licenses.txt' file in current directory

```ps
dotnet-project-licenses -i projectFolder -u -o
```

** Generate output json file
### Create output file 'new-name.txt' in another directory

```ps
dotnet-project-licenses -i projectFolder -o --outfile ../../../another/folder/new-name.txt
```

### Creates output json file of unique licences in a file 'licenses.json' in the current directory

```ps
dotnet-project-licenses -i projectFolder -u -o -j
```
```
24 changes: 24 additions & 0 deletions src/InvalidLicensesException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace NugetUtility
{
public class InvalidLicensesException : Exception
{
public InvalidLicensesException(ValidationResult validationResult, ICollection<string> allowedLicenses) : base(GetMessage(validationResult, allowedLicenses))
{
}

private static string GetMessage(ValidationResult validationResult, ICollection<string> allowedLicenses)
{
allowedLicenses = allowedLicenses ?? Array.Empty<string>();

return $"Only the following packages are allowed: {string.Join(", ", allowedLicenses.ToArray())}{Environment.NewLine}"
+ string.Join(Environment.NewLine, validationResult.InvalidPackages.Select(x =>
{
return $"Project ({x.Key}) Package({x.Value.Metadata.Id}-{x.Value.Metadata.Version}) LicenseUrl({x.Value.Metadata.LicenseUrl}) License Type ({x.Value.Metadata.License?.Text})";
}));
}
}
}
21 changes: 21 additions & 0 deletions src/LibraryNameAndVersionComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace NugetUtility
{
public class LibraryNameAndVersionComparer : IEqualityComparer<LibraryInfo>
{
public static LibraryNameAndVersionComparer Default = new LibraryNameAndVersionComparer();

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

public int GetHashCode([DisallowNull] LibraryInfo obj)
{
return obj.PackageName.GetHashCode() ^ obj.PackageVersion.GetHashCode();
}
}
}
21 changes: 21 additions & 0 deletions src/LicenseToUrlMappings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace NugetUtility
{
public class LicenseToUrlMappings : Dictionary<string, string>
{
public LicenseToUrlMappings() { }

public LicenseToUrlMappings(IDictionary<string, string> dictionary) : base(dictionary)
{
}

public static LicenseToUrlMappings Default { get; } = new LicenseToUrlMappings
{
{ "http://www.apache.org/licenses/LICENSE-2.0.html", "Apache2.0" },
{ "http://www.apache.org/licenses/LICENSE-2.0", "Apache2.0" },
{ "http://aws.amazon.com/apache2.0/", "Apache2.0" },
{ "https://opensource.org/licenses/MS-PL", "MS-PL" }
};
}
}
12 changes: 12 additions & 0 deletions src/LogLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NugetUtility
{
public enum LogLevel
{
None = 0,
Verbose = 100,
Information = 200,
Warning = 300,
Error = 400,
Always = 500
}
}
Loading

0 comments on commit f79e4b8

Please sign in to comment.