license_finder 4.0.1 → 4.0.2

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: 32d2839f00871d5e2e7a3a9e878cff1db69cc16d
4
- data.tar.gz: 7efb10b41b8f02f96d76cc8c930e633c968577d6
3
+ metadata.gz: 7666cca63edcbd5d26d92de0d0079eb6baba6f04
4
+ data.tar.gz: bd234f6e53146db0c10bb5aedec7bf2ab9666af0
5
5
  SHA512:
6
- metadata.gz: 7788b979fe82a6d433413e3fdfc1c8c0cac611c52f5e6314e6b73a9a4ee5b5e75111ebc6f1fa0b6be9de484b503166c1cc3de63e22772c2751353269a4572dd3
7
- data.tar.gz: c09196ab1c745506c23bd7e1e17ed6753ec8e7016195eeb55a458cf5df16cb9fde391f0efe25461ce380948717ebfc830c493524e956cc554c70d4e75a42e381
6
+ metadata.gz: 6632cd374b76addc79e2c094aaf2210ec8185319633ca15594eb5217cc29eb954b66e5a21ea081c28a171a6df3aea48f12d58f8a2759f4ac5c87e987121f332e
7
+ data.tar.gz: ff1d7062e96965b57f17260398faa2baa0fd4caffccec01b0d483ece2690e963c75779b3b6561b7b216ca9d4be42a51f1f830b2cfef57e6ebd7a091bd58c2895
@@ -53,4 +53,11 @@ describe 'License Finder command line executable' do
53
53
  developer.run_license_finder('gopath_dep/src/foo-dep')
54
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
55
  end
56
+
57
+ specify 'displays a warning if no package managers are active/installed', :focus do
58
+ developer.create_empty_project
59
+ developer.execute_command('license_finder')
60
+ expect(developer).to be_seeing('No active and installed package managers found for project.')
61
+ expect(developer).to be_receiving_exit_code(0)
62
+ end
56
63
  end
@@ -3,12 +3,24 @@ require_relative '../../support/feature_helper'
3
3
  describe 'Glide Dependencies' do
4
4
  let(:go_developer) { LicenseFinder::TestingDSL::User.new }
5
5
 
6
- specify 'are shown in reports for a project' do
7
- project = LicenseFinder::TestingDSL::GlideProject.create
8
- ENV['GOPATH'] = "#{project.project_dir}/gopath_glide"
6
+ context 'when project is in src directory' do
7
+ specify 'are shown in reports for a project' do
8
+ project = LicenseFinder::TestingDSL::GlideProject.create
9
+ ENV['GOPATH'] = "#{project.project_dir}/gopath_glide"
9
10
 
10
- go_developer.run_license_finder('gopath_glide')
11
- expect(go_developer).to be_seeing_line 'github.com/Masterminds/semver, 517734cc7d6470c0d07130e40fd40bdeb9bcd3fd, MIT'
12
- expect(go_developer).to be_seeing_line 'github.com/Masterminds/cookoo, 78aa11ce75e257c51be7ea945edb84cf19c4a6de, MIT'
11
+ go_developer.run_license_finder('gopath_glide')
12
+ expect(go_developer).to be_seeing_line 'github.com/Masterminds/semver, 517734cc7d6470c0d07130e40fd40bdeb9bcd3fd, MIT'
13
+ expect(go_developer).to be_seeing_line 'github.com/Masterminds/cookoo, 78aa11ce75e257c51be7ea945edb84cf19c4a6de, MIT'
14
+ end
15
+ end
16
+
17
+ context 'when projecy is not in src directory' do
18
+ specify 'are shown in reports for a project' do
19
+ LicenseFinder::TestingDSL::GlideProjectWithoutSrc.create
20
+
21
+ go_developer.run_license_finder('gopath_glide_without_src')
22
+ expect(go_developer).to be_seeing_line 'github.com/Masterminds/semver, 517734cc7d6470c0d07130e40fd40bdeb9bcd3fd, MIT'
23
+ expect(go_developer).to be_seeing_line 'github.com/Masterminds/cookoo, 78aa11ce75e257c51be7ea945edb84cf19c4a6de, MIT'
24
+ end
13
25
  end
