-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from danielklecha/master
Search for license in repository url and in local package folder
- Loading branch information
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DotnetThirdPartyNotices/LicenseResolvers/Interfaces/IRepositoryUriLicenseResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotnetThirdPartyNotices.LicenseResolvers.Interfaces; | ||
|
||
internal interface IRepositoryUriLicenseResolver : ILicenseResolver | ||
{ | ||
bool CanResolve(Uri projectUri); | ||
Task<string> Resolve(Uri projectUri); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/DotnetThirdPartyNotices/LicenseResolvers/LocalPackageLicenseResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using DotnetThirdPartyNotices.LicenseResolvers.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotnetThirdPartyNotices.LicenseResolvers; | ||
|
||
internal class LocalPackageLicenseResolver : IFileVersionInfoLicenseResolver | ||
{ | ||
public bool CanResolve( FileVersionInfo fileVersionInfo ) => true; | ||
|
||
public async Task<string> Resolve( FileVersionInfo fileVersionInfo ) | ||
{ | ||
var packageName = Path.GetFileNameWithoutExtension(fileVersionInfo.FileName); | ||
var directoryParts = Path.GetDirectoryName(fileVersionInfo.FileName ).Split('\\', StringSplitOptions.RemoveEmptyEntries); | ||
for ( var i = 0; i < directoryParts.Length; i++ ) | ||
{ | ||
var directoryPath = string.Join('\\', directoryParts.SkipLast(i)); | ||
var licensePath = Directory.EnumerateFiles(directoryPath, "license.txt", SearchOption.TopDirectoryOnly) | ||
.FirstOrDefault(); | ||
if (licensePath != null) | ||
return await File.ReadAllTextAsync(licensePath); | ||
if (directoryPath.EndsWith($"\\{packageName}", StringComparison.OrdinalIgnoreCase)) | ||
break; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters