license_finder 0.8.2-java → 0.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
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,10 @@
1
+ === TBD
2
+
3
+ * Features
4
+
5
+ * Can maintain whitelisted licenses from command line
6
+ * Improve New BSD license detection
7
+
1
8
  === 0.8.2 / 2012-07-09
2
9
 
3
10
  * Features
@@ -16,7 +16,7 @@ Feature: License Finder command line executable
16
16
 
17
17
  Scenario: Auditing an application with whitelisted licenses
18
18
  Given I have an app with license finder that depends on a MIT licensed gem
19
- When I whitelist MIT and 'other' licenses
19
+ When I whitelist MIT and 'other' and New BSD licenses
20
20
  Then it should exit with status code 0
21
21
  And I should see all gems approved for use
22
22
 
@@ -24,3 +24,13 @@ Feature: License Finder command line executable
24
24
  Given I have a project that depends on mime-types with a manual license type
25
25
  When I run license_finder
26
26
  Then the mime-types license remains set with my manual license type
27
+
28
+ Scenario: Viewing help for license_finder subcommand
29
+ Given I have an app with license finder
30
+ When I run license_finder help on a specific command
31
+ Then I should see the correct subcommand usage instructions
32
+
33
+ Scenario: Viewing help for license_finder default
34
+ Given I have an app with license finder
35
+ When I run license_finder help
36
+ Then I should the correct default usage instructions
@@ -19,5 +19,5 @@ Feature: HTML Report
19
19
 
20
20
  Scenario: Dependency summary
21
21
  And my app depends on MIT and GPL licensed gems
22
- When I whitelist MIT and 'other' licenses
22
+ When I whitelist MIT and 'other' and New BSD licenses
23
23
  Then I should see only see GPL liceneses as unapproved in the html
@@ -3,21 +3,21 @@ Feature: Ignore Bundle Groups
3
3
  I want to ignore certain bundler groups
4
4
  So that any gems I use in development, or for testing, are automatically approved for use
5
5
 
6
+ Scenario: Bundler groups can be added to the ignore list
7
+ Given I have an app with license finder
8
+ And I add the test group to the ignored bundler groups
9
+ When I get the ignored groups
10
+ Then I should see the test group in the output
11
+
6
12
  Scenario: Ignored bundler groups are not evaluated for licenses
7
13
  Given I have an app with license finder that depends on a GPL licensed gem in the test bundler group
8
14
  And I add the test group to the ignored bundler groups
9
15
  When I run license_finder
10
16
  Then I should not see the GPL licensed gem in the output
11
17
 
12
- Scenario: Bundler groups can be added to the ignore list from command line
13
- Given I have an app with license finder
14
- And I add the test group to the ignored bundler groups
15
- When I get the ignored groups from the command line
16
- Then I should see the test group in the output
17
-
18
- Scenario: Bundler groups can be removed from the ignore list from command line
18
+ Scenario: Bundler groups can be removed from the ignore list
19
19
  Given I have an app with license finder
20
20
  And I add the test group to the ignored bundler groups
21
21
  And I remove the test group from the ignored bundler groups
22
- When I get the ignored groups from the command line
22
+ When I get the ignored groups
23
23
  Then I should not see the test group in the output
@@ -8,7 +8,7 @@ When(/^I approve that gem$/) do
8
8
  @output = @user.execute_command "license_finder"
9
9
  @output.should include "gpl_gem"
10
10
  @output = @user.execute_command "license_finder approve gpl_gem"
11
- @output = @user.execute_command "license_finder -q"
11
+ @output = @user.execute_command "license_finder --quiet"
12
12
  end
13
13
 
14
14
  Then(/^I should not see that gem in the console output$/) do
