license_finder 0.8.2-java → 0.9.0-java

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.
Files changed (33) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/features/cli.feature +11 -1
  3. data/features/html_report.feature +1 -1
  4. data/features/ignore_bundle_groups.feature +8 -8
  5. data/features/step_definitions/approve_dependencies_steps.rb +1 -1
  6. data/features/step_definitions/cli_steps.rb +17 -1
  7. data/features/step_definitions/html_report_steps.rb +1 -1
  8. data/features/step_definitions/ignore_bundle_groups_steps.rb +6 -6
  9. data/features/step_definitions/non_bundler_steps.rb +4 -4
  10. data/features/step_definitions/rails_rake_steps.rb +1 -1
  11. data/features/step_definitions/set_license_steps.rb +2 -2
  12. data/features/step_definitions/shared_steps.rb +4 -4
  13. data/features/step_definitions/whitelist_steps.rb +33 -2
  14. data/features/whitelist.feature +19 -1
  15. data/lib/license_finder.rb +4 -1
  16. data/lib/license_finder/bundle.rb +3 -1
  17. data/lib/license_finder/bundled_gem.rb +1 -1
  18. data/lib/license_finder/bundled_gem_saver.rb +35 -12
  19. data/lib/license_finder/cli.rb +50 -8
  20. data/lib/license_finder/configuration.rb +6 -4
  21. data/lib/license_finder/dependency_manager.rb +1 -2
  22. data/lib/license_finder/license/new_bsd.rb +19 -0
  23. data/license_finder.gemspec +3 -2
  24. data/readme.md +24 -1
  25. data/spec/lib/license_finder/bundled_gem_saver_spec.rb +131 -84
  26. data/spec/lib/license_finder/cli_spec.rb +44 -4
  27. data/spec/lib/license_finder/configuration_spec.rb +15 -3
  28. data/spec/lib/license_finder/dependency_manager_spec.rb +1 -1
  29. data/spec/lib/license_finder/license/new_bsd_spec.rb +28 -0
  30. data/spec/lib/license_finder_spec.rb +1 -1
  31. metadata +67 -52
  32. data/lib/license_finder/bundler_group_manager.rb +0 -22
  33. data/spec/lib/license_finder/bundler_group_manager_spec.rb +0 -60
@@ -1,3 +1,5 @@
1
+ require "rake"
2
+
1
3
  module LicenseFinder
2
4
  class Configuration
3
5
  attr_accessor :whitelist, :ignore_groups, :dependencies_dir
@@ -41,7 +43,7 @@ module LicenseFinder
41
43
  config = self.class.config_hash(config)
42
44
 
43
45
  @whitelist = config['whitelist'] || []
44
- @ignore_groups = (config["ignore_groups"] || []).map(&:to_sym)
46
+ @ignore_groups = (config["ignore_groups"] || [])
45
47
  @dependencies_dir = config['dependencies_file_dir'] || './doc/'
46
48
  FileUtils.mkdir_p(@dependencies_dir)
47
49
  end
@@ -67,11 +69,11 @@ module LicenseFinder
67
69
  whitelisted_licenses.include? license
68
70
  end
69
71
 
70
- def save_to_yaml
72
+ def save
71
73
  File.open(Configuration.config_file_path, 'w') do |file|
72
74
  file.write({
73
- 'whitelist' => @whitelist,
74
- 'ignore_groups' => @ignore_groups
75
+ 'whitelist' => @whitelist.uniq,
76
+ 'ignore_groups' => @ignore_groups.uniq
75
77
  }.to_yaml)
76
78
  end
77
79
  end
@@ -1,9 +1,8 @@
1
1
  module LicenseFinder
2
2
  module DependencyManager
3
3
  def self.sync_with_bundler
4
- current_gems = Bundle.current_gems
5
4
  modifying {
6
- current_dependencies = current_gems.map(&:save_as_dependency)
5
+ current_dependencies = LicenseFinder.current_gems.map(&:save_as_dependency)
7
6
  Dependency.bundler.obsolete(current_dependencies).each(&:destroy)
8
7
  }
