Skip to content

Commit 4417652

Browse files
committed
Merge remote-tracking branch 'origin/issue-15'
2 parents fefc4eb + 608d5ce commit 4417652

File tree

3 files changed

+118
-66
lines changed

3 files changed

+118
-66
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog for `dotnet-delice`
22

3+
## Unreleased
4+
5+
### Changed
6+
7+
- Detecting dotnet tool references and handling them (issue #15)
8+
39
## [1.4.0] - 2020-01-10
410

511
### Changed

src/DotNetDelice.Licensing/LicenseBuilder.fs

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,80 +34,84 @@ let rec private findPackage paths identity logger =
3434
| pkg -> Some(pkg, head)
3535
| [] -> None
3636

37-
38-
let getPackageLicense (projectSpec: PackageSpec) checkGitHub token checkLicenseContent (lib: LockFileLibrary) =
39-
let identity = PackageIdentity(lib.Name, lib.Version)
40-
41-
let checkLicenseContents' name url =
42-
if checkLicenseContent then checkLicenseContents name url
43-
else None
44-
45-
let nugetPaths =
46-
[| projectSpec.RestoreMetadata.PackagesPath |]
47-
|> Seq.append projectSpec.RestoreMetadata.FallbackFolders
48-
|> Seq.toList
49-
50-
match findPackage nugetPaths identity MemoryLogger.Instance with
51-
| None ->
52-
{ PackageName = lib.Name
53-
PackageVersion = lib.Version
54-
Type = lib.Type }
55-
|> PackageNotFound
56-
| Some(pId, path) ->
57-
let licenseMetadata =
58-
{ Type = None
59-
Version = None
60-
Url = pId.Nuspec.GetLicenseUrl()
61-
PackageName = lib.Name
62-
PackageVersion = lib.Version }
63-
match pId.Nuspec.GetLicenseMetadata() with
64-
| null ->
65-
let url = pId.Nuspec.GetLicenseUrl()
66-
match checkGitHub, knownLicenseCache.TryFind url with
67-
| (_, Some cachedLicense) ->
37+
let private buildLicenseFromPackage checkGitHub token checkLicenseContents' (identity: PackageIdentity) packagePath
38+
(pId: LocalPackageInfo) path =
39+
let licenseMetadata =
40+
{ Type = None
41+
Version = None
42+
Url = pId.Nuspec.GetLicenseUrl()
43+
PackageName = identity.Id
44+
PackageVersion = identity.Version }
45+
match pId.Nuspec.GetLicenseMetadata() with
46+
| null ->
47+
let url = pId.Nuspec.GetLicenseUrl()
48+
match checkGitHub, knownLicenseCache.TryFind url with
49+
| (_, Some cachedLicense) ->
50+
{ licenseMetadata with
51+
Type = Some cachedLicense.Expression
52+
Version = None }
53+
|> Licensed
54+
| (true, None) ->
55+
match checkLicenseViaGitHub token url with
56+
| Some cachedLicense ->
6857
{ licenseMetadata with
6958
Type = Some cachedLicense.Expression
7059
Version = None }
7160
|> Licensed
72-
| (true, None) ->
73-
match checkLicenseViaGitHub token url with
74-
| Some cachedLicense ->
75-
{ licenseMetadata with
76-
Type = Some cachedLicense.Expression
77-
Version = None }
78-
|> Licensed
79-
| None ->
80-
match checkLicenseContents' lib.Name url with
81-
| Some cachedLicense ->
82-
{ licenseMetadata with
83-
Type = Some cachedLicense.Expression
84-
Version = None }
85-
|> Licensed
86-
| None -> licenseMetadata |> LegacyLicensed
87-
| (false, None) ->
88-
match checkLicenseContents' lib.Name url with
61+
| None ->
62+
match checkLicenseContents' identity.Id url with
8963
| Some cachedLicense ->
9064
{ licenseMetadata with
9165
Type = Some cachedLicense.Expression
9266
Version = None }
9367
|> Licensed
9468
| None -> licenseMetadata |> LegacyLicensed
95-
| license when license.Type = LicenseType.File ->
96-
match Path.Combine(path, lib.Path, license.License)
97-
|> File.ReadAllText
98-
|> findMatchingLicense with
99-
| Some licenseSpdx ->
69+
| (false, None) ->
70+
match checkLicenseContents' identity.Id url with
71+
| Some cachedLicense ->
10072
{ licenseMetadata with
101-
Type = Some licenseSpdx
102-
Version = Some license.Version }
103-
|> Licensed
104-
| None ->
105-
{ licenseMetadata with
106-
Type = Some license.License
107-
Version = Some license.Version }
73+
Type = Some cachedLicense.Expression
74+
Version = None }
10875
|> Licensed
109-
| license ->
76+
| None -> licenseMetadata |> LegacyLicensed
77+
| license when license.Type = LicenseType.File ->
78+
match Path.Combine(path, packagePath, license.License)
79+
|> File.ReadAllText
80+
|> findMatchingLicense with
81+
| Some licenseSpdx ->
82+
{ licenseMetadata with
83+
Type = Some licenseSpdx
84+
Version = Some license.Version }
85+
|> Licensed
86+
| None ->
11087
{ licenseMetadata with
11188
Type = Some license.License
11289
Version = Some license.Version }
11390
|> Licensed
91+
| license ->
92+
{ licenseMetadata with
93+
Type = Some license.License
94+
Version = Some license.Version }
95+
|> Licensed
96+
97+
let getPackageLicense (projectSpec: PackageSpec) checkGitHub token checkLicenseContent packageName packageVersion
98+
packageType =
99+
let identity = PackageIdentity(packageName, packageVersion)
100+
101+
let checkLicenseContents' name url =
102+
if checkLicenseContent then checkLicenseContents name url else None
103+
104+
let nugetPaths =
105+
[| projectSpec.RestoreMetadata.PackagesPath |]
106+
|> Seq.append projectSpec.RestoreMetadata.FallbackFolders
107+
|> Seq.toList
108+
109+
match findPackage nugetPaths identity MemoryLogger.Instance with
110+
| None ->
111+
{ PackageName = identity.Id
112+
PackageVersion = identity.Version
113+
Type = packageType }
114+
|> PackageNotFound
115+
| Some(pId, path) ->
116+
buildLicenseFromPackage checkGitHub token checkLicenseContents' identity
117+
((sprintf "%s/%A" identity.Id identity.Version).ToLower()) pId path