@@ -17,11 +17,19 @@ Given(/^I have a project that depends on mime\-types with a manual license type$
17
17
  @user.create_rails_app
18
18
  @user.add_gem_dependency('mime-types')
19
19
  @user.bundle_app
20
- @user.execute_command "license_finder -q"
20
+ @user.execute_command "license_finder --quiet"
21
21
  @output = @user.execute_command "license_finder license Ruby mime-types"
22
22
  @output.should =~ /mime-types.*Ruby/
23
23
  end
24
24
 
25
+ When(/^I run license_finder help on a specific command$/) do
26
+ @output = @user.execute_command "license_finder dependencies help add"
27
+ end
28
+
29
+ When(/^I run license_finder help$/) do
30
+ @output = @user.execute_command "license_finder help"
31
+ end
32
+
25
33
  Then(/^it creates a config directory with the license_finder config$/) do
26
34
  File.should be_exists(@user.app_path('config'))
27
35
  text = "---\nwhitelist:\n#- MIT\n#- Apache 2.0\nignore_groups:\n#- test\n#- development\ndependencies_file_dir: './doc/'\n"
@@ -43,3 +51,11 @@ end
43
51
  Then(/^the mime\-types license remains set with my manual license type$/) do
44
52
  @output.should =~ /mime-types.*Ruby/
45
53
  end
54
+
55
+ Then(/^I should see the correct subcommand usage instructions$/) do
56
+ @output.should include 'license_finder dependencies add LICENSE'
57
+ end
58
+
59
+ Then(/^I should the correct default usage instructions$/) do
60
+ @output.should include 'license_finder help [COMMAND]'
61
+ end
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  When(/^I whitelist the MIT license$/) do
27
27
  @user.configure_license_finder_whitelist ["MIT"]
28
- @user.execute_command "license_finder -q"
28
+ @user.execute_command "license_finder --quiet"
29
29
  end
30
30
 
31
31
  Then(/^I should see my specific gem details listed in the html$/) do
@@ -4,20 +4,20 @@ Given(/^I have an app with license finder that depends on a GPL licensed gem in
4
4
  @user.add_dependency_to_app 'gpl_gem', :license => 'GPL', :bundler_groups => 'test'
5
5
  end
6
6
 
7
- And(/^I add the test group to the ignored bundler groups$/) do
7
+ When(/^I add the test group to the ignored bundler groups$/) do
8
8
  @user.execute_command('license_finder ignored_bundler_group add test')
9
9
  end
10
10
 
11
- And(/^I remove the test group from the ignored bundler groups$/) do
11
+ When(/^I remove the test group from the ignored bundler groups$/) do
12
12
  @user.execute_command('license_finder ignored_bundler_group remove test')
13
13
  end
14
14
 
15
- Then(/^I should not see the GPL licensed gem in the output$/) do
16
- @output.should_not include 'gpl_gem'
15
+ When(/^I get the ignored groups$/) do
16
+ @output = @user.execute_command('license_finder ignored_bundler_group list')
17
17
  end
18
18
 
19
- When(/^I get the ignored groups from the command line$/) do
20
- @output = @user.execute_command('license_finder ignored_bundler_group list')
19
+ Then(/^I should not see the GPL licensed gem in the output$/) do
20
+ @output.should_not include 'gpl_gem'
21
21
  end
22
22
 
23
23
  Then(/^I should see the test group in the output$/) do
@@ -9,7 +9,7 @@ When(/^I add my JS dependency$/) do
9
9
  end
10
10
 
11
11
  When(/^I add my JS dependency with an approval flag$/) do
12
- @output = @user.execute_command 'license_finder dependencies add -a MIT my_js_dep 1.2.3'
12
+ @output = @user.execute_command 'license_finder dependencies add --approve MIT my_js_dep 1.2.3'
13
13
  @output.should == "The my_js_dep dependency has been added and approved!\n"
14
14
  end
15
15
 
@@ -18,16 +18,16 @@ When(/^I remove my JS dependency$/) do
18
18
  end
19
19
 
20
20
  Then(/^I should see the JS dependency in the console output$/) do
21
- @output = @user.execute_command 'license_finder -q'
21
+ @output = @user.execute_command 'license_finder --quiet'
22
22
  @output.should include 'my_js_dep, 1.2.3, MIT'
23
23
  end
24
24
 
25
25
  Then(/^I should not see the JS dependency in the console output$/) do
26
- @output = @user.execute_command 'license_finder -q'
26
+ @output = @user.execute_command 'license_finder --quiet'
27
27
  @output.should_not include 'my_js_dep, 1.2.3, MIT'
28
28
  end
29
29
 
30
30
  Then(/^I should not see the JS dependency in the console output since it is approved$/) do
31
- @output = @user.execute_command 'license_finder -q'
31
+ @output = @user.execute_command 'license_finder --quiet'
32
32
  @output.should_not include 'my_js_dep, 1.2.3, MIT'
33
33
  end
@@ -4,7 +4,7 @@ Given /^I have a rails app(?:lication)? with license finder$/ do
4
4
  end
5
5
 
6
6
  When(/^I run rake license_finder$/) do
7
- @output = @user.execute_command "rake license_finder -q"
7
+ @output = @user.execute_command "rake license_finder --quiet"
8
8
  end
9
9
 
10
10
  Then(/^I should see a normal output$/) do
@@ -6,9 +6,9 @@ Given(/^I have an app with license finder that depends on an other licensed gem$
6
6
  end
7
7
 
8
8
  When(/^I set that gems license to MIT from the command line$/) do
9
- @output = @user.execute_command 'license_finder -q'
9
+ @output = @user.execute_command 'license_finder --quiet'
10
10
  @output = @user.execute_command 'license_finder license MIT other_gem'
11
- @output = @user.execute_command 'license_finder -q'
11
+ @output = @user.execute_command 'license_finder --quiet'
12
12
  end
13
13
 
14
14
  Then(/^I should see that other gems license set to MIT$/) do
@@ -11,12 +11,12 @@ Given(/^I have an app with license finder$/) do
11
11
  end
12
12
 
13
13
  When(/^I run license_finder$/) do
14
- @output = @user.execute_command "license_finder -q"
14
+ @output = @user.execute_command "license_finder --quiet"
15
15
  end
16
16
 
17
- When(/^I whitelist MIT and 'other' licenses$/) do
18
- @user.configure_license_finder_whitelist ["MIT","other"]
19
- @output = @user.execute_command "license_finder -q"
17
+ When(/^I whitelist MIT and 'other' and New BSD licenses$/) do
18
+ @user.configure_license_finder_whitelist ["MIT","other","New BSD"]
19
+ @output = @user.execute_command "license_finder --quiet"
20
20
  end
21
21
 
22
22
  module DSL
@@ -4,11 +4,42 @@ Given(/^I have an app with license finder that depends on an MIT license$/) do
4
4
  @user.add_dependency_to_app 'mit_gem', :license => 'MIT'
5
5
  end
6
6
 
7
+ Given(/^I have an app with license finder that depends on an BSD license$/) do
8
+ @user = ::DSL::User.new
9
+ @user.create_nonrails_app
10
+ @user.add_dependency_to_app 'bsd_gem', :license => 'BSD'
11
+ end
12
+
13
+ When(/^I whitelist the BSD license$/) do
14
+ @user.execute_command 'license_finder whitelist add BSD'
15
+ end
16
+
7
17
  When(/^I whitelist the Expat license$/) do
8
- @user.configure_license_finder_whitelist ["Expat"]
9
- @output = @user.execute_command 'license_finder -q'
18
+ @user.execute_command 'license_finder whitelist add Expat'
19
+ end
20
+
21
+ When(/^I view the whitelisted licenses$/) do
22
+ @output = @user.execute_command 'license_finder whitelist list'
23
+ end
24
+
25
+ When(/^I remove Expat from the whitelist$/) do
26
+ @output = @user.execute_command 'license_finder whitelist remove Expat'
10
27
  end
11
28
 
12
29
  Then(/^I should not see a MIT licensed gem unapproved$/) do
30
+ @output = @user.execute_command 'license_finder --quiet'
13
31
  @output.should_not include 'mit_gem'
14
32
  end
33
+
34
+ Then(/^I should see Expat in the output$/) do
35
+ @output.should include 'Expat'
36
+ end
37
+
38
+ Then(/^I should not see Expat in the output$/) do
39
+ @output.should_not include 'Expat'
40
+ end
41
+
42
+ Then(/^I should not see a BSD licensed gem unapproved$/) do
43
+ @output = @user.execute_command 'license_finder --quiet'
44
+ @output.should_not include 'bsd_gem'
45
+ end
@@ -3,7 +3,25 @@ Feature: Whitelist licenses
3
3
  I want to whitelist certain OSS licenses that my business has pre-approved
4
4
  So that any dependencies with those licenses do not show up as action items
5
5
 
6
- Scenario: Whitelist with MIT License alternative name "Expat" should whitelist "MIT" licenses
6
+ Scenario: Adding a license to the whitelist
7
+ Given I have an app with license finder
8
+ When I whitelist the Expat license
9
+ And I view the whitelisted licenses
10
+ Then I should see Expat in the output
11
+
12
+ Scenario: Whitelisting the BSD License should approve BSD licensed dependencies
13
+ Given I have an app with license finder that depends on an BSD license
14
+ When I whitelist the BSD license
15
+ Then I should not see a BSD licensed gem unapproved
16
+
17
+ Scenario: Removing a license from the whitelist
18
+ Given I have an app with license finder
19
+ When I whitelist the Expat license
20
+ And I remove Expat from the whitelist
21
+ And I view the whitelisted licenses
22
+ Then I should not see Expat in the output
23
+
24
+ Scenario: Whitelist with MIT License aliased name "Expat" should whitelist "MIT" licenses
7
25
  Given I have an app with license finder that depends on an MIT license
8
26
  When I whitelist the Expat license
9
27
  Then I should not see a MIT licensed gem unapproved
@@ -10,7 +10,6 @@ module LicenseFinder
10
10
  autoload :Bundle, 'license_finder/bundle'
11
11
  autoload :BundledGem, 'license_finder/bundled_gem'
12
12
  autoload :BundledGemSaver, 'license_finder/bundled_gem_saver'
13
- autoload :BundlerGroupManager, 'license_finder/bundler_group_manager'
14
13
  autoload :CLI, 'license_finder/cli'
15
14
  autoload :Configuration, 'license_finder/configuration'
16
15
  autoload :DependencyManager, 'license_finder/dependency_manager'
@@ -35,6 +34,10 @@ module LicenseFinder
35
34
  @config ||= Configuration.ensure_default
36
35
  end
37
36
 
37
+ def self.current_gems
38
+ @current_gems ||= Bundle.current_gems
39
+ end
40
+
38
41
  def self.load_rake_tasks
39
42
  load 'tasks/license_finder.rake'
40
43
  end
@@ -1,3 +1,5 @@
1
+ require "bundler"
2
+
1
3
  module LicenseFinder
2
4
  class Bundle
3
5
  attr_writer :ignore_groups
@@ -34,7 +36,7 @@ module LicenseFinder
34
36
  end
35
37
 
36
38
  def included_groups
37
- definition.groups - ignore_groups
39
+ definition.groups - ignore_groups.map(&:to_sym)
38
40
  end
39
41
 
40
42
  def gemfile_path
@@ -42,7 +42,7 @@ module LicenseFinder
42
42
  end
43
43
 
44
44
  def save_as_dependency
45
- BundledGemSaver.find_or_initialize_by_name(@spec.name, self).save
45
+ BundledGemSaver.find_or_create_by_name(@spec.name, self).save
46
46
  end
47
47
  end
48
48
  end
@@ -4,7 +4,9 @@ module LicenseFinder
4
4
  def_delegators :spec, :name, :version, :summary, :description, :homepage
5
5
  def_delegators :bundled_gem, :bundler_dependency, :determine_license, :children
6
6
 
7
- def self.find_or_initialize_by_name(name, bundled_gem)
7
+ attr_reader :dependency, :bundled_gem
8
+
9
+ def self.find_or_create_by_name(name, bundled_gem)
8
10
  dependency = Dependency.named(name)
9
11
  new(dependency, bundled_gem)
10
12
  end
@@ -26,19 +28,27 @@ module LicenseFinder
26
28
 
27
29
  private
28
30
 
29
- attr_reader :dependency, :bundled_gem
30
-
31
31
  def spec
32
32
  bundled_gem.spec
33
33
  end
34
34
 
35
35
  def apply_dependency_definition
36
- dependency.version = version.to_s
37
- dependency.summary = summary
38
- dependency.description = description
39
- dependency.homepage = homepage
40
- dependency.license ||= LicenseAlias.create(name: determine_license)
41
- dependency.save
36
+ if values_have_changed?
37
+ dependency.version = version.to_s
38
+ dependency.summary = summary
39
+ dependency.description = description
40
+ dependency.homepage = homepage
41
+ dependency.license ||= LicenseAlias.create(name: determine_license)
42
+ dependency.save
43
+ end
44
+ end
45
+
46
+ def values_have_changed?
47
+ return dependency.version != version.to_s ||
48
+ dependency.summary != summary ||
49
+ dependency.description != description ||
50
+ dependency.homepage != homepage ||
51
+ dependency.license.name != determine_license
42
52
  end
43
53
 
44
54
  def refresh_bundler_groups
@@ -53,14 +63,27 @@ module LicenseFinder
53
63
  def refresh_children
54
64
  dependency.remove_all_children
55
65
  children.each do |child|
56
- dependency.add_child Dependency.named(child)
66
+ if child_required?(child)
67
+ dependency.add_child Dependency.named(child)
68
+ end
57
69
  end
58
70
  end
59
71
 
72
+ def child_required?(child)
73
+ current_gem_names.include?(child)
74
+ end
75
+
76
+ def current_gem_names
77
+ @current_gem_names ||= LicenseFinder.current_gems.map { |gem| gem.name.split(" ")[0] }
78
+ end
79
+
60
80
  def apply_better_license
61
81
  if dependency.license && !dependency.license.manual && determine_license != 'other'
62
- dependency.license.name = determine_license
63
- dependency.license.save
82
+ new_name = determine_license
83
+ unless new_name == dependency.license.name
84
+ dependency.license.name = new_name
85
+ dependency.license.save
86
+ end
64
87
  end
65
88
  end
66
89
  end
@@ -19,8 +19,17 @@ module LicenseFinder
19
19
  end
20
20
  end
21
21
 
22
- class Dependencies < Base
23
- option :approve, type: :boolean, aliases: :a
22
+ # Thor fix for `license_finder <subcommand> help <action>`
23
+ class Subcommand < Base
24
+ # Hack to override the help message produced by Thor.
25
+ # https://github.com/wycats/thor/issues/261#issuecomment-16880836
26
+ def self.banner(command, namespace = nil, subcommand = nil)
27
+ "#{basename} #{name.split("::").last.downcase} #{command.usage}"
28
+ end
29
+ end
30
+
31
+ class Dependencies < Subcommand
32
+ option :approve, type: :boolean, desc: "Approve the added dependency"
24
33
  desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve]", "Add a dependency that is not managed by Bundler"
25
34
  def add(license, name, version = nil)
26
35
  die_on_error {
@@ -44,12 +53,42 @@ module LicenseFinder
44
53
  end
45
54
  end
46
55
 
47
- class IgnoredBundlerGroups < Base
56
+ class Whitelist < Subcommand
57
+ desc "list", "List all the whitelisted licenses"
58
+ def list
59
+ whitelist = LicenseFinder.config.whitelist
60
+
61
+ say "Whitelisted Licenses:", :blue
62
+ whitelist.each do |license|
63
+ say license
64
+ end
65
+ end
66
+
67
+ desc "add", "Add a license to the whitelist"
68
+ def add(license)
69
+ die_on_error {
70
+ LicenseFinder.config.whitelist.push(license)
71
+ LicenseFinder.config.save
72
+ }
73
+ say "Added #{license} to the license whitelist"
74
+ end
75
+
76
+ desc "remove", "Remove a license from the whitelist"
77
+ def remove(license)
78
+ die_on_error {
79
+ LicenseFinder.config.whitelist.delete(license)
80
+ LicenseFinder.config.save
81
+ }
82
+ say "Removed #{license} from the license whitelist"
83
+ end
84
+ end
85
+
86
+ class IgnoredBundlerGroups < Subcommand
48
87
  desc "list", "List all the ignored bundler groups"
49
88
  def list
50
89
  ignored = LicenseFinder.config.ignore_groups
51
90
 
52
- say "Ignored Bundler Groups:", :red
91
+ say "Ignored Bundler Groups:", :blue
53
92
  ignored.each do |group|
54
93
  say group
55
94
  end
@@ -58,7 +97,8 @@ module LicenseFinder
58
97
  desc "add", "Add a bundler group to be ignored"
59
98
  def add(group)
60
99
  die_on_error {
61
- BundlerGroupManager.add_ignored_group(group)
100
+ LicenseFinder.config.ignore_groups.push(group)
101
+ LicenseFinder.config.save
62
102
  }
63
103
  say "Added #{group} to the ignored bundler groups"
64
104
  end
@@ -66,15 +106,16 @@ module LicenseFinder
66
106
  desc "remove", "Remove a bundler group from the ignored bundler groups"
67
107
  def remove(group)
68
108
  die_on_error {
69
- BundlerGroupManager.remove_ignored_group(group)
109
+ LicenseFinder.config.ignore_groups.delete(group)
110
+ LicenseFinder.config.save
70
111
  }
71
112
  say "Removed #{group} from the ignored bundler groups"
72
113
  end
73
114
  end
74
115
 
75
116
  class Main < Base
76
- option :quiet, type: :boolean, aliases: :q
77
- desc "rescan", "Find new dependencies."
117
+ option :quiet, type: :boolean, desc: "silences loading output"
118
+ desc "rescan", "Find new dependencies. (Default action)"
78
119
  def rescan
79
120
  die_on_error {
80
121
  spinner {
@@ -125,6 +166,7 @@ module LicenseFinder
125
166
 
126
167
  subcommand "dependencies", Dependencies, "manage non-Bundler dependencies"
127
168
  subcommand "ignored_bundler_groups", IgnoredBundlerGroups, "manage ignored bundler groups"
169
+ subcommand "whitelist", Whitelist, "manage whitelisted licenses"
128
170
 
129
171
  private
130
172