9
8
  end
@@ -5,4 +5,23 @@ class LicenseFinder::License::NewBSD < LicenseFinder::License::Base
5
5
  def self.pretty_name
6
6
  'New BSD'
7
7
  end
8
+
9
+ def matches?
10
+ super || matches_alternate?
11
+ end
12
+
13
+ def matches_alternate?
14
+ !!(text =~ alternate_license_regex)
15
+ end
16
+
17
+ def alternate_license_regex
18
+ /#{Regexp.escape(alternate_license_text).gsub(/<[^<>]+>/, '(.*)')}/
19
+ end
20
+
21
+ def alternate_license_text
22
+ self.class.license_text.gsub(
23
+ "Neither the name of <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.",
24
+ "The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission."
25
+ )
26
+ end
8
27
  end
@@ -2,7 +2,7 @@ require './lib/license_finder/platform'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "license_finder"
5
- s.version = "0.8.2"
5
+ s.version = "0.9.0"
6
6
  s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards", "Paul Meskers", "Brent Wheeldon", "David Tengdin", "William Ramsey"]
7
7
  s.email = ["licensefinder@pivotalabs.com"]
8
8
  s.homepage = "https://github.com/pivotal/LicenseFinder"
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "bundler"
22
22
  s.add_dependency "sequel"
23
23
  s.add_dependency "thor"
24
+ s.add_dependency "rake"
24
25
  s.add_dependency LicenseFinder::Platform.sqlite_gem
25
26
 
26
- %w(rspec rake xpath cucumber).each do |gem|
27
+ %w(rspec xpath cucumber).each do |gem|
27
28
  s.add_development_dependency gem
28
29
  end
29
30
 
data/readme.md CHANGED
@@ -23,7 +23,7 @@ License finder will generate reports of action items - i.e., dependencies that d
23
23
  $ license_finder
