license_finder 0.8.1-java → 0.8.2-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 (50) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.rdoc +15 -1
  3. data/bin/license_finder +1 -61
  4. data/db/migrate/201304181524_add_manual_to_dependencies.rb +7 -0
  5. data/features/ignore_bundle_groups.feature +15 -2
  6. data/features/non_bundler_dependencies.feature +19 -0
  7. data/features/step_definitions/approve_dependencies_steps.rb +1 -1
  8. data/features/step_definitions/cli_steps.rb +1 -1
  9. data/features/step_definitions/html_report_steps.rb +1 -6
  10. data/features/step_definitions/ignore_bundle_groups_steps.rb +18 -2
  11. data/features/step_definitions/non_bundler_steps.rb +33 -0
  12. data/features/step_definitions/set_license_steps.rb +1 -1
  13. data/features/step_definitions/shared_steps.rb +5 -8
  14. data/lib/license_finder.rb +24 -25
  15. data/lib/license_finder/bundle.rb +2 -2
  16. data/lib/license_finder/bundled_gem.rb +3 -3
  17. data/lib/license_finder/{gem_saver.rb → bundled_gem_saver.rb} +3 -5
  18. data/lib/license_finder/bundler_group_manager.rb +22 -0
  19. data/lib/license_finder/cli.rb +137 -31
  20. data/lib/license_finder/configuration.rb +28 -12
  21. data/lib/license_finder/dependency_manager.rb +49 -0
  22. data/lib/license_finder/license.rb +3 -3
  23. data/lib/license_finder/{license_files.rb → possible_license_files.rb} +2 -2
  24. data/lib/license_finder/{dependency_report.rb → reports/dependency_report.rb} +1 -1
  25. data/lib/license_finder/{html_report.rb → reports/html_report.rb} +0 -0
  26. data/lib/license_finder/{reporter.rb → reports/reporter.rb} +0 -0
  27. data/lib/license_finder/{text_report.rb → reports/text_report.rb} +0 -0
  28. data/lib/license_finder/tables.rb +1 -1
  29. data/lib/license_finder/tables/dependency.rb +24 -5
  30. data/lib/license_finder/yml_to_sql.rb +5 -0
  31. data/lib/tasks/license_finder.rake +1 -1
  32. data/license_finder.gemspec +5 -3
  33. data/readme.md +103 -26
  34. data/release.md +7 -2
  35. data/spec/lib/license_finder/bundle_spec.rb +4 -11
  36. data/spec/lib/license_finder/{gem_saver_spec.rb → bundled_gem_saver_spec.rb} +7 -4
  37. data/spec/lib/license_finder/bundled_gem_spec.rb +1 -1
  38. data/spec/lib/license_finder/bundler_group_manager_spec.rb +60 -0
  39. data/spec/lib/license_finder/cli_spec.rb +119 -19
  40. data/spec/lib/license_finder/configuration_spec.rb +31 -8
  41. data/spec/lib/license_finder/dependency_manager_spec.rb +107 -0
  42. data/spec/lib/license_finder/html_report_spec.rb +3 -3
  43. data/spec/lib/license_finder/{license_files_spec.rb → possible_license_files_spec.rb} +7 -7
  44. data/spec/lib/license_finder/tables/dependency_spec.rb +31 -44
  45. data/spec/lib/license_finder/yml_to_sql_spec.rb +24 -2
  46. data/spec/spec_helper.rb +0 -1
  47. data/spec/support/silence_stdout.rb +13 -0
  48. metadata +85 -76
  49. data/lib/license_finder/bundle_syncer.rb +0 -11
  50. data/spec/lib/license_finder/bundle_syncer_spec.rb +0 -16
data/release.md CHANGED
@@ -2,10 +2,15 @@
2
2
 
3
3
  Build the gem for both ruby and jruby (use a later version of each ruby, if desired)
4
4
 
5
+
6
+ The first time you rvm install jruby, you may also have to bundle. This will require you to delete
7
+ any existing Gemfile.lock in the directory.
8
+
9
+
5
10
  ```sh
6
- $ rvm use jruby-1.7.3-d19
11
+ $ rvm use jruby-1.7.4
7
12
  $ rake build
8
- $ rvm use ruby-1.9.3-p392
13
+ $ rvm use ruby-2.0.0
9
14
  $ rake build
10
15
  ```