14
26
  end
@@ -0,0 +1,9 @@
1
+ hash: 4765849129e9fbb9f7ebc620df51f27b6999f1a06bba4ecf92193ffffcf1d684
2
+ updated: 2017-09-27T22:42:02.817609367Z
3
+ imports:
4
+ - name: github.com/Masterminds/cookoo
5
+ version: 78aa11ce75e257c51be7ea945edb84cf19c4a6de
6
+ repo: https://github.com/Masterminds/cookoo.git
7
+ - name: github.com/Masterminds/semver
8
+ version: 517734cc7d6470c0d07130e40fd40bdeb9bcd3fd
9
+ testImports: []
@@ -0,0 +1,6 @@
1
+ package: github.com/Masterminds/glide
2
+ import:
3
+ - package: github.com/Masterminds/semver
4
+ - package: github.com/Masterminds/cookoo
5
+ version: ^1.2.0
6
+ repo: https://github.com/Masterminds/cookoo.git
@@ -215,6 +215,28 @@ module LicenseFinder
215
215
  end
216
216
  end
217
217
 
218
+ class GlideProjectWithoutSrc < Project
219
+ def add_dep
220
+ clone('gopath_glide_without_src')
221
+ end
222
+
223
+ def install
224
+ src_path = File.join(project_dir, 'gopath_glide_without_src', 'src')
225
+ FileUtils.mkdir_p(src_path)
226
+
227
+ orig_gopath = ENV['GOPATH']
228
+ ENV['GOPATH'] = "#{project_dir}/gopath_glide_without_src"
229
+ shell_out('glide install')
230
+ ENV['GOPATH'] = orig_gopath
231
+
232
+ FileUtils.rmdir(src_path)
233
+ end
234
+
235
+ def shell_out(command)
236
+ ProjectDir.new(Paths.root.join('tmp', 'projects', 'my_app', 'gopath_glide_without_src')).shell_out(command)
237
+ end
238
+ end
239
+
218
240
  class GvtProject < Project
219
241
  def add_dep
220
242
  clone('gopath_gvt')
@@ -47,16 +47,23 @@ module LicenseFinder
47
47
  desc: 'Prepares the project first for license_finder',
48
48
  default: false,
49
49
  required: false
50
+
51
+ method_option :recursive, aliases: '-r', type: :boolean, default: false,
52
+ desc: 'Recursively runs License Finder on all sub-projects'
53
+
54
+ method_option :aggregate_paths, aliases: '-a', type: :array,
55
+ desc: "Generate a single report for multiple projects. Ex: --aggregate_paths='path/to/project1' 'path/to/project2'"
56
+
57
+ method_option :quiet, aliases: '-q', type: :boolean, desc: 'Silences progress report', required: false
50
58
  end
51
59
 
52
60
  desc 'action_items', 'List unapproved dependencies (the default action for `license_finder`)'
53
- method_option :quiet, aliases: '-q', type: :boolean, desc: 'Silences progress report', required: false
54
61
  shared_options
55
62
  def action_items
56
- run_prepare_phase if prepare?
57
- any_packages = license_finder.any_packages?
58
- unapproved = license_finder.unapproved
59
- blacklisted = license_finder.blacklisted
63
+ finder = LicenseAggregator.new(license_finder_config, aggregate_paths)
64
+ any_packages = finder.any_packages?
65
+ unapproved = finder.unapproved
66
+ blacklisted = finder.blacklisted
60
67
 
61
68
  # Ensure to start output on a new line even with dot progress indicators.
62
69
  say "\n"
@@ -88,11 +95,7 @@ module LicenseFinder
88
95
 
89
96
  desc 'report', "Print a report of the project's dependencies to stdout"
90
97
  shared_options
91
- method_option :recursive, aliases: '-r', type: :boolean, default: false,
92
- desc: 'Recursively runs License Finder on all sub-projects'
93
98
 
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'"
96
99
  def report
97
100
  logger_config[:mode] = Logger::MODE_QUIET
98
101
  aggregate_paths = options[:aggregate_paths]
@@ -132,6 +135,13 @@ module LicenseFinder
132
135
 
133
136
  private