24
24
  ```
25
25
 
26
- (Note) If you wish to run license_finder without the progress spinner use the -q or --quiet option.
26
+ (Note) If you wish to run license_finder without the progress spinner use the --quiet option.
27
27
 
28
28
  On a brand new Rails project, you could expect `license_finder` to output something like the following
29
29
  (assuming you whitelisted the MIT license -- see [Configuration](#configuration)):
@@ -85,6 +85,29 @@ $ license_finder approve awesome_gpl_gem
85
85
 
86
86
  If you rerun `license_finder`, you should no longer see `awesome_gpl_gem` in the output.
87
87
 
88
+ ### Managing license whitelist
89
+
90
+ Licenses can be added to a whitelist that tells LicenseFinder to automatically approve dependencies using the specified licenses.
91
+ These licenses can be managed with the `whitelist` command.
92
+
93
+ To list licenses currently on the whitelist:
94
+
95
+ ```sh
96
+ $ license_finder whitelist list
97
+ ```
98
+
99
+ To add a license to the whitelist:
100
+
101
+ ```sh
102
+ $ license_finder whitelist add MIT
103
+ ```
104
+
105
+ To remove a license from the whitelist:
106
+
107
+ ```sh
108
+ $ license_finder whitelist remove MIT
109
+ ```
110
+
88
111
  ### Managing ignored Bundler groups
89
112
 
90
113
  Bundler groups can be added to an ignore list which will prevent LicenseFinder from evaluating their licenses.
@@ -16,7 +16,7 @@ module LicenseFinder
16
16
 
17
17
  describe "#save" do
18
18
  let(:bundled_gem) { BundledGem.new(gemspec) }
19
- subject { described_class.find_or_initialize_by_name('spec_name', bundled_gem).save }
19
+ subject { described_class.find_or_create_by_name('spec_name', bundled_gem).save }
20
20
 
21
21
  context "when the dependency is new" do
22
22
  it "persists gem data" do
@@ -28,9 +28,22 @@ module LicenseFinder
28
28
  subject.homepage.should == "homepage"
29
29
  end
30
30
 
31
- it "associates children" do
32
- subject.children.map(&:name).should == ['foo']
33
- subject.children.each { |child| child.approval.should be }
31
+ describe "associating children" do
32
+ context "when the child is in Bundler's current gems" do
33
+ before { LicenseFinder.stub(:current_gems).and_return([double(:gemspec, name: "foo 0.0")]) }
34
+
35
+ it "associates children" do
36
+ subject.children.map(&:name).should == ['foo']
37
+ subject.children.each { |child| child.id.should_not be_nil }
38
+ end
39
+ end
40
+
41
+ context "when the child is not in Bundler's current gems" do
42
+ it "does not associates children" do
43
+ subject.children.map(&:name).should == []
44
+ subject.children.each { |child| child.id.should be_nil }
45
+ end
46
+ end
34
47
  end
35
48
 
36
49
  it "marks depenency as unapproved by default" do
@@ -47,109 +60,143 @@ module LicenseFinder
47
60
  end
48
61
 
49
62
  context "when the dependency already existed" do
50
- let!(:old_copy) do
51
- dep = Dependency.create(
52
- name: 'spec_name',
53
- version: '0.1.2',
54
- summary: 'old summary',
55
- description: 'old desription',
56
- homepage: 'old homepage'
57
- )
58
- dep.approval = Approval.create
59
- dep
60
- end
61
-
62
- it "merges in the latest data" do
63
- subject.id.should == old_copy.id
64
- subject.name.should == old_copy.name
65
- subject.version.should == "2.1.3"
66
- subject.summary.should == "summary"
67
- subject.description.should == "description"
68
- subject.homepage.should == "homepage"
69
- end
70
-
71
- it "keeps a manually assigned license" do
72
- old_copy.license = LicenseAlias.create(name: 'foo', manual: true)
73
- old_copy.save
74
- subject.license.name.should == 'foo'
75
- end
76
-
77
- it "keeps approval" do
78
- old_copy.approval = Approval.create(state: true)
79
- old_copy.save
80
- subject.approval.state.should == true
81
- end
63
+ before { LicenseFinder.stub(:current_gems).and_return([double(:gemspec, name: "foo 0.0")]) }
64
+
65
+ context "the values have not changed" do
66
+ let!(:original_dependency) do
67
+ license = LicenseAlias.create(
68
+ name: 'other'
69
+ )
70
+ Dependency.create(
71
+ name: 'spec_name',
72
+ version: '2.1.3',
73
+ summary: 'summary',
74
+ description: 'description',
75
+ homepage: 'homepage',
76
+ license: license
77
+ )
78
+ end
79
+ let(:bundled_gem_saver) { described_class.find_or_create_by_name('spec_name', bundled_gem) }
82
80
 
83
- it "ensures correct children are associated" do
84
- old_copy.add_child Dependency.new(name: 'bob')
85
- old_copy.add_child Dependency.new(name: 'joe')
86
- old_copy.children.each(&:save)
87
- subject.children.map(&:name).should =~ ['foo']
81
+ it "does not save the dependency" do
82
+ bundled_gem_saver.dependency.should_not_receive(:save)
83
+ bundled_gem_saver.save
84
+ end
88
85
  end
89
86
 
90
- context "with a bundler dependency" do
91
- let(:bundled_gem) { BundledGem.new(gemspec, double(:bundler_dependency, groups: %w[1 2 3]))}
87
+ context "the values have changed" do
88
+ let!(:old_copy) do
89
+ dep = Dependency.create(
90
+ name: 'spec_name',
91
+ version: '0.1.2',
92
+ summary: 'old summary',
93
+ description: 'old desription',
94
+ homepage: 'old homepage'
95
+ )
96
+ dep.approval = Approval.create
97
+ dep
98
+ end
92
99
 
93
- before do
94
- old_copy.add_bundler_group BundlerGroup.find_or_create(name: 'a')
95
- old_copy.add_bundler_group BundlerGroup.find_or_create(name: 'b')
100
+ it "merges in the latest data" do
101
+ subject.id.should == old_copy.id
102
+ subject.name.should == old_copy.name
103
+ subject.version.should == "2.1.3"
104
+ subject.summary.should == "summary"
105
+ subject.description.should == "description"
106
+ subject.homepage.should == "homepage"
96
107
  end
97
108
 
98
- it "ensures the correct bundler groups are associated" do
99
- subject.bundler_groups.map(&:name).should =~ %w[1 2 3]
109
+ it "keeps a manually assigned license" do
110
+ old_copy.license = LicenseAlias.create(name: 'foo', manual: true)
111
+ old_copy.save
112
+ subject.license.name.should == 'foo'
100
113
  end
101
- end
102
114
 
103
- context "license changes to something other than 'other'" do
104
- before do
105
- old_copy.license = LicenseAlias.create(name: 'other')
115
+ it "keeps approval" do
116
+ old_copy.approval = Approval.create(state: true)
106
117
  old_copy.save
107
- gemspec.license = "new license"
118
+ subject.approval.state.should == true
108
119
  end
109
120
 
110
- context "new license is whitelisted" do
111
- before { LicenseFinder.config.stub(:whitelist).and_return [gemspec.license] }
121
+ it "ensures correct children are associated" do
122
+ old_copy.add_child Dependency.new(name: 'bob')
123
+ old_copy.add_child Dependency.new(name: 'joe')
124
+ old_copy.children.each(&:save)
125
+ subject.children.map(&:name).should =~ ['foo']
126
+ end
112
127
 
113
- it "should set the approval to true" do
114
- subject.should be_approved
128
+ context "with a bundler dependency" do
129
+ let(:bundled_gem) { BundledGem.new(gemspec, double(:bundler_dependency, groups: %w[1 2 3]))}
130
+
131
+ before do
132
+ old_copy.add_bundler_group BundlerGroup.find_or_create(name: 'a')
133
+ old_copy.add_bundler_group BundlerGroup.find_or_create(name: 'b')
115
134
  end
116
- end
117
135
 
118
- context "new license is not whitelisted" do
119
- it "should set the approval to false" do
120
- subject.should_not be_approved
136
+ it "ensures the correct bundler groups are associated" do
137
+ subject.bundler_groups.map(&:name).should =~ %w[1 2 3]
121
138
  end
122
139
  end
123
- end
124
140
 
125
- context "license changes to unknown (i.e., 'other')" do
126
- before do
127
- old_copy.license = LicenseAlias.create(name: 'MIT')
128
- old_copy.approval = Approval.create(state: false)
129
- old_copy.save
130
- gemspec.license = "other"
131
- end
141
+ context "license changes to something other than 'other'" do
142
+ before do
143
+ old_copy.license = LicenseAlias.create(name: 'other')
144
+ old_copy.save
145
+ gemspec.license = "new license"
146
+ end
132
147
 
133
- it "should not change the license" do
134
- subject.license.name.should == 'MIT'
135
- end
148
+ context "new license is whitelisted" do
149
+ before { LicenseFinder.config.stub(:whitelist).and_return [gemspec.license] }
150
+
151
+ it "should set the approval to true" do
152
+ subject.should be_approved
153
+ end
154
+ end
136
155
 
137
- it "should not change the approval" do
138
- subject.should_not be_approved
156
+ context "new license is not whitelisted" do
157
+ it "should set the approval to false" do
158
+ subject.should_not be_approved
159
+ end
160
+ end
139
161
  end
140
- end
141
162
 
142
- context "license does not change" do
143
- before do
144
- old_copy.license = LicenseAlias.create(name: 'MIT')
145
- old_copy.approval = Approval.create(state: false)
146
- old_copy.save
147
- gemspec.license = "MIT"
163
+ context "license changes to unknown (i.e., 'other')" do
164
+ before do
165
+ old_copy.license = LicenseAlias.create(name: 'MIT')
166
+ old_copy.approval = Approval.create(state: false)
167
+ old_copy.save
168
+ gemspec.license = "other"
169
+ end
170
+
171
+ it "should not change the license" do
172
+ subject.license.name.should == 'MIT'
173
+ end
174
+
175
+ it "should not change the approval" do
176
+ subject.should_not be_approved
177
+ end
148
178
  end
149
179
 
150
- it "should not change the license or approval" do
151
- subject.should_not be_approved
152
- subject.license.name.should == "MIT"
180
+ context "license does not change" do
181
+ let(:bundled_gem_saver) { described_class.find_or_create_by_name('spec_name', bundled_gem) }
182
+
183
+ before do
184
+ old_copy.license = LicenseAlias.create(name: 'MIT')
185
+ old_copy.approval = Approval.create(state: false)
186
+ old_copy.save
187
+ gemspec.license = "MIT"
188
+ end
189
+
190
+ it "should not change the license or approval" do
191
+ dependency = bundled_gem_saver.save
192
+ dependency.should_not be_approved
193
+ dependency.license.name.should == "MIT"
194
+ end
195
+
196
+ it "should not save the license" do
197
+ bundled_gem_saver.dependency.license.should_not_receive(:save)
198
+ bundled_gem_saver.save
199
+ end
153
200
  end
154
201
  end
155
202
  end
@@ -20,7 +20,7 @@ module LicenseFinder
20
20
  end
21
21
  end
22
22
 
23
- it "has an -a option to approve the added dependency" do
23
+ it "has an --approve option to approve the added dependency" do
24
24
  DependencyManager.should_receive(:create_non_bundler).with("MIT", "js_dep", "1.2.3")
25
25
  DependencyManager.should_receive(:approve!).with("js_dep")
26
26
 
@@ -40,10 +40,48 @@ module LicenseFinder
40
40
  end
41
41
  end
42
42
 
43
+ describe Whitelist do
44
+ let(:config) { LicenseFinder.config }
45
+
46
+ describe "list" do
47
+ it "shows the whitelist of licenses" do
48
+ config.should_receive(:whitelist).and_return([])
49
+
50
+ silence_stdout do
51
+ subject.list
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "add" do
57
+ it "adds the specified license to the whitelist" do
58
+ config.whitelist.should_receive(:push).with("test")
59
+ config.should_receive(:save)
60
+
61
+ silence_stdout do
62
+ subject.add("test")
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "remove" do
68
+ it "removes the specified license from the whitelist" do
69
+ config.should_receive(:save)
70
+ config.whitelist.should_receive(:delete).with("test")
71
+
72
+ silence_stdout do
73
+ subject.remove("test")
74
+ end
75
+ end
76
+ end
77
+ end
78
+
43
79
  describe IgnoredBundlerGroups do
80
+ let(:config) { LicenseFinder.config }
81
+
44
82
  describe "list" do
45
83
  it "shows the ignored groups in the standard output" do
46
- LicenseFinder.config.should_receive(:ignore_groups).and_return([])
84
+ config.should_receive(:ignore_groups).and_return([])
47
85
 
48
86
  silence_stdout do
49
87
  subject.list
@@ -53,7 +91,8 @@ module LicenseFinder
53
91
 
54
92
  describe "add" do
55
93
  it "adds the specified group to the ignored groups list" do
56
- BundlerGroupManager.should_receive(:add_ignored_group).with("test")
94
+ config.ignore_groups.should_receive(:push).with("test")
95
+ config.should_receive(:save)
57
96
 
58
97
  silence_stdout do
59
98
  subject.add("test")
@@ -63,7 +102,8 @@ module LicenseFinder
63
102
 
64
103
  describe "remove" do
65
104
  it "removes the specified group from the ignored groups list" do
66
- BundlerGroupManager.should_receive(:remove_ignored_group).with("test")
105
+ config.ignore_groups.should_receive(:delete).with("test")
106
+ config.should_receive(:save)
67
107
 
68
108
  silence_stdout do
69
109
  subject.remove("test")