license_finder 3.1.1 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 956d6a13cb2fb6bdcaa433ec77957db763a41d6b
4
- data.tar.gz: 1f9a2da6f824d793b9dffb6a1e5903de465d8d13
3
+ metadata.gz: 32d2839f00871d5e2e7a3a9e878cff1db69cc16d
4
+ data.tar.gz: 7efb10b41b8f02f96d76cc8c930e633c968577d6
5
5
  SHA512:
6
- metadata.gz: d2fb7013ff3482c23d1fba6c30aef68df057e1c61665f50907ed0f8e1151a0785430c4a233424d8c5d890f426e57234df435dec7c5e7ea70712eb21941271c17
7
- data.tar.gz: 9805ab07f8d85a4b1d34d4a4e26b44c645e4477eef615b870692c9099233ecb072b9acc895917960ad2763c447825a059d7ee04e144a062e2231499b4006cc2a
6
+ metadata.gz: 7788b979fe82a6d433413e3fdfc1c8c0cac611c52f5e6314e6b73a9a4ee5b5e75111ebc6f1fa0b6be9de484b503166c1cc3de63e22772c2751353269a4572dd3
7
+ data.tar.gz: c09196ab1c745506c23bd7e1e17ed6753ec8e7016195eeb55a458cf5df16cb9fde391f0efe25461ce380948717ebfc830c493524e956cc554c70d4e75a42e381
@@ -1,3 +1,14 @@
1
+ # [4.0.0] / 2017-11-10
2
+
3
+ ### Changed
4
+
5
+ * CLI output has been altered to be clear about active states and installed states.
6
+ * option `--subprojects`have been renamed to `--aggregate_paths` in order to be clear about its functionality
7
+
8
+ ### Fixed
9
+
10
+ * Fixed issue where dangling symbolic link would cause License Finder to crash and not continue. Instead, License Finder will now warn about the issue and continue.
11
+
1
12
  # [3.1.0] / 2017-11-10
2
13
 
3
14
  ### Added
@@ -487,6 +498,7 @@ Bugfixes:
487
498
 
488
499
 
489
500
  [Unreleased]: https://github.com/pivotal/LicenseFinder/compare/v3.0.4...HEAD
501
+ [4.0.0]: https://github.com/pivotal/LicenseFinder/compare/v3.1.0...v4.0.0
490
502
  [3.1.0]: https://github.com/pivotal/LicenseFinder/compare/v3.0.4...v3.1.0
491
503
  [3.0.4]: https://github.com/pivotal/LicenseFinder/compare/v3.0.2...v3.0.4
492
504
  [3.0.2]: https://github.com/pivotal/LicenseFinder/compare/v3.0.1...v3.0.2
@@ -1,5 +1,4 @@
1
1
  require_relative '../../support/feature_helper'
2
-
3
2
  describe 'License Finder command line executable' do
4
3
  # As a developer
5
4
  # I want a command-line interface
@@ -47,4 +46,11 @@ describe 'License Finder command line executable' do
47
46
  expect(developer).to be_seeing("Project path '#{File.absolute_path(path)}' does not exist!")
48
47
  expect(developer).to be_receiving_exit_code(1)
49
48
  end
49
+
50
+ specify 'displays an error if symlink to potential license file is dangling' do
51
+ project = LicenseFinder::TestingDSL::BrokenSymLinkDepProject.create
52
+ ENV['GOPATH'] = "#{project.project_dir}/gopath_dep"
53
+ developer.run_license_finder('gopath_dep/src/foo-dep')
54
+ expect(developer).to be_seeing_something_like %r{ERROR: .*my_app/gopath_dep/src/foo-dep/vendor/a/b/LICENSE does not exists}
55
+ end
50
56
  end
@@ -61,12 +61,12 @@ describe 'Diff report' do
61
61
  project2 = developer.create_ruby_app('project_2')
62
62
  project2.depend_on(developer.create_gem('foo', version: '1.0.0', license: 'MIT'))
63
63
  developer