134
137
 
138
+ def aggregate_paths
139
+ aggregate_paths = options[:aggregate_paths]
140
+ aggregate_paths = ProjectFinder.new(license_finder.config.project_path).find_projects if options[:recursive]
141
+ return aggregate_paths unless aggregate_paths.nil? || aggregate_paths.empty?
142
+ [license_finder_config[:project_path]] unless license_finder_config[:project_path].nil?
143
+ end
144
+
135
145
  def save_report(content, file_name)
136
146
  File.open(file_name, 'w') do |f|
137
147
  f.write(content)
@@ -43,6 +43,10 @@ module LicenseFinder
43
43
  decisions.project_name || config.project_path.basename.to_s
44
44
  end
45
45
 
46
+ def project_path
47
+ config.project_path
48
+ end
49
+
46
50
  def decisions
47
51
  @decisions ||= Decisions.fetch_saved(config.decisions_file_path)
48
52
  end
@@ -7,19 +7,42 @@ module LicenseFinder
7
7
 
8
8
  def dependencies
9
9
  aggregate_packages
10
- .group_by { |package| [package.name, package.version] }
11
- .map do |_, packages|
12
- MergedPackage.new(packages[0].dependency, packages.flat_map(&:aggregate_paths))
13
- end
10
+ end
11
+
12
+ def any_packages?
13
+ finders.map(&:any_packages?).reduce(:|)
14
+ end
15
+
16
+ def unapproved
17
+ aggregate_packages.reject(&:approved?)
18
+ end
19
+
20
+ def blacklisted
21
+ aggregate_packages.select(&:blacklisted?)
14
22
  end
15
23
 
16
24
  private
17
25
 
26
+ def finders
27
+ return @finders unless @finders.nil?
28
+ @finders = if @aggregate_paths.nil?
29
+ [LicenseFinder::Core.new(@license_finder_config)]
30
+ else
31
+ @aggregate_paths.map do |path|
32
+ LicenseFinder::Core.new(@license_finder_config.merge(project_path: path))
33
+ end
34
+ end
35
+ end
36
+
18
37
  def aggregate_packages
19
- @aggregate_paths.flat_map do |project_path|
20
- finder = LicenseFinder::Core.new(@license_finder_config.merge(project_path: project_path))
38
+ return @packages unless @packages.nil?
39
+ all_packages = finders.flat_map do |finder|
21
40
  finder.prepare_projects if @license_finder_config[:prepare]
22
- finder.acknowledged.map { |dep| MergedPackage.new(dep, [project_path]) }
41
+ finder.acknowledged.map { |dep| MergedPackage.new(dep, [finder.project_path]) }
42
+ end
43
+ @packages = all_packages.group_by { |package| [package.name, package.version] }
44
+ .map do |_, packages|
45
+ MergedPackage.new(packages[0].dependency, packages.flat_map(&:aggregate_paths))
23
46
  end
24
47
  end
25
48
  end
@@ -42,6 +42,10 @@ module LicenseFinder
42
42
  end
43
43
  end
44
44
 
45
+ if active_pm_classes.empty?
46
+ logger.info 'License Finder', 'No active and installed package managers found for project.', color: :red
47
+ end
48
+
45
49
  active_pm_classes -= active_pm_classes.map(&:takes_priority_over)
46
50
  active_pm_classes.map { |pm_class| pm_class.new(options) }
47
51
  end
@@ -21,6 +21,10 @@ module LicenseFinder
21
21
  'bundle'
22
22
  end
23
23
 
24
+ def self.prepare_command
25
+ 'bundle install'
26
+ end
27
+
24
28
  private
25
29
 
26
30
  attr_reader :ignored_groups
@@ -5,11 +5,20 @@ module LicenseFinder
5
5
  end
6
6
 
7
7
  def current_packages
8
- YAML.load_file(detected_package_path).fetch('imports').map do |package_hash|
8
+ detected_path = detected_package_path
9
+
10
+ YAML.load_file(detected_path).fetch('imports').map do |package_hash|
9
11
  import_path = package_hash.fetch('name')
