Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom licensee behavior overrides #455

Merged
merged 7 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .licenses/bundler/bundler.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: bundler
version: 2.3.7
version: 2.3.8
type: bundler
summary: The best way to manage your application's dependencies
homepage: https://bundler.io
Expand Down
2 changes: 1 addition & 1 deletion .licenses/bundler/licensee.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: licensee
version: 9.15.1
version: 9.15.2
type: bundler
summary: A Ruby Gem to detect open source project licenses
homepage: https://github.com/benbalter/licensee
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A configuration file specifies the details of enumerating and operating on licen

Configuration can be specified in either YML or JSON formats, with examples given in YML. The example
below describes common configuration values and their purposes. See [configuration options documentation](./configuration)
for in depth information.
for in depth information.

Additionally, some dependency sources have their own specific configuration options. See the [source documentation](./sources) for details.

Expand Down
13 changes: 13 additions & 0 deletions docs/configuration/customizing_licensee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Customize Licensee's behavior

Licensed uses [Licensee](https://github.com/licensee/licensee) to detect and evaluate OSS licenses for project dependencies found during source enumeration. Licensed can optionally [customize Licensee's behavior](https://github.com/licensee/licensee/blob/jonabc-patch-1/docs/customizing.md#customizing-licensees-behavior) based on options set in the configuration file.
Copy link
Contributor

@villelahdenvuo villelahdenvuo Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed you link to your own patch branch, probably should be linked to the main branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah good call


**NOTE** Matching licenses based on package manager metadata and README references is always enabled and cannot currently be configured.

```yml
licensee:
# the confidence threshold is an integer between 1 and 100. the value represents
# the minimum percentage confidence that Licensee must have to report a matched license
# https://github.com/licensee/licensee/blob/jonabc-patch-1/docs/customizing.md#adjusting-the-confidence-threshold
confidence_threshold: 90 # default value: 98
```
28 changes: 28 additions & 0 deletions lib/licensed/commands/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def run_command(report)
files.clear
end

# Run the command for an application configurations.
# Applies a licensee configuration for the duration of the operation.
#
# report - A Licensed::Report object for this command
#
# Returns whether the command succeeded
def run_app(app, report)
with_licensee_configuration(app, report) do
super
end
end

# Run the command for all enumerated dependencies found in a dependency source,
# recording results in a report.
# Enumerating dependencies in the source is skipped if a :sources option
Expand Down Expand Up @@ -136,6 +148,22 @@ def cache_paths
def files
@files ||= Set.new
end

# Configure licensee for the duration of a yielded operation
def with_licensee_configuration(app, report)
licensee_configuration = app["licensee"]
return yield unless licensee_configuration

report["licensee"] = licensee_configuration

if new_threshold = licensee_configuration["confidence_threshold"]
old_threshold, Licensee.confidence_threshold = Licensee.confidence_threshold, new_threshold
end

yield
ensure
Licensee.confidence_threshold = old_threshold if old_threshold
end
end
end
end
2 changes: 1 addition & 1 deletion licensed.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.3.0"

spec.add_dependency "licensee", ">= 9.14.0", "< 10.0.0"
spec.add_dependency "licensee", ">= 9.15.2", "< 10.0.0"
spec.add_dependency "thor", ">= 0.19"
spec.add_dependency "pathname-common_prefix", "~> 0.0.1"
spec.add_dependency "tomlrb", ">= 1.2", "< 3.0"
Expand Down
11 changes: 11 additions & 0 deletions test/commands/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@
end
end

it "sets licensee configuration when evaluating an app" do
config.apps.each do |app|
app["licensee"] = { "confidence_threshold" => 50 }
end

run_command

report = reporter.report.all_reports.find { |r| r.target.is_a?(Licensed::AppConfiguration) }
assert_equal({ "confidence_threshold" => 50 }, report["licensee"])
end

describe "with multiple apps" do
let(:apps) do
[
Expand Down