64
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
64
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
65
65
 
66
66
  # Second multi-project report
67
67
  project2.depend_on(developer.create_gem('baz', version: '3.0.0', license: 'BSD'))
68
68
  developer
69
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
69
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
70
70
 
71
71
  # Diff the reports
72
72
  developer.execute_command('license_finder diff report-1.csv report-2.csv --save=diff.csv --format=csv')
@@ -88,14 +88,14 @@ describe 'Diff report' do
88
88
  project2 = developer.create_ruby_app('project_2')
89
89
  project2.depend_on(developer.create_gem('foo', version: '1.0.0', license: 'MIT'))
90
90
  developer
91
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
91
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
92
92
 
93
93
  # Second multi-project report
94
94
  project2.depend_on(developer.create_gem('baz', version: '3.0.0', license: 'BSD'))
95
95
  project1.depend_on(developer.create_gem('bar', version: '3.0.0', license: 'GPLv2'))
96
96
 
97
97
  developer
98
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
98
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
99
99
 
100
100
  # Diff the reports
101
101
  developer.execute_command('license_finder diff report-1.csv report-2.csv --save=diff.csv --format=csv')
@@ -117,14 +117,14 @@ describe 'Diff report' do
117
117
  project2 = developer.create_ruby_app('project_2')
118
118
  project2.depend_on(developer.create_gem('foo', version: '1.0.0', license: 'MIT'))
119
119
  developer
120
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
120
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
121
121
 
122
122
  # Second multi-project report
123
123
  project2.depend_on(developer.create_gem('baz', version: '3.0.0', license: 'BSD'))
124
124
  project1.depend_on(developer.create_gem('bar', version: '3.0.0', license: 'MIT'))
125
125
 
126
126
  developer
127
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
127
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
128
128
 
129
129
  # Diff the reports
130
130
  developer
@@ -149,14 +149,14 @@ describe 'Diff report' do
149
149
  project2 = developer.create_ruby_app('project_2')
150
150
  project2.depend_on(developer.create_gem('foo', version: '1.0.0', license: 'MIT'))
151
151
  developer
152
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
152
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
153
153
 
154
154
  # Second multi-project report
155
155
  project2.depend_on(developer.create_gem('baz', version: '3.0.0', license: 'BSD'))
156
156
  project1.depend_on(developer.create_gem('foo', version: '2.0.0', license: 'BSD'))
157
157
 
158
158
  developer