src/DotNetDelice/App.fs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,31 @@ let findProject path =
3939
let getLicenses checkGitHub token checkLicenseContent (projectSpec: PackageSpec) =
4040
let file = Path.Combine(projectSpec.RestoreMetadata.OutputPath, "project.assets.json")
4141
let lockFile = LockFileUtilities.GetLockFile(file, NullLogger.Instance)
42-
lockFile.Libraries |> Seq.map (getPackageLicense projectSpec checkGitHub token checkLicenseContent)
42+
lockFile.Libraries
43+
|> Seq.map
44+
(fun lib ->
45+
getPackageLicense projectSpec checkGitHub token checkLicenseContent lib.Name lib.Version lib.Type)
46+
47+
let getLicensesForTool checkGitHub token checkLicenseContent (projectSpec: PackageSpec) =
48+
let package =
49+
projectSpec.TargetFrameworks
50+
|> Seq.map (fun fx ->
51+
let dep = fx.Dependencies |> Seq.head
52+
let pkg =
53+
NuGet.Protocol.LocalFolderUtility.GetPackageV3
54+
(projectSpec.RestoreMetadata.PackagesPath, dep.Name, dep.LibraryRange.VersionRange.MinVersion,
55+
MemoryLogger.Instance)
56+
pkg)
57+
|> Seq.head
58+
59+
let depGroups = package.Nuspec.GetDependencyGroups()
60+
61+
depGroups
62+
|> Seq.collect (fun dg -> dg.Packages)
63+
|> Seq.map
64+
(fun p ->
65+
getPackageLicense projectSpec checkGitHub token checkLicenseContent p.Id p.VersionRange.MinVersion
66+
"package")
4367

4468
[<HelpOption>]
4569
type Cli() =
@@ -98,18 +122,36 @@ type Cli() =
98122
"delice only supports SDK project files (.NET Core, NETStandard, etc.), not legacy MSBuild ones (common for .NET Framework)."
99123
| Some dependencyGraph ->
100124
let getLicenses' = getLicenses this.CheckGitHub this.GitHubToken this.CheckLicenseContent
101-
if this.Json then
125+
let projects =
102126
dependencyGraph.Projects
103-
|> Seq.filter (fun projectSpec -> projectSpec.RestoreMetadata.ProjectStyle <> ProjectStyle.Unknown)
127+
|> Seq.filter (fun projectSpec ->
128+
projectSpec.RestoreMetadata.ProjectStyle <> ProjectStyle.Unknown
129+
&& projectSpec.RestoreMetadata.ProjectStyle <> ProjectStyle.DotnetCliTool)
130+
131+
if this.Json then
132+
let toolLicenseResults =
133+
dependencyGraph.Projects
134+
|> Seq.filter (fun ps -> ps.RestoreMetadata.ProjectStyle = ProjectStyle.DotnetCliTool)
135+
|> Seq.map (fun projectSpec ->
136+
getLicensesForTool this.CheckGitHub this.GitHubToken this.CheckLicenseContent projectSpec
137+
|> jsonBuilder projectSpec.Name)
138+
projects
104139
|> Seq.map (fun projectSpec -> getLicenses' projectSpec |> jsonBuilder projectSpec.Name)
140+
|> Seq.append toolLicenseResults
105141
|> jsonPrinter this.JsonOutput
106142
else
107-
dependencyGraph.Projects
108-
|> Seq.filter (fun projectSpec -> projectSpec.RestoreMetadata.ProjectStyle <> ProjectStyle.Unknown)
143+
projects
109144
|> Seq.iter (fun projectSpec ->
110145
getLicenses' projectSpec |> prettyPrint projectSpec.Name
111146
printfn "")
112147

148+
dependencyGraph.Projects
149+
|> Seq.filter (fun ps -> ps.RestoreMetadata.ProjectStyle = ProjectStyle.DotnetCliTool)
150+
|> Seq.iter (fun projectSpec ->
151+
getLicensesForTool this.CheckGitHub this.GitHubToken this.CheckLicenseContent projectSpec
152+
|> prettyPrint projectSpec.Name
153+
printfn "")
154+
113155
let unknownProjectStyles =
114156
dependencyGraph.Projects
115157
|> Seq.filter (fun projectSpec -> projectSpec.RestoreMetadata.ProjectStyle = ProjectStyle.Unknown)

0 commit comments

Comments
 (0)