12
+ license_path =
13
+ if detected_path == possible_package_paths.first
14
+ project_path.join('src', 'vendor', import_path)
15
+ else
16
+ project_path.join('vendor', import_path)
17
+ end
18
+
10
19
  GoPackage.from_dependency({
11
20
  'ImportPath' => import_path,
12
- 'InstallPath' => project_path.join('src', 'vendor', import_path),
21
+ 'InstallPath' => license_path,
13
22
  'Rev' => package_hash.fetch('version')
14
23
  }, nil, true)
15
24
  end
@@ -1,10 +1,11 @@
1
1
  module LicenseFinder
2
- class MergedPackage
2
+ class MergedPackage < Package
3
3
  attr_reader :dependency
4
4
 
5
- def initialize(dependency, aggregate_paths)
6
- @dependency = dependency
5
+ def initialize(package, aggregate_paths)
6
+ @dependency = package
7
7
  @aggregate_paths = aggregate_paths.map { |p| Pathname(p) }
8
+ super(package.name, package.version)
8
9
  end
9
10
 
10
11
  def name
@@ -39,6 +40,22 @@ module LicenseFinder
39
40
  dependency.description
40
41
  end
41
42
 
43
+ def approved_manually?
44
+ dependency.approved_manually?
45
+ end
46
+
47
+ def approved?
48
+ dependency.approved?
49
+ end
50
+
51
+ def whitelisted?
52
+ dependency.whitelisted?
53
+ end
54
+
55
+ def blacklisted?
56
+ dependency.blacklisted?
57
+ end
58
+
42
59
  def groups
43
60
  dependency.groups
44
61
  end
@@ -56,7 +73,15 @@ module LicenseFinder
56
73
  end
57
74
 
58
75
  def eql?(other)
59
- dependency.eql?(other.dependency)
76
+ if other.instance_of? MergedPackage
77
+ other.dependency.eql?(dependency)
78
+ else
79
+ dependency.eql?(other)
80
+ end
81
+ end
82
+
83
+ def ==(other)
84
+ dependency.eql?(other.dependency) && aggregate_paths.eql?(other.aggregate_paths)
60
85
  end
61
86
 
62
87
  def hash
@@ -1,3 +1,3 @@
1
1
  module LicenseFinder
2
- VERSION = '4.0.1'.freeze
2
+ VERSION = '4.0.2'.freeze
3
3
  end
@@ -42,8 +42,9 @@ Gem::Specification.new do |s|
42
42
  s.add_dependency 'httparty'
43
43
  s.add_dependency 'rubyzip'
44
44
  s.add_dependency 'thor'
45
- s.add_dependency 'xml-simple'
46
45
  s.add_dependency 'toml', '0.1.2'
46
+ s.add_dependency 'xml-simple'
47
+
47
48
  # to preserve ruby 1.9.3 support
48
49
  s.add_dependency 'with_env', (RUBY_VERSION <= '1.9.3' ? '1.0.0' : '> 1.0')
49
50
 
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: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Maine
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
- date: 2017-11-14 00:00:00.000000000 Z
23
+ date: 2017-11-16 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
@@ -79,33 +79,33 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: xml-simple
82
+ name: toml
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ">="
85
+ - - '='
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: 0.1.2
88
88
  type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">="
92
+ - - '='
93
93
  - !ruby/object:Gem::Version
94
- version: '0'
94
+ version: 0.1.2
95
95
  - !ruby/object:Gem::Dependency
96
- name: toml
96
+ name: xml-simple
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: 0.1.2
101
+ version: '0'
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: 0.1.2
108
+ version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: with_env
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -366,6 +366,8 @@ files:
366
366
  - features/fixtures/gopath_dep/src/foo-dep/vendor/a/b/LICENSE
367
367
  - features/fixtures/gopath_glide/src/glide.lock
368
368
  - features/fixtures/gopath_glide/src/glide.yaml
369
+ - features/fixtures/gopath_glide_without_src/glide.lock
370
+ - features/fixtures/gopath_glide_without_src/glide.yaml
369
371
  - features/fixtures/gopath_govendor/src/vendor/vendor.json
370
372
  - features/fixtures/gopath_gvt/src/vendor/manifest
371
373
  - features/fixtures/gradle-wrapper/build.gradle