159
- .execute_command("license_finder report --columns name version licenses subproject_paths --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
159
+ .execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
160
160
 
161
161
  # Diff the reports
162
162
  developer
@@ -178,13 +178,13 @@ describe 'Diff report' do
178
178
 
179
179
  project2 = developer.create_ruby_app('project_2')
180
180
  project2.depend_on(developer.create_gem('foo', version: '2.0.0', license: 'BSD'))
181
- developer.execute_command("license_finder report --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
181
+ developer.execute_command("license_finder report --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-1.csv --format=csv")
182
182
 
183
183
  # Second multi-project report
184
184
  project2.depend_on(developer.create_gem('baz', version: '3.0.0', license: 'BSD'))
185
185
  project1.depend_on(developer.create_gem('foo', version: '2.0.0', license: 'BSD'))
186
186
 
187
- developer.execute_command("license_finder report --subprojects=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
187
+ developer.execute_command("license_finder report --aggregate_paths=#{project1.project_dir} #{project2.project_dir} --save=report-2.csv --format=csv")
188
188
 
189
189
  # Diff the reports
190
190
  developer.execute_command('license_finder diff report-1.csv report-2.csv --save=diff.csv --format=csv')
@@ -1,6 +1,6 @@
1
1
  require_relative '../../support/feature_helper'
2
2
 
3
- describe 'Subproject report' do
3
+ describe 'Aggregate Paths Projects report' do
4
4
  # As a non-technical product owner
5
5
  # I want a single csv report that includes multiple sub-projects
6
6
  # So that I can easily review my composite application's dependencies and licenses
@@ -14,11 +14,11 @@ describe 'Subproject report' do
14
14
  project1.depend_on(foo10)
15
15
 
16
16
  developer.create_empty_project
17
- developer.execute_command("license_finder report --columns name homepage subproject_paths --subprojects #{project1.project_dir} --format=csv")
17
+ developer.execute_command("license_finder report --columns name homepage aggregate_paths --aggregate_paths #{project1.project_dir} --format=csv")
18
18
  expect(developer).to be_seeing_once("foo,http://example.homepage.com,#{project1.project_dir}")
19
19
  end
20
20
 
21
- specify 'shows dependencies for multiple subprojects' do
21
+ specify 'shows dependencies for multiple projects' do
22
22
  project1 = developer.create_ruby_app('project_1')
23
23
  project1.depend_on(developer.create_gem('foo', version: '1.0.0', license: 'MIT'))
24
24
 
@@ -26,7 +26,7 @@ describe 'Subproject report' do
26
26
  project2.depend_on(developer.create_gem('bar', version: '2.0.0', license: 'GPLv2'))
27
27
 
28
28
  developer.create_empty_project
29
- developer.execute_command("license_finder report --columns name version licenses subproject_paths --subprojects #{project1.project_dir} #{project2.project_dir} --format=csv")
29
+ developer.execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths #{project1.project_dir} #{project2.project_dir} --format=csv")
30
30
  expect(developer).to be_seeing("foo,1.0.0,MIT,#{project1.project_dir}")
31
31
  expect(developer).to be_seeing("bar,2.0.0,GPLv2,#{project2.project_dir}")
32
32
  end
@@ -41,7 +41,7 @@ describe 'Subproject report' do
41
41
  project2.depend_on(foo)
42
42
 
43
43
  developer.create_empty_project
44
- developer.execute_command("license_finder report --columns name version licenses subproject_paths --subprojects #{project1.project_dir} #{project2.project_dir} --format=csv")
44
+ developer.execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths #{project1.project_dir} #{project2.project_dir} --format=csv")
45
45
  expect(developer).to be_seeing_once("foo,1.0.0,MIT,\"#{project1.project_dir},#{project2.project_dir}\"")
46
46
  end
47
47
 
@@ -56,7 +56,7 @@ describe 'Subproject report' do
56
56
  project2.depend_on(foo11)
57
57
 
58
58
  developer.create_empty_project
59
- developer.execute_command("license_finder report --columns name version licenses subproject_paths --subprojects #{project1.project_dir} #{project2.project_dir} --format=csv")
59
+ developer.execute_command("license_finder report --columns name version licenses aggregate_paths --aggregate_paths #{project1.project_dir} #{project2.project_dir} --format=csv")
60
60
  expect(developer).to be_seeing_once("foo,1.0.0,MIT,#{project1.project_dir}")
61
61
  expect(developer).to be_seeing_once("foo,1.1.0,MIT,#{project2.project_dir}")
62
62
  end
@@ -1,5 +1,10 @@
1
1
  # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2
2
 
3
+ [[projects]]
4
+ branch = "master"
5
+ name = "a/b"
6
+ packages = ["."]
7
+ revision = "2269160ae1757f96bbb8c6475e6fa36c805e7234"
3
8
 
4
9
  [solve-meta]
5
10
  analyzer-name = "dep"
@@ -0,0 +1 @@
1
+ features/fixtures/gopath_dep/src/foo-dep/vendor/a/b/LICENSE
@@ -249,6 +249,18 @@ module LicenseFinder
249
249
  end
250
250
  end
251
251
 
252
+ class BrokenSymLinkDepProject < Project
253
+ def add_dep
254
+ clone('gopath_dep')
255
+ end
256
+
257
+ def install; end
258
+
259
+ def shell_out(command)
260
+ ProjectDir.new(Paths.root.join('tmp', 'projects', 'my_app', 'gopath_dep', 'src', 'foo-dep')).shell_out(command)
261
+ end
262
+ end
263
+
252
264
  class GovendorProject < Project
253
265
  def add_dep
254
266
  clone('gopath_govendor')
@@ -463,7 +475,7 @@ module LicenseFinder
463
475
  end
464
476
 
465
477
  def install_fixture(fixture_name)
466
- if Platform.windows?
478
+ if RUBY_PLATFORM =~ /mswin|cygwin|mingw/
467
479
  FileUtils.cp(Paths.fixtures.join(fixture_name), join(fixture_name))
468
480
  else
469
481
  join(fixture_name).make_symlink Paths.fixtures.join(fixture_name)
@@ -48,7 +48,17 @@ module LicenseFinder
48
48
  end
49
49
 
50
50
  def logger_config
51
- @logger_config ||= extract_options(:quiet, :debug)
51
+ quiet = LicenseFinder::Logger::MODE_QUIET
52
+ debug = LicenseFinder::Logger::MODE_DEBUG
53
+ info = LicenseFinder::Logger::MODE_INFO
54
+ mode = extract_options(quiet, debug)
55
+ if mode[quiet]
56
+ { mode: quiet }
57
+ elsif mode[debug]
58
+ { mode: debug }
59
+ else
60
+ { mode: info }
61
+ end
52
62
  end
53
63
 
54
64
  def say_each(coll)
@@ -4,6 +4,7 @@ require 'license_finder/diff'
4
4
  require 'license_finder/package_delta'
5
5
  require 'license_finder/license_aggregator'
6
6
  require 'license_finder/project_finder'
7
+ require 'license_finder/logger'
7
8
 
8
9
  module LicenseFinder
9
10
  module CLI
@@ -90,15 +91,15 @@ module LicenseFinder
90
91
  method_option :recursive, aliases: '-r', type: :boolean, default: false,
91
92
  desc: 'Recursively runs License Finder on all sub-projects'
92
93
 
93
- method_option :subprojects, aliases: '-s', type: :array,
94
- desc: "Generate a single report for multiple sub-projects. Ex: --subprojects='path/to/project1', 'path/to/project2'"
94
+ method_option :aggregate_paths, aliases: '-a', type: :array,
95
+ desc: "Generate a single report for multiple projects. Ex: --aggregate_paths='path/to/project1' 'path/to/project2'"
95
96
  def report
96
- logger_config[:quiet] = true
97
- subproject_paths = options[:subprojects]
98
- subproject_paths = ProjectFinder.new(license_finder.config.project_path).find_projects if options[:recursive]
97
+ logger_config[:mode] = Logger::MODE_QUIET
98
+ aggregate_paths = options[:aggregate_paths]
99
+ aggregate_paths = ProjectFinder.new(license_finder.config.project_path).find_projects if options[:recursive]
99
100
 
100
- if subproject_paths && !subproject_paths.empty?
101
- finder = LicenseAggregator.new(license_finder_config, subproject_paths)
101
+ if aggregate_paths && !aggregate_paths.empty?
102
+ finder = LicenseAggregator.new(license_finder_config, aggregate_paths)
102
103
  report = MergedReport.new(finder.dependencies, options)
103
104
  else
104
105
  run_prepare_phase if prepare?
@@ -14,7 +14,7 @@ module LicenseFinder
14
14
  attr_reader :config
15
15
 
16
16
  def self.default_logger
17
- Logger::Default.new
17
+ Logger.new
18
18
  end
19
19
 
20
20
  # Default +options+:
@@ -50,9 +50,9 @@ module LicenseFinder
50
50
  def prepare_projects
51
51
  package_managers = PackageManager.active_package_managers options
52
52
  package_managers.each do |manager|
53
- logger.log manager.class, 'Running prepare on project'
53
+ logger.debug manager.class, 'Running prepare on project'
54
54
  manager.prepare
55
- logger.log manager.class, 'Finished prepare on project', color: :green
55
+ logger.debug manager.class, 'Finished prepare on project', color: :green
56
56
  end
57
57
  end
58
58
 
@@ -64,6 +64,7 @@ module LicenseFinder
64
64
  # packages.
65
65
  def decision_applier
66
66
  # lazy, do not move to `initialize`
67
+ # Needs to be lazy loaded to prvent multiple decision appliers being created each time
67
68
  @applier ||= DecisionApplier.new(decisions: decisions, packages: current_packages)
68
69
  end
69
70
 
@@ -1,22 +1,22 @@
1
1
  module LicenseFinder
2
2
  class LicenseAggregator
3
- def initialize(license_finder_config, subprojects)
3
+ def initialize(license_finder_config, aggregate_paths)
4
4
  @license_finder_config = license_finder_config
5
- @subprojects = subprojects
5
+ @aggregate_paths = aggregate_paths
6
6
  end
7
7
 
8
8
  def dependencies
9
9
  aggregate_packages
10
10
  .group_by { |package| [package.name, package.version] }
11
11
  .map do |_, packages|
12
- MergedPackage.new(packages[0].dependency, packages.flat_map(&:subproject_paths))
12
+ MergedPackage.new(packages[0].dependency, packages.flat_map(&:aggregate_paths))
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
17
 
18
18
  def aggregate_packages
19
- @subprojects.flat_map do |project_path|
19
+ @aggregate_paths.flat_map do |project_path|
20
20
  finder = LicenseFinder::Core.new(@license_finder_config.merge(project_path: project_path))
21
21
  finder.prepare_projects if @license_finder_config[:prepare]
22
22
  finder.acknowledged.map { |dep| MergedPackage.new(dep, [project_path]) }
@@ -1,17 +1,34 @@
1
+ require 'logger'
2
+
1
3
  module LicenseFinder
2
- module Logger
3
- def self.new(options = {})
4
- klass = if options[:quiet]
5
- Quiet
6
- elsif options[:debug]
7
- Verbose
8
- else
9
- Progress
10
- end
11
- klass.new
4
+ class Logger
5
+ MODE_QUIET = :quiet
6
+ MODE_INFO = :info
7
+ MODE_DEBUG = :debug
8
+
9
+ attr_reader :mode
10
+
11
+ def initialize(options = {})
12
+ @system_logger = ::Logger.new(STDOUT)
13
+ @system_logger.formatter = proc do |_, _, _, msg|
14
+ "#{msg}\n"
15
+ end
16
+
17
+ self.mode = options[:mode] || MODE_INFO
18
+ end
19
+
20
+ [MODE_INFO, MODE_DEBUG].each do |level|
21
+ define_method level do |prefix, string, options = {}|
22
+ msg = format('%s: %s', prefix, colorize(string, options[:color]))
23
+ log(msg, level)
24
+ end
12
25
  end
13
26
 
14
- def self.colorize(string, color)
27
+ private
28
+
29
+ attr_reader :system_logger
30
+
31
+ def colorize(string, color)
15
32
  case color
16
33
  when :red
17
34
  "\e[31m#{string}\e[0m"
@@ -22,28 +39,25 @@ module LicenseFinder
22
39
  end
23
40
  end
24
41
 
25
- class Base
26
- def log(_prefix, _string, _options = {})
27
- raise NotImplementedError, '#log must be implemented'
28
- end
29
- end
42
+ def mode=(v)
43
+ @mode = v
30
44
 
31
- class Quiet < Base
32
- def log(prefix, string, options = {}); end
45
+ return if quiet?
46
+ level = @mode.equal?(MODE_DEBUG) ? ::Logger::DEBUG : ::Logger::INFO
47
+ system_logger.level = level
33
48
  end
34
49
 
35
- class Progress < Base
36
- def log(_prefix, _string, _options = {})
37
- print('.') && $stdout.flush
38
- end
50
+ def log(msg, method)
51
+ return if quiet?
52
+ system_logger.send(method, msg)
39
53
  end
40
54
 
41
- class Verbose < Base
42
- def log(prefix, string, options = {})
43
- printf("%s: %s\n", prefix, Logger.colorize(string, options[:color]))
44
- end
55
+ def debug?
56
+ @mode.equal?(MODE_DEBUG)
45
57
  end
46
58
 
47
- Default = Quiet
59
+ def quiet?
60
+ @mode.equal?(MODE_QUIET)
61
+ end
48
62
  end
49
63
  end
@@ -142,7 +142,7 @@ module LicenseFinder
142
142
  end
143
143
 
144
144
  def license_files
145
- LicenseFiles.find(install_path)
145
+ LicenseFiles.find(install_path, logger: logger)
146
146
  end
147
147
 
148
148
  def package_manager
@@ -156,10 +156,10 @@ module LicenseFinder
156
156
  def log_activation(activation)
157
157
  preamble = format('package %s:', activation.package.name)
158
158
  if activation.sources.empty?
159
- logger.log activation.package.class, format('%s no licenses found', preamble)
159
+ logger.debug activation.package.class, format('%s no licenses found', preamble)
160
160
  else
161
161
  activation.sources.each do |source|
162
- logger.log activation.package.class, format("%s found license '%s' %s", preamble, activation.license.name, source)
162
+ logger.debug activation.package.class, format("%s found license '%s' %s", preamble, activation.license.name, source)
163
163
  end
164
164
  end
165
165
  end
@@ -16,8 +16,8 @@ module LicenseFinder
16
16
  pick_package.version
17
17
  end
18
18
 
19
- def subproject_paths
20
- pick_package.subproject_paths
19
+ def aggregate_paths
20
+ pick_package.aggregate_paths
21
21
  end
22
22
 
23
23
  attr_reader :status
@@ -22,12 +22,26 @@ module LicenseFinder
22
22
  Yarn, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget, Carthage, Mix, Conan]
23
23
  end
24
24
 
25
- def active_packages(options)
26
- active_package_managers(options).flat_map(&:current_packages_with_relations)
25
+ def active_packages(options = { project_path: Pathname.new('') })
26
+ package_managers = active_package_managers(options)
27
+ installed_package_managers = package_managers.select { |pm| pm.class.installed?(options[:logger]) }
28
+ installed_package_managers.flat_map(&:current_packages_with_relations)
27
29
  end
28
30
 
29
31
  def active_package_managers(options = { project_path: Pathname.new('') })
30
- active_pm_classes = package_managers.select { |pm_class| pm_class.new(options).active? }
32
+ logger = options[:logger]
33
+
34
+ active_pm_classes = []
35
+ package_managers.each do |pm_class|
36
+ active = pm_class.new(options).active?
37
+ if active
38
+ logger.info pm_class, 'is active', color: :green
39
+ active_pm_classes << pm_class
40
+ else
41
+ logger.debug pm_class, 'is not active', color: :red
42
+ end
43
+ end
44
+
31
45
  active_pm_classes -= active_pm_classes.map(&:takes_priority_over)
32
46
  active_pm_classes.map { |pm_class| pm_class.new(options) }
33
47
  end
@@ -38,13 +52,13 @@ module LicenseFinder
38
52
 
39
53
  def installed?(logger = Core.default_logger)
40
54
  if package_management_command.nil?
41
- logger.log self, 'no command defined' # TODO: comment me out
55
+ logger.debug self, 'no command defined' # TODO: comment me out
42
56
  true
43
57
  elsif command_exists?(package_management_command)
44
- logger.log self, 'is installed', color: :green
58
+ logger.debug self, 'is installed', color: :green
45
59
  true
46
60
  else
47
- logger.log self, 'is not installed', color: :red
61
+ logger.info self, 'is not installed', color: :red
48
62
  false
49
63
  end
50
64
  end
@@ -67,15 +81,7 @@ module LicenseFinder
67
81
 
68
82
  def active?
69
83
  path = detected_package_path
70
- self.class.installed?(logger) &&
71
- !path.nil? &&
72
- path.exist?.tap do |is_active|
73
- if is_active
74
- logger.log self.class, 'is active', color: :green
75
- else
76
- logger.log self.class, 'is not active'
77
- end
78
- end
84
+ path && path.exist?
79
85
  end
80
86
 
81
87
  def detected_package_path
@@ -87,7 +93,7 @@ module LicenseFinder
87
93
  _stdout, _stderr, status = Cmd.run(self.class.prepare_command)
88
94
  raise "Prepare command '#{self.class.prepare_command}' failed" unless status.success?
89
95
  else
90
- logger.log self.class, 'no prepare step provided', color: :red
96
+ logger.debug self.class, 'no prepare step provided', color: :red
91
97
  end
92
98
  end
93
99
 
@@ -103,11 +109,12 @@ module LicenseFinder
103
109
  end
104
110
 
105
111
  def self.command_exists?(command)
106
- if LicenseFinder::Platform.windows?
107
- _stdout, _stderr, status = Cmd.run("where #{command} 2>NUL")
108
- else
109
- _stdout, _stderr, status = Cmd.run("which #{command} 2>/dev/null")
110
- end
112
+ _stdout, _stderr, status =
113
+ if LicenseFinder::Platform.windows?
114
+ Cmd.run("where #{command}")
115
+ else
116
+ Cmd.run("which #{command}")
117
+ end
111
118
 
112
119
  status.success?
113
120
  end
@@ -9,7 +9,7 @@ module LicenseFinder
9
9
  end
10
10
 
11
11
  def current_packages
12
- logger.log self.class, "including groups #{included_groups.inspect}"
12
+ logger.debug self.class, "including groups #{included_groups.inspect}"
13
13
  details.map do |gem_detail, bundle_detail|
14
14
  BundlerPackage.new(gem_detail, bundle_detail, logger: logger).tap do |package|
15
15
  log_package_dependencies package
@@ -60,11 +60,11 @@ module LicenseFinder
60
60
  def log_package_dependencies(package)
61
61
  dependencies = package.children
62
62
  if dependencies.empty?
63
- logger.log self.class, format("package '%s' has no dependencies", package.name)
63
+ logger.debug self.class, format("package '%s' has no dependencies", package.name)
64
64
  else
65
- logger.log self.class, format("package '%s' has dependencies:", package.name)
65
+ logger.debug self.class, format("package '%s' has dependencies:", package.name)
66
66
  dependencies.each do |dep|
67
- logger.log self.class, format('- %s', dep)
67
+ logger.debug self.class, format('- %s', dep)
68
68
  end
69
69
  end
70
70
  end
@@ -38,19 +38,10 @@ module LicenseFinder
38
38
  end
39
39
 
40
40
  def active?
41
- return false unless self.class.installed?(logger)
42
-
43
41
  godep = LicenseFinder::GoDep.new(project_path: Pathname(project_path))
44
42
  # go workspace is only active if GoDep wasn't. There are some projects
45
43
  # that will use the .envrc and have a Godep folder as well.
46
- active = !!(!godep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
47
- active.tap do |is_active|
48
- if is_active
49
- logger.log self.class, 'is active', color: :green
50
- else
51
- logger.log self.class, 'is not active'
52
- end
53
- end
44
+ !!(!godep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
54
45
  end
55
46
 
56
47
  private
@@ -2,9 +2,9 @@ module LicenseFinder
2
2
  class MergedPackage
3
3
  attr_reader :dependency
4
4
 
5
- def initialize(dependency, subproject_paths)
5
+ def initialize(dependency, aggregate_paths)
6
6
  @dependency = dependency
7
- @subproject_paths = subproject_paths.map { |p| Pathname(p) }
7
+ @aggregate_paths = aggregate_paths.map { |p| Pathname(p) }
8
8
  end
9
9
 
10
10
  def name
@@ -47,8 +47,8 @@ module LicenseFinder
47
47
  dependency.package_manager
48
48
  end
49
49
 
50
- def subproject_paths
51
- @subproject_paths.map { |p| p.expand_path.to_s }
50
+ def aggregate_paths
51
+ @aggregate_paths.map { |p| p.expand_path.to_s }
52
52
  end
53
53
 
54
54
  def <=>(other)
@@ -5,17 +5,17 @@ module LicenseFinder
5
5
  CANDIDATE_FILE_NAMES = %w[LICENSE License Licence COPYING README Readme ReadMe].freeze
6
6
  CANDIDATE_PATH_WILDCARD = "*{#{CANDIDATE_FILE_NAMES.join(',')}}*".freeze
7
7
 
8
- def self.find(install_path)
9
- new(install_path).find
8
+ def self.find(install_path, options = {})
9
+ new(install_path).find(options)
10
10
  end
11
11
 
12
12
  def initialize(install_path)
13
13
  @install_path = install_path ? Pathname(install_path) : nil
14
14
  end
15
15
 
16
- def find
16
+ def find(options = {})
17
17
  paths_of_candidate_files
18
- .map { |path| PossibleLicenseFile.new(path) }
18
+ .map { |path| PossibleLicenseFile.new(path, options) }
19
19
  .reject { |file| file.license.nil? }
20
20
  end
21
21
 
@@ -1,7 +1,8 @@
1
1
  module LicenseFinder
2
2
  class PossibleLicenseFile
3
- def initialize(path)
3
+ def initialize(path, options = {})
4
4
  @path = Pathname(path)
5
+ @logger = options[:logger]
5
6
  end
6
7
 
7
8
  def path
@@ -13,7 +14,12 @@ module LicenseFinder
13
14
  end
14
15
 
15
16
  def text
16
- @text ||= (@path.respond_to?(:binread) ? @path.binread : @path.read)
17
+ if @path.exist?
18
+ @text ||= (@path.respond_to?(:binread) ? @path.binread : @path.read)
19
+ else
20
+ @logger.info('ERROR', "#{@path} does not exists", color: :red)
21
+ ''
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -15,7 +15,7 @@ module LicenseFinder
15
15
  end
16
16
 
17
17
  def format_project_paths(dep)
18
- dep.subproject_paths.join(self.class::COMMA_SEP)
18
+ dep.aggregate_paths.join(self.class::COMMA_SEP)
19
19
  end
20
20
 
21
21
  private
@@ -1,14 +1,14 @@
1
1
  module LicenseFinder
2
2
  class MergedReport < CsvReport
3
- AVAILABLE_COLUMNS = AVAILABLE_COLUMNS + ['subproject_paths']
3
+ AVAILABLE_COLUMNS = AVAILABLE_COLUMNS + ['aggregate_paths']
4
4
 
5
5
  def initialize(dependencies, options = {})
6
- options[:columns] ||= %w[name version licenses subproject_paths]
6
+ options[:columns] ||= %w[name version licenses aggregate_paths]
7
7
  super(dependencies, options)
8
8
  end
9
9
 
10
- def format_subproject_paths(merged_dep)
11
- merged_dep.subproject_paths.join(self.class::COMMA_SEP)
10
+ def format_aggregate_paths(merged_dep)
11
+ merged_dep.aggregate_paths.join(self.class::COMMA_SEP)
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module LicenseFinder
2
- VERSION = '3.1.1'.freeze
2
+ VERSION = '4.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Maine
@@ -363,6 +363,7 @@ files:
363
363
  - features/fixtures/gopath_dep/src/foo-dep/Gopkg.toml
364
364
  - features/fixtures/gopath_dep/src/foo-dep/bar/bar.go
365
365
  - features/fixtures/gopath_dep/src/foo-dep/foo.go
366
+ - features/fixtures/gopath_dep/src/foo-dep/vendor/a/b/LICENSE
366
367
  - features/fixtures/gopath_glide/src/glide.lock
367
368
  - features/fixtures/gopath_glide/src/glide.yaml
368
369
  - features/fixtures/gopath_govendor/src/vendor/vendor.json