11
16
 
@@ -26,20 +26,15 @@ module LicenseFinder
26
26
  end
27
27
  end
28
28
 
29
- describe '.current_gem_dependencies' do
29
+ describe '.current_gems' do
30
30
  subject do
31
- Bundle.current_gem_dependencies(definition)
31
+ Bundle.current_gems(definition)
32
32
  end
33
33
 
34
34
  it "should have 2 dependencies" do
35
35
  subject.size.should == 2
36
36
  end
37
37
 
38
- it "returns persisted dependencies" do
39
- subject.first.id.should be
40
- subject.last.id.should be
41
- end
42
-
43
38
  context "when initialized with a parent and child gem" do
44
39
  before do
45
40
  definition.stub(:specs_for).and_return([
@@ -49,11 +44,9 @@ module LicenseFinder
49
44
  end
50
45
 
51
46
  it "should update the child dependency with its parent data" do
52
- gem1 = subject.first.reload
53
- gem2 = subject.last.reload
47
+ gem1 = subject.first
54
48
 
55
- gem2.parents.should == [gem1]
56
- gem1.children.should == [gem2]
49
+ gem1.children.should == ["gem2"]
57
50
  end
58
51
  end
59
52
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
- describe GemSaver do
4
+ describe BundledGemSaver do
5
5
  let(:gemspec) do
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'spec_name'
@@ -30,6 +30,7 @@ module LicenseFinder
30
30
 
31
31
  it "associates children" do
32
32
  subject.children.map(&:name).should == ['foo']
33
+ subject.children.each { |child| child.approval.should be }
33
34
  end
34
35
 
35
36
  it "marks depenency as unapproved by default" do
@@ -37,7 +38,7 @@ module LicenseFinder
37
38
  end
38
39
 
39
40
  context "with a bundler dependency" do
40
- let(:bundled_gem) { BundledGem.new(gemspec, stub(:bundler_dependency, groups: %w[1 2 3]))}
41
+ let(:bundled_gem) { BundledGem.new(gemspec, double(:bundler_dependency, groups: %w[1 2 3]))}
41
42
 
42
43
  it "saves the bundler groups" do
43
44
  subject.bundler_groups.map(&:name).should =~ %w[1 2 3]
@@ -47,13 +48,15 @@ module LicenseFinder
47
48
 
48
49
  context "when the dependency already existed" do
49
50
  let!(:old_copy) do
50
- Dependency.create(
51
+ dep = Dependency.create(
51
52
  name: 'spec_name',
52
53
  version: '0.1.2',
53
54
  summary: 'old summary',
54
55
  description: 'old desription',
55
56
  homepage: 'old homepage'
56
57
  )
58
+ dep.approval = Approval.create
59
+ dep
57
60
  end
58
61
 
59
62
  it "merges in the latest data" do
@@ -85,7 +88,7 @@ module LicenseFinder
85
88
  end
86
89
 
87
90
  context "with a bundler dependency" do
88
- let(:bundled_gem) { BundledGem.new(gemspec, stub(:bundler_dependency, groups: %w[1 2 3]))}
91
+ let(:bundled_gem) { BundledGem.new(gemspec, double(:bundler_dependency, groups: %w[1 2 3]))}
89
92
 
90
93
  before do
91
94
  old_copy.add_bundler_group BundlerGroup.find_or_create(name: 'a')
@@ -54,7 +54,7 @@ module LicenseFinder
54
54
 
55
55
  describe "#license_files" do
56
56
  it "delegates to the license files helper" do
57
- LicenseFiles.should_receive(:new).with(gemspec.full_gem_path) { stub(files: [] )}
57
+ PossibleLicenseFiles.should_receive(:new).with(gemspec.full_gem_path) { double(find: [] )}
58
58
  subject.license_files
59
59
  end
60
60
  end
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe BundlerGroupManager do
5
+ let(:config) { Configuration.new }
6
+
7
+ before do
8
+ LicenseFinder.stub(:config).and_return config
9
+ config.ignore_groups = ignore_groups
10
+ end
11
+
12
+ describe ".add_ignored_group" do
13
+ describe "when the group is already ignored" do
14
+ let(:ignore_groups) { ["test", "other_group"] }
15
+
16
+ it "does not create a duplicate entry" do
17
+ config.should_not_receive(:save_to_yaml)
18
+
19
+ described_class.add_ignored_group("test")
20
+ end
21
+ end
22
+
23
+ describe "when the group is not ignored" do
24
+ let(:ignore_groups) { [] }
25
+
26
+ it "adds the group to the ignored bundler groups" do
27
+ config.should_receive(:save_to_yaml)
28
+
29
+ described_class.add_ignored_group("test")
30
+
31
+ config.ignore_groups.should include(:test)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe ".remove_ignored_group" do
37
+ describe "when the group is not ignored" do
38
+ let(:ignore_groups) { [] }
39
+
40
+ it "does not call save_to_yaml on config" do
41
+ config.should_not_receive(:save_to_yaml)
42
+
43
+ described_class.remove_ignored_group("test")
44
+ end
45
+ end
46
+
47
+ describe "when the group is already ignored" do
48
+ let(:ignore_groups) { ["test", "other_group"] }
49
+
50
+ it "removes the group from the ignored bundler group list" do
51
+ config.should_receive(:save_to_yaml)
52
+
53
+ described_class.remove_ignored_group("test")
54
+
55
+ config.ignore_groups.should_not include(:test)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,36 +1,136 @@
1
1
  require "spec_helper"
2
2
 
3
3
  module LicenseFinder
4
- describe CLI do
5
- describe "#execute!(options)" do
6
- before { CLI.stub(:check_for_action_items) }
4
+ module CLI
5
+ describe Dependencies do
6
+ describe "add" do
7
+ it "adds a dependency" do
8
+ DependencyManager.should_receive(:create_non_bundler).with("MIT", "js_dep", "1.2.3")
7
9
 
8
- context "when the approve option is provided" do
9
- it "should approve the requested gem" do
10
- dependency = double('dependency', :name => nil)
11
- dependency.should_receive(:approve!)
10
+ silence_stdout do
11
+ subject.add("MIT", "js_dep", "1.2.3")
12
+ end
13
+ end
12
14
 
13
- Dependency.stub(:first).with(name: 'foo').and_return(dependency)
15
+ it "does not require a version" do
16
+ DependencyManager.should_receive(:create_non_bundler).with("MIT", "js_dep", nil)
14
17
 
15
- CLI.execute! approve: true, dependency: 'foo'
18
+ silence_stdout do
19
+ subject.add("MIT", "js_dep")
20
+ end
21
+ end
22
+
23
+ it "has an -a option to approve the added dependency" do
24
+ DependencyManager.should_receive(:create_non_bundler).with("MIT", "js_dep", "1.2.3")
25
+ DependencyManager.should_receive(:approve!).with("js_dep")
26
+
27
+ silence_stdout do
28
+ LicenseFinder::CLI::Main.start(["dependencies", "add", "--approve", "MIT", "js_dep", "1.2.3"])
29
+ end
16
30
  end
17
31
  end
18
32
 
19
- context "when the -l (--license) switch is provided" do
20
- it "should update the license on the requested gem" do
21
- dependency = double :dependency, :name => nil
22
- dependency.should_receive(:set_license_manually).with("foo")
33
+ describe "remove" do
34
+ it "removes a dependency" do
35
+ DependencyManager.should_receive(:destroy_non_bundler).with("js_dep")
36
+ silence_stdout do
37
+ subject.remove("js_dep")
38
+ end
39
+ end
40
+ end
41
+ end
23
42
 
24
- Dependency.stub(:first).with(name: "foo_gem").and_return dependency
43
+ describe IgnoredBundlerGroups do
44
+ describe "list" do
45
+ it "shows the ignored groups in the standard output" do
46
+ LicenseFinder.config.should_receive(:ignore_groups).and_return([])
25
47
 
26
- CLI.execute! license: "foo", dependency: 'foo_gem'
48
+ silence_stdout do
49
+ subject.list
50
+ end
27
51
  end
28
52
  end
29
53
 
30
- context "when no options are provided" do
31
- it "should check for action items" do
32
- CLI.should_receive(:check_for_action_items)
33
- CLI.execute!
54
+ describe "add" do
55
+ it "adds the specified group to the ignored groups list" do
56
+ BundlerGroupManager.should_receive(:add_ignored_group).with("test")
57
+
58
+ silence_stdout do
59
+ subject.add("test")
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "remove" do
65
+ it "removes the specified group from the ignored groups list" do
66
+ BundlerGroupManager.should_receive(:remove_ignored_group).with("test")
67
+
68
+ silence_stdout do
69
+ subject.remove("test")
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ describe Main do
76
+ describe "default" do
77
+ it "checks for action items" do
78
+ DependencyManager.should_receive(:sync_with_bundler)
79
+ Dependency.stub(:unapproved) { [] }
80
+ silence_stdout do
81
+ described_class.start([])
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "#rescan" do
87
+ it "resyncs with Gemfile" do
88
+ DependencyManager.should_receive(:sync_with_bundler)
89
+ Dependency.stub(:unapproved) { [] }
90
+
91
+ silence_stdout do
92
+ subject.rescan
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#license" do
98
+ it "updates the license on the requested gem" do
99
+ DependencyManager.should_receive(:license!).with("foo_gem", "foo")
100
+
101
+ silence_stdout do
102
+ subject.license 'foo', 'foo_gem'
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "#approve" do
108
+ it "approves the requested gem" do
109
+ DependencyManager.should_receive(:approve!).with("foo")
110
+
111
+ silence_stdout do
112
+ subject.approve 'foo'
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "#action_items" do
118
+ it "reports unapproved dependencies" do
119
+ Dependency.stub(:unapproved) { ['one dependency'] }
120
+ TextReport.stub(:new) { double(:report, to_s: "a report!") }
121
+ silence_stdout do
122
+ $stdout.stub(:puts)
123
+ $stdout.should_receive(:puts).with(/dependencies/i)
124
+ expect { subject.action_items }.to raise_error(SystemExit)
125
+ end
126
+ end
127
+
128
+ it "reports that all dependencies are approved" do
129
+ Dependency.stub(:unapproved) { [] }
130
+ silence_stdout do
131
+ $stdout.should_receive(:puts).with(/approved/i)
132
+ expect { subject.action_items }.to_not raise_error
133
+ end
34
134
  end
35
135
  end
36
136
  end
@@ -24,9 +24,12 @@ module LicenseFinder
24
24
  subject.dependencies_dir.should == attributes['dependencies_file_dir']
25
25
  end
26
26
  end
27
+ end
27
28
 
28
- it "uses absolute path in database_path" do
29
- subject.database_path.should_not start_with(".")
29
+ describe "#database_uri" do
30
+ it "should URI escape absolute path the dependencies_file_dir" do
31
+ config = described_class.new('dependencies_file_dir' => 'test path')
32
+ config.database_uri.should =~ /test%20path\/dependencies\.db$/
30
33
  end
31
34
  end
32
35
 
@@ -56,14 +59,34 @@ module LicenseFinder
56
59
  end
57
60
  end
58
61
 
59
- describe "#ignore_groups" do
60
- it "should default to an empty array" do
61
- config.ignore_groups.should == []
62
+ describe "#save_to_yaml" do
63
+ let(:tmp_yml) { '.tmp.configuration_spec.yml' }
64
+
65
+ before do
66
+ Configuration.stub(:config_file_path).and_return(tmp_yml)
67
+ config.whitelist = ['my_gem']
68
+ config.ignore_groups = ['other_group', 'test']
62
69
  end
63
70
 
64
- it "should always return symbolized versions of the ignore groups" do
65
- config.ignore_groups = %w[test development]
66
- config.ignore_groups.should == [:test, :development]
71
+ after do
72
+ File.delete(tmp_yml)
73
+ end
74
+
75
+ it "writes the whitelist to the yaml file" do
76
+ config.save_to_yaml
77
+
78
+ yaml = YAML.load(File.read(tmp_yml))
79
+
80
+ yaml["whitelist"].should include("my_gem")
81
+ end
82
+
83
+ it "writes the ignored bundler groups to the yaml file" do
84
+ config.save_to_yaml
85
+
86
+ yaml = YAML.load(File.read(tmp_yml))
87
+
88
+ yaml["ignore_groups"].should include("other_group")
89
+ yaml["ignore_groups"].should include("test")
67
90
  end
68
91
  end
69
92
  end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe DependencyManager do
5
+ let(:config) { Configuration.new }
6
+
7
+ before do
8
+ LicenseFinder.stub(:config).and_return config
9
+ config.whitelist = ["MIT", "other"]
10
+ Reporter.stub(:write_reports)
11
+ end
12
+
13
+ describe "#sync_with_bundler" do
14
+ it "destroys every dependency except for the ones Bundler reports as 'current' or are marked as 'manual'" do
15
+ cur1 = Dependency.create(name: "current dependency 1")
16
+ cur2 = Dependency.create(name: "current dependency 2")
17
+ man1 = Dependency.create(name: "manual dependency", manual: true)
18
+ Dependency.create(name: "old dependency 1")
19
+ Dependency.create(name: "old dependency 2")
20
+
21
+ current_gems = [
22
+ double(:gem1, save_as_dependency: cur1),
23
+ double(:gem2, save_as_dependency: cur2)
24
+ ]
25
+ Bundle.stub(:current_gems) { current_gems }
26
+
27
+ described_class.sync_with_bundler
28
+ Dependency.all.map(&:name).should =~ [cur1, cur2, man1].map(&:name)
29
+ end
30
+ end
31
+
32
+ describe ".create_non_bundler" do
33
+ it "should add a Dependency" do
34
+ expect do
35
+ described_class.create_non_bundler("MIT", "js_dep", "0.0.0")
36
+ end.to change(Dependency, :count).by(1)
37
+ end
38
+
39
+ it "should mark the dependency as manual" do
40
+ described_class.create_non_bundler("MIT", "js_dep", "0.0.0")
41
+ .should be_manual
42
+ end
43
+
44
+ it "should set the appropriate values" do
45
+ dep = described_class.create_non_bundler("GPL", "js_dep", "0.0.0")
46
+ dep.name.should == "js_dep"
47
+ dep.version.should == "0.0.0"
48
+ dep.license.name.should == "GPL"
49
+ dep.should_not be_approved
50
+ end
51
+
52
+ it "should complain if the dependency already exists" do
53
+ Dependency.create(name: "current dependency 1")
54
+ expect { described_class.create_non_bundler("GPL", "current dependency 1", "0.0.0") }
55
+ .to raise_error(LicenseFinder::Error)
56
+ end
57
+ end
58
+
59
+ describe ".destroy_non_bundler" do
60
+ it "should remove a non bundler Dependency" do
61
+ described_class.create_non_bundler("GPL", "a non-bundler dep", nil)
62
+ expect do
63
+ described_class.destroy_non_bundler("a non-bundler dep")
64
+ end.to change(Dependency, :count).by(-1)
65
+ end
66
+
67
+ it "should not remove a bundler Dependency" do
68
+ Dependency.create(name: "a bundler dep")
69
+ expect do
70
+ expect do
71
+ described_class.destroy_non_bundler("a bundler dep")
72
+ end.to raise_error(LicenseFinder::Error)
73
+ end.to_not change(Dependency, :count)
74
+ end
75
+ end
76
+
77
+ describe ".approve!" do
78
+ it "approves the dependency" do
79
+ dep = Dependency.named("current dependency")
80
+ dep.reload.should_not be_approved
81
+ described_class.approve!("current dependency")
82
+ dep.reload.should be_approved
83
+ end
84
+
85
+ it "should raise an error if it can't find the dependency" do
86
+ expect { described_class.approve!("non-existent dependency") }
87
+ .to raise_error(LicenseFinder::Error)
88
+ end
89
+ end
90
+
91
+ describe ".license!" do
92
+ it "adds a license for the dependency" do
93
+ dep = described_class.create_non_bundler("old license", "current dependency", nil)
94
+ dep.reload.license.name.should == "old license"
95
+ described_class.license!("current dependency", "a license")
96
+ dep.reload.license.name.should == "a license"
97
+ end
98
+
99
+ it "should raise an error if it can't find the dependency" do
100
+ expect { described_class.license!("non-existent dependency", "a license") }
101
+ .to raise_error(LicenseFinder::Error)
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+