license_patrol 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +15 -0
- data/VERSION +1 -1
- data/lib/license_patrol/cli/base.rb +1 -0
- data/lib/license_patrol/cli/main.rb +4 -0
- data/lib/license_patrol/configuration.rb +4 -0
- data/lib/license_patrol/core.rb +1 -0
- data/lib/license_patrol/package_managers/bundler.rb +77 -38
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4654e0d8c8444ded245bd4960a0897b7ec961ac6329751ae545cefbf907adbd2
|
|
4
|
+
data.tar.gz: c7b5677df462576bd56bc82f3114052cbd136afba270effcf19427d8621b5e9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01cd7fd00cacc1e8e150294fcdd43abc35261fe2da6e82138e5cc6a335d3503120df25ce0728888bd30cbabae39cd0c81df1c427a7c0b681ef2b4c97f2b8f5e3
|
|
7
|
+
data.tar.gz: aed4baf70fad953b9c6fdf6a851e5c1cb0dc6f501f115b9676771b7c82967fd1c40776b36635805961e24ce37896c128436939f80be9ac6acbcb930afa1d6652
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
# [1.
|
|
1
|
+
# [1.1.0] / 2026-10-21
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
* `bundler_gemfiles` option to scan many gemfiles, such as Appraisal's `gemfiles/*.gemfile`, in one run - [5d7e1372](https://github.com/powerhome/license_patrol/commit/5d7e1372) - Carlos Palhares
|
|
5
|
+
|
|
6
|
+
# [1.0.0] / 2026-10-21
|
|
2
7
|
|
|
3
8
|
First release as `license_patrol`, forked from LicenseFinder 7.2.1. Earlier entries are LicenseFinder's history.
|
|
4
9
|
|
|
@@ -1068,3 +1073,5 @@ Bugfixes:
|
|
|
1068
1073
|
[7.1.0]: https://github.com/pivotal/LicenseFinder/compare/v7.0.1...v7.1.0
|
|
1069
1074
|
[7.2.0]: https://github.com/pivotal/LicenseFinder/compare/v7.1.0...v7.2.0
|
|
1070
1075
|
[7.2.1]: https://github.com/pivotal/LicenseFinder/compare/v7.2.0...v7.2.1
|
|
1076
|
+
[1.0.0]: https://github.com/powerhome/license_patrol/releases/tag/v1.0.0
|
|
1077
|
+
[1.1.0]: https://github.com/powerhome/license_patrol/compare/v1.0.0...v1.1.0
|
data/README.md
CHANGED
|
@@ -466,6 +466,18 @@ If you store rebar dependencies in a custom directory (by setting `deps_dir` in
|
|
|
466
466
|
You can also invoke a custom Mix script `remix` with `--mix_command remix` and
|
|
467
467
|
set `--mix_deps_dir` to fetch Mix dependencies from a custom directory.
|
|
468
468
|
|
|
469
|
+
By default, `bundler` dependencies are read from the gemfile in `BUNDLE_GEMFILE`,
|
|
470
|
+
or from `Gemfile`. If your project locks dependencies in more than one gemfile
|
|
471
|
+
(e.g. when using [Appraisal](https://github.com/thoughtbot/appraisal)), pass all
|
|
472
|
+
of them to `--bundler_gemfiles`, relative to the project path. Glob patterns are
|
|
473
|
+
accepted, as long as they are quoted:
|
|
474
|
+
|
|
475
|
+
```
|
|
476
|
+
$ license_patrol --bundler_gemfiles Gemfile 'gemfiles/*.gemfile'
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
Every gem locked by any of the gemfiles will be reported, once per version.
|
|
480
|
+
|
|
469
481
|
### Narrow down Package Manager
|
|
470
482
|
|
|
471
483
|
By default, license_patrol will check for all supported package managers,
|
|
@@ -492,6 +504,9 @@ rebar_command: './rebarw'
|
|
|
492
504
|
rebar_deps_dir: './rebar_deps'
|
|
493
505
|
mix_command: './mixw'
|
|
494
506
|
mix_deps_dir: './mix_deps'
|
|
507
|
+
bundler_gemfiles:
|
|
508
|
+
- Gemfile
|
|
509
|
+
- gemfiles/*.gemfile
|
|
495
510
|
enabled_package_managers:
|
|
496
511
|
- bundler
|
|
497
512
|
- gradle
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.1.0
|
|
@@ -24,6 +24,10 @@ module LicensePatrol
|
|
|
24
24
|
'junit' => JunitReport
|
|
25
25
|
}.freeze
|
|
26
26
|
|
|
27
|
+
class_option :bundler_gemfiles,
|
|
28
|
+
type: :array,
|
|
29
|
+
desc: "Gemfiles to be scanned, relative to the project path. Accepts glob patterns (e.g. 'gemfiles/*.gemfile' for Appraisal).
|
|
30
|
+
Only meaningful if used with a Ruby/bundler project. Defaults to BUNDLE_GEMFILE, or 'Gemfile'."
|
|
27
31
|
class_option :go_full_version, desc: 'Whether dependency version should include full version. Only meaningful if used with a Go project. Defaults to false.'
|
|
28
32
|
class_option :gradle_include_groups, desc: 'Whether dependency name should include group id. Only meaningful if used with a Java/gradle project. Defaults to false.'
|
|
29
33
|
class_option :gradle_command,
|
data/lib/license_patrol/core.rb
CHANGED
|
@@ -95,6 +95,7 @@ module LicensePatrol
|
|
|
95
95
|
log_directory: File.join(config.log_directory, project_name),
|
|
96
96
|
ignored_groups: decisions.ignored_groups,
|
|
97
97
|
enabled_package_manager_ids: config.enabled_package_manager_ids,
|
|
98
|
+
bundler_gemfiles: config.bundler_gemfiles,
|
|
98
99
|
go_full_version: config.go_full_version,
|
|
99
100
|
gradle_command: config.gradle_command,
|
|
100
101
|
gradle_include_groups: config.gradle_include_groups,
|
|
@@ -2,23 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
require 'bundler'
|
|
4
4
|
require 'securerandom'
|
|
5
|
+
require 'shellwords'
|
|
5
6
|
|
|
6
7
|
module LicensePatrol
|
|
7
8
|
class Bundler < PackageManager
|
|
8
9
|
def initialize(options = {})
|
|
9
10
|
super
|
|
10
11
|
@ignored_groups = options[:ignored_groups]
|
|
12
|
+
@gemfiles = Array(options[:bundler_gemfiles]) unless options[:bundler_gemfiles].nil?
|
|
11
13
|
@definition = options[:definition] # dependency injection for tests
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def current_packages
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
log_package_dependencies package
|
|
20
|
-
end
|
|
21
|
-
end
|
|
17
|
+
packages = existing_gemfile_paths.flat_map { |gemfile_path| current_packages_for(gemfile_path) }
|
|
18
|
+
|
|
19
|
+
packages.group_by { |package| [package.name, package.version] }.map do |_, same_packages|
|
|
20
|
+
merge_groups(same_packages)
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
|
|
@@ -32,68 +31,81 @@ module LicensePatrol
|
|
|
32
31
|
gem_path = "lf-bundler-gems-#{SecureRandom.uuid}"
|
|
33
32
|
logger.info self.class, "Running bundle install for #{Dir.pwd} with path #{gem_path}", color: :blue
|
|
34
33
|
|
|
35
|
-
"bundle install #{ignored_groups_argument} --path #{gem_path}".strip
|
|
34
|
+
return "bundle install #{ignored_groups_argument} --path #{gem_path}".strip if existing_gemfile_paths.size <= 1
|
|
35
|
+
|
|
36
|
+
existing_gemfile_paths.map do |gemfile_path|
|
|
37
|
+
gemfile_argument = "--gemfile #{Shellwords.escape(relative_to_project(gemfile_path))}"
|
|
38
|
+
"bundle install #{gemfile_argument} #{ignored_groups_argument} --path #{gem_path}".squeeze(' ')
|
|
39
|
+
end.join(' && ')
|
|
36
40
|
end
|
|
37
41
|
|
|
38
42
|
def possible_package_paths
|
|
39
|
-
|
|
43
|
+
gemfile_paths
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
private
|
|
43
47
|
|
|
44
48
|
attr_reader :ignored_groups
|
|
45
49
|
|
|
46
|
-
def
|
|
47
|
-
|
|
50
|
+
def current_packages_for(gemfile_path)
|
|
51
|
+
with_gemfile(gemfile_path) do
|
|
52
|
+
definition = definition_for(gemfile_path)
|
|
53
|
+
included_groups = definition.groups - ignored_groups.map(&:to_sym)
|
|
54
|
+
logger.debug self.class, "including groups #{included_groups.inspect} from #{gemfile_path}"
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
details(definition, included_groups, gemfile_path).map do |gem_detail, bundle_detail|
|
|
57
|
+
BundlerPackage.new(gem_detail, bundle_detail, logger: logger).tap do |package|
|
|
58
|
+
log_package_dependencies package
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
50
62
|
end
|
|
51
63
|
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
ENV['BUNDLE_GEMFILE'] = gemfile_path.to_s
|
|
55
|
-
yield
|
|
56
|
-
ensure
|
|
57
|
-
ENV['BUNDLE_GEMFILE'] = previous_gemfile
|
|
64
|
+
def definition_for(gemfile_path)
|
|
65
|
+
@definition || ::Bundler::Definition.build(gemfile_path, lockfile_path(gemfile_path), nil)
|
|
58
66
|
end
|
|
59
67
|
|
|
60
|
-
def details
|
|
61
|
-
|
|
68
|
+
def details(definition, included_groups, gemfile_path)
|
|
69
|
+
bundler_details = definition.dependencies
|
|
70
|
+
|
|
71
|
+
gem_details(definition, included_groups, gemfile_path).map do |gem_detail|
|
|
62
72
|
bundle_detail = bundler_details.detect { |bundler_detail| bundler_detail.name == gem_detail.name }
|
|
63
73
|
[gem_detail, bundle_detail]
|
|
64
74
|
end
|
|
65
75
|
end
|
|
66
76
|
|
|
67
|
-
def gem_details
|
|
68
|
-
return @gem_details if @gem_details
|
|
69
|
-
|
|
77
|
+
def gem_details(definition, included_groups, gemfile_path)
|
|
70
78
|
# clear gem paths before running specs_for
|
|
71
79
|
Gem.clear_paths
|
|
72
|
-
if bundler_config_path_found
|
|
80
|
+
if bundler_config_path_found(gemfile_path)
|
|
73
81
|
::Bundler.reset!
|
|
74
82
|
::Bundler.configure
|
|
75
83
|
end
|
|
76
|
-
|
|
84
|
+
definition.specs_for(included_groups)
|
|
77
85
|
end
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
# The same gem (name and version) may be locked by several gemfiles,
|
|
88
|
+
# in which case it should be reported once, but under all its groups.
|
|
89
|
+
def merge_groups(packages)
|
|
90
|
+
packages.first.tap do |package|
|
|
91
|
+
package.groups.concat(packages.drop(1).flat_map(&:groups)).uniq!
|
|
92
|
+
end
|
|
85
93
|
end
|
|
86
94
|
|
|
87
|
-
def
|
|
88
|
-
|
|
95
|
+
def with_gemfile(gemfile_path)
|
|
96
|
+
previous_gemfile = ENV['BUNDLE_GEMFILE']
|
|
97
|
+
ENV['BUNDLE_GEMFILE'] = gemfile_path.to_s
|
|
98
|
+
yield
|
|
99
|
+
ensure
|
|
100
|
+
ENV['BUNDLE_GEMFILE'] = previous_gemfile
|
|
89
101
|
end
|
|
90
102
|
|
|
91
|
-
def lockfile_path
|
|
103
|
+
def lockfile_path(gemfile_path)
|
|
92
104
|
Pathname("#{gemfile_path}.lock")
|
|
93
105
|
end
|
|
94
106
|
|
|
95
107
|
# Bundler keeps the config (e.g. BUNDLE_PATH for vendored gems) next to the gemfile
|
|
96
|
-
def bundler_config_path_found
|
|
108
|
+
def bundler_config_path_found(gemfile_path)
|
|
97
109
|
config_file = gemfile_path.dirname.join('.bundle/config')
|
|
98
110
|
|
|
99
111
|
return false unless File.exist?(config_file)
|
|
@@ -114,14 +126,41 @@ module LicensePatrol
|
|
|
114
126
|
end
|
|
115
127
|
end
|
|
116
128
|
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
# All the gemfiles to be scanned, from the `bundler_gemfiles` option
|
|
130
|
+
# (which accepts glob patterns, e.g. `gemfiles/*.gemfile` for Appraisal),
|
|
131
|
+
# or the one in BUNDLE_GEMFILE, or `Gemfile`, relative to the project path.
|
|
132
|
+
def gemfile_paths
|
|
133
|
+
@gemfile_paths ||= gemfiles.flat_map { |gemfile| expand_gemfile(gemfile) }.uniq
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def existing_gemfile_paths
|
|
137
|
+
gemfile_paths.select(&:exist?)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def gemfiles
|
|
141
|
+
@gemfiles || [default_gemfile]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def relative_to_project(gemfile_path)
|
|
145
|
+
gemfile_path.expand_path.relative_path_from(project_path.expand_path).to_s
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def expand_gemfile(gemfile)
|
|
149
|
+
return [project_path.join(gemfile)] unless glob?(gemfile)
|
|
150
|
+
|
|
151
|
+
Dir.glob(gemfile, base: project_path.to_s).sort
|
|
152
|
+
.reject { |path| path.end_with?('.lock') }
|
|
153
|
+
.map { |path| project_path.join(path) }
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def glob?(gemfile)
|
|
157
|
+
gemfile.match?(/[*?\[{]/)
|
|
119
158
|
end
|
|
120
159
|
|
|
121
160
|
# BUNDLE_GEMFILE is taken as relative to the project path. Through `bundle exec`
|
|
122
161
|
# it gets expanded to an absolute path, which may point to another project
|
|
123
162
|
# (e.g. when using --project_path), in which case only its basename is kept.
|
|
124
|
-
def
|
|
163
|
+
def default_gemfile
|
|
125
164
|
gemfile = ENV['BUNDLE_GEMFILE']
|
|
126
165
|
return 'Gemfile' if gemfile.nil? || gemfile.empty?
|
|
127
166
|
return gemfile unless Pathname(gemfile).absolute?
|