license_finder 0.8.1 → 0.8.2

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 (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.rdoc +14 -1
  4. data/bin/license_finder +1 -61
  5. data/db/migrate/201304181524_add_manual_to_dependencies.rb +7 -0
  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 +1 -1
  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 +8 -3
  14. data/lib/license_finder.rb +23 -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/cli.rb +109 -32
  19. data/lib/license_finder/configuration.rb +19 -8
  20. data/lib/license_finder/dependency_manager.rb +49 -0
  21. data/lib/license_finder/license.rb +3 -3
  22. data/lib/license_finder/{license_files.rb → possible_license_files.rb} +2 -2
  23. data/lib/license_finder/{dependency_report.rb → reports/dependency_report.rb} +1 -1
  24. data/lib/license_finder/{html_report.rb → reports/html_report.rb} +0 -0
  25. data/lib/license_finder/{reporter.rb → reports/reporter.rb} +0 -0
  26. data/lib/license_finder/{text_report.rb → reports/text_report.rb} +0 -0
  27. data/lib/license_finder/tables.rb +1 -1
  28. data/lib/license_finder/tables/dependency.rb +24 -5
  29. data/lib/license_finder/yml_to_sql.rb +5 -0
  30. data/lib/tasks/license_finder.rake +1 -1
  31. data/license_finder.gemspec +5 -3
  32. data/readme.md +80 -26
  33. data/spec/lib/license_finder/bundle_spec.rb +4 -11
  34. data/spec/lib/license_finder/{gem_saver_spec.rb → bundled_gem_saver_spec.rb} +7 -4
  35. data/spec/lib/license_finder/bundled_gem_spec.rb +1 -1
  36. data/spec/lib/license_finder/cli_spec.rb +86 -18
  37. data/spec/lib/license_finder/configuration_spec.rb +5 -2
  38. data/spec/lib/license_finder/dependency_manager_spec.rb +107 -0
  39. data/spec/lib/license_finder/html_report_spec.rb +3 -3
  40. data/spec/lib/license_finder/{license_files_spec.rb → possible_license_files_spec.rb} +7 -7
  41. data/spec/lib/license_finder/tables/dependency_spec.rb +31 -44
  42. data/spec/lib/license_finder/yml_to_sql_spec.rb +24 -2
  43. data/spec/support/silence_stdout.rb +13 -0
  44. metadata +66 -72
  45. data/lib/license_finder/bundle_syncer.rb +0 -11
  46. data/spec/lib/license_finder/bundle_syncer_spec.rb +0 -16
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 145e1e16abccb31283a36af7e17e267debf7311e
4
+ data.tar.gz: 30c980da2290161caf8be382f506aed979a31a8e
5
+ SHA512:
6
+ metadata.gz: 5041534cffb5b947d28b4280774a95a605350f67fde724643cb062141ed6141a79f6e395a5b909623640d4569cf1b2e2668caa27eb4e7629eda49d85767c65cc
7
+ data.tar.gz: 96b37486e8b5a22beeb4cec03a0f7d67394cb6ffd293c66b854647c883d4b854274ba2d0aed428533de88dc3da4077df10a8f917988fdf20d7e7f6b92811b28d
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ doc/dependencies.*
10
10
  db/schema.rb
11
11
  config/
12
12
  .pairs
13
+ *.swp
@@ -1,8 +1,21 @@
1
+ === TBD
2
+
3
+ * Features
4
+
5
+ * Switch to thor for CLI, to support future additions to CLI
6
+ * Restore ability to manage (add/remove) dependencies that Bundler can't find
7
+
8
+ * Bugfixes
9
+
10
+ * Fix bug preventing manual approval of child dependencies (Issue #23)
11
+ * Fix issue with database URI when the absolute path to the database file
12
+ contains spaces.
13
+ * Upgrading from 0.7.2 no longer removes non-gem dependencies (Issue #20)
14
+
1
15
  === 0.8.1 / 2013-04-14
2
16
 
3
17
  * Features
4
18
 
5
- * Add spinner to show that the binary is actually doing something.
6
19
  * JRuby version of the gem.
7
20
  * Official ruby 2.0 support.
8
21
  * CLI interface for moving dependencies.* files to `doc/`.
@@ -1,65 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'license_finder'
4
- require 'optparse'
5
4
 
6
- module SpinnerStrategy
7
- module Spin
8
- def self.run
9
- thread = Thread.new() {
10
- wheel = '\|/-'
11
- i = 0
12
- while not LicenseFinder::CLI.class_variable_get("@@run_complete") do
13
- print "\r ---------- #{wheel[i]} ----------"
14
- i = (i + 1) % 4
15
- end
16
- }
17
- yield
18
- thread.join
19
- end
20
- end
21
-
22
- module Noop
23
- def self.run
24
- yield
25
- end
26
- end
27
- end
28
-
29
- options = {}
30
- spinner = SpinnerStrategy::Spin
31
- skip = false
32
-
33
- OptionParser.new do |opts|
34
- opts.banner = "Usage: license_finder [options] [dependency]"
35
-
36
- opts.on("-a", "--approve", "Approve a gem by name.") do |gem_name|
37
- options[:approve] = true
38
- end
39
-
40
- opts.on("-l", "--license [LICENSE]", "Update a gem's license.") do |license|
41
- options[:license] = license
42
- end
43
-
44
- opts.on("-q", "--quiet") do
45
- spinner = SpinnerStrategy::Noop
46
- end
47
-
48
- opts.on("-m", "--move") do
49
- skip = true
50
- `sed '$d' < config/license_finder.yml > tmp34567.txt`
51
- `mv tmp34567.txt config/license_finder.yml`
52
- `echo "dependencies_file_dir: './doc/'" >> config/license_finder.yml`
53
- `mkdir doc`
54
- `mv dependencies.* doc/`
55
- puts "Congratulations, you have cleaned up your root directory!'"
56
- end
57
- end.parse!
58
-
59
- unless options.empty?
60
- options[:dependency] = ARGV.last
61
- end
62
-
63
- spinner.run {
64
- LicenseFinder::CLI.execute!(options)
65
- } unless skip
5
+ LicenseFinder::CLI::Main.start
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:dependencies) do
4
+ add_column :manual, TrueClass # i.e., keep this dependency eternally
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ Feature: Tracking non-Bundler Dependencies
2
+ So that I can track JS and other dependencies not tracked by Bundler
3
+ As an application developer using license finder
4
+ I want to be able to manually manage non-Bundler dependencies
5
+
6
+ Scenario: Adding a non-Bundler dependency
7
+ Given I have an app with license finder
8
+ When I add my JS dependency
9
+ Then I should see the JS dependency in the console output
10
+
11
+ Scenario: Auto approving a non-Bundler dependency I add
12
+ Given I have an app with license finder
13
+ When I add my JS dependency with an approval flag
14
+ Then I should not see the JS dependency in the console output since it is approved
15
+
16
+ Scenario: Removing a non-Bundler dependency
17
+ Given I have an app with license finder and a JS dependency
18
+ When I remove my JS dependency
19
+ Then I should not see the JS dependency in the console output
@@ -7,7 +7,7 @@ end
7
7
  When(/^I approve that gem$/) do
8
8
  @output = @user.execute_command "license_finder"
9
9
  @output.should include "gpl_gem"
10
- @output = @user.execute_command "license_finder -a gpl_gem"
10
+ @output = @user.execute_command "license_finder approve gpl_gem"
11
11
  @output = @user.execute_command "license_finder -q"
12
12
  end
13
13
 
@@ -18,7 +18,7 @@ Given(/^I have a project that depends on mime\-types with a manual license type$
18
18
  @user.add_gem_dependency('mime-types')
19
19
  @user.bundle_app
20
20
  @user.execute_command "license_finder -q"
21
- @output = @user.execute_command "license_finder -l Ruby mime-types"
21
+ @output = @user.execute_command "license_finder license Ruby mime-types"
22
22
  @output.should =~ /mime-types.*Ruby/
23
23
  end
24
24
 
@@ -1,8 +1,3 @@
1
- Given(/^I have an app with license finder$/) do
2
- @user = ::DSL::User.new
3
- @user.create_nonrails_app
4
- end
5
-
6
1
  Given(/^my app depends on a gem with specific details$/) do
7
2
  @gem_name = "mit_licensed_gem"
8
3
  @table = {
@@ -54,7 +49,7 @@ end
54
49
  Then(/^I should see only see GPL liceneses as unapproved in the html$/) do
55
50
  html = File.read(@user.dependencies_html_path)
56
51
  page = Capybara.string(html)
57
- page.should have_content '8 total'
52
+ page.should have_content '9 total'
58
53
  page.should have_content '1 unapproved'
59
54
  page.should have_content '1 GPL'
60
55
  end
@@ -5,7 +5,7 @@ Given(/^I have an app with license finder that depends on a GPL licensed gem in
5
5
  end
6
6
 
7
7
  And(/^I ignore the test group$/) do
8
- @user.configure_license_finder_bundler_whitelist('test')
8
+ @user.configure_license_finder_bundler_ignore_groups('test')
9
9
  end
10
10
 
11
11
  Then(/^I should not see the GPL licensed gem in the output$/) do
@@ -0,0 +1,33 @@
1
+ Given(/^I have an app with license finder and a JS dependency$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_nonrails_app
4
+ @output = @user.execute_command 'license_finder dependencies add MIT my_js_dep 1.2.3'
5
+ end
6
+
7
+ When(/^I add my JS dependency$/) do
8
+ @output = @user.execute_command 'license_finder dependencies add MIT my_js_dep 1.2.3'
9
+ end
10
+
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'
13
+ @output.should == "The my_js_dep dependency has been added and approved!\n"
14
+ end
15
+
16
+ When(/^I remove my JS dependency$/) do
17
+ @user.execute_command 'license_finder dependencies remove my_js_dep'
18
+ end
19
+
20
+ Then(/^I should see the JS dependency in the console output$/) do
21
+ @output = @user.execute_command 'license_finder -q'
22
+ @output.should include 'my_js_dep, 1.2.3, MIT'
23
+ end
24
+
25
+ Then(/^I should not see the JS dependency in the console output$/) do
26
+ @output = @user.execute_command 'license_finder -q'
27
+ @output.should_not include 'my_js_dep, 1.2.3, MIT'
28
+ end
29
+
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'
32
+ @output.should_not include 'my_js_dep, 1.2.3, MIT'
33
+ end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  When(/^I set that gems license to MIT from the command line$/) do
9
9
  @output = @user.execute_command 'license_finder -q'
10
- @output = @user.execute_command 'license_finder -lq MIT other_gem'
10
+ @output = @user.execute_command 'license_finder license MIT other_gem'
11
11
  @output = @user.execute_command 'license_finder -q'
12
12
  end
13
13
 
@@ -5,6 +5,11 @@ require 'capybara'
5
5
 
6
6
  ########## COMMON STEPS ##########
7
7
 
8
+ Given(/^I have an app with license finder$/) do
9
+ @user = ::DSL::User.new
10
+ @user.create_nonrails_app
11
+ end
12
+
8
13
  When(/^I run license_finder$/) do
9
14
  @output = @user.execute_command "license_finder -q"
10
15
  end
@@ -103,11 +108,11 @@ module DSL
103
108
  end
104
109
  end
105
110
 
106
- def configure_license_finder_bundler_whitelist(whitelisted_groups=[])
107
- whitelisted_groups = Array whitelisted_groups
111
+ def configure_license_finder_bundler_ignore_groups(ignored_groups=[])
112
+ ignored_groups = Array ignored_groups
108
113
  FileUtils.mkdir_p(config_path)
109
114
  File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
110
- f.write({'ignore_groups' => whitelisted_groups}.to_yaml)
115
+ f.write({'ignore_groups' => ignored_groups}.to_yaml)
111
116
  end
112
117
  end
113
118
 
@@ -5,32 +5,30 @@ require 'erb'
5
5
  module LicenseFinder
6
6
  ROOT_PATH = Pathname.new(__FILE__).dirname
7
7
 
8
- DEPENDENCY_ATTRIBUTES = [
9
- "name", "version", "license", "license_url", "approved", "notes",
10
- "license_files", "bundler_groups", "summary",
11
- "description", "homepage", "children", "parents", "manual"
12
- ]
13
-
14
- autoload :Bundle, 'license_finder/bundle'
15
- autoload :BundledGem, 'license_finder/bundled_gem'
16
- autoload :CLI, 'license_finder/cli'
17
- autoload :Configuration, 'license_finder/configuration'
18
- autoload :License, 'license_finder/license'
19
- autoload :LicenseUrl, 'license_finder/license_url'
20
- autoload :PossibleLicenseFile, 'license_finder/possible_license_file'
21
- autoload :DependencyReport, 'license_finder/dependency_report'
22
- autoload :HtmlReport, 'license_finder/html_report'
23
- autoload :TextReport, 'license_finder/text_report'
24
- autoload :Reporter, 'license_finder/reporter'
25
- autoload :BundleSyncer, 'license_finder/bundle_syncer'
26
- autoload :YmlToSql, 'license_finder/yml_to_sql'
27
- autoload :Dependency, 'license_finder/tables/dependency'
28
- autoload :Approval, 'license_finder/tables/approval'
29
- autoload :LicenseAlias, 'license_finder/tables/license_alias'
8
+ Error = Class.new(StandardError)
9
+
10
+ autoload :Bundle, 'license_finder/bundle'
11
+ autoload :BundledGem, 'license_finder/bundled_gem'
12
+ autoload :BundledGemSaver, 'license_finder/bundled_gem_saver'
13
+ autoload :CLI, 'license_finder/cli'
14
+ autoload :Configuration, 'license_finder/configuration'
15
+ autoload :DependencyManager, 'license_finder/dependency_manager'
16
+ autoload :License, 'license_finder/license'
17
+ autoload :LicenseUrl, 'license_finder/license_url'
18
+ autoload :Platform, 'license_finder/platform'
19
+ autoload :PossibleLicenseFile, 'license_finder/possible_license_file'
20
+ autoload :PossibleLicenseFiles, 'license_finder/possible_license_files'
21
+ autoload :YmlToSql, 'license_finder/yml_to_sql'
22
+
23
+ autoload :Approval, 'license_finder/tables/approval'
30
24
  autoload :BundlerGroup, 'license_finder/tables/bundler_group'
31
- autoload :GemSaver, 'license_finder/gem_saver'
32
- autoload :LicenseFiles, 'license_finder/license_files'
33
- autoload :Platform, 'license_finder/platform'
25
+ autoload :Dependency, 'license_finder/tables/dependency'
26
+ autoload :LicenseAlias, 'license_finder/tables/license_alias'
27
+
28
+ autoload :DependencyReport, 'license_finder/reports/dependency_report'
29
+ autoload :HtmlReport, 'license_finder/reports/html_report'
30
+ autoload :Reporter, 'license_finder/reports/reporter'
31
+ autoload :TextReport, 'license_finder/reports/text_report'
34
32
 
35
33
  def self.config
36
34
  @config ||= Configuration.ensure_default
@@ -2,8 +2,8 @@ module LicenseFinder
2
2
  class Bundle
3
3
  attr_writer :ignore_groups
4
4
 
5
- def self.current_gem_dependencies(bundler_definition=nil)
6
- new(bundler_definition).gems.map(&:save_or_merge)
5
+ def self.current_gems(bundler_definition=nil)
6
+ new(bundler_definition).gems
7
7
  end
8
8
 
9
9
  def initialize(bundler_definition=nil)
@@ -34,15 +34,15 @@ module LicenseFinder
34
34
  end
35
35
 
36
36
  def license_files
37
- LicenseFiles.new(@spec.full_gem_path).files
37
+ PossibleLicenseFiles.new(@spec.full_gem_path).find
38
38
  end
39
39
 
40
40
  def sort_order
41
41
  dependency_name.downcase
42
42
  end
43
43
 
44
- def save_or_merge
45
- GemSaver.find_or_initialize_by_name(@spec.name, self).save
44
+ def save_as_dependency
45
+ BundledGemSaver.find_or_initialize_by_name(@spec.name, self).save
46
46
  end
47
47
  end
48
48
  end
@@ -1,13 +1,11 @@
1
1
  module LicenseFinder
2
- class GemSaver
2
+ class BundledGemSaver
3
3
  extend Forwardable
4
4
  def_delegators :spec, :name, :version, :summary, :description, :homepage
5
5
  def_delegators :bundled_gem, :bundler_dependency, :determine_license, :children
6
6
 
7
7
  def self.find_or_initialize_by_name(name, bundled_gem)
8
- dependency = Dependency.find_or_create(name: name) do |d|
9
- d.approval = Approval.create
10
- end
8
+ dependency = Dependency.named(name)
11
9
  new(dependency, bundled_gem)
12
10
  end
13
11
 
@@ -55,7 +53,7 @@ module LicenseFinder
55
53
  def refresh_children
56
54
  dependency.remove_all_children
57
55
  children.each do |child|
58
- dependency.add_child Dependency.find_or_create(name: child.to_s)
56
+ dependency.add_child Dependency.named(child)
59
57
  end
60
58
  end
61
59
 
@@ -1,49 +1,126 @@
1
+ require 'thor'
2
+
1
3
  module LicenseFinder
2
4
  module CLI
3
- extend self
4
-
5
- @@run_complete = false
6
-
7
- def check_for_action_items
8
- BundleSyncer.sync!
9
- @@run_complete = true
10
- generate_reports
5
+ class Base < Thor
6
+ def self.subcommand(namespace, klass, namespace_description)
7
+ description = "#{namespace} [#{(klass.tasks.keys - ["help"]).join("|")}]"
8
+ desc description, "#{namespace_description} - see `license_finder #{namespace} help` for more information"
9
+ super namespace, klass
10
+ end
11
11
 
12
- unapproved = Dependency.unapproved
12
+ private
13
13
 
14
- puts "\r" + " "*24
15
- if unapproved.count == 0
16
- puts "All gems are approved for use"
17
- else
18
- puts "Dependencies that need approval:"
19
- puts TextReport.new(unapproved)
14
+ def die_on_error
15
+ yield
16
+ rescue LicenseFinder::Error => e
17
+ say e.message, :red
20
18
  exit 1
21
19
  end
22
20
  end
23
21
 
24
- def execute!(options={})
25
- if options.empty?
26
- check_for_action_items
27
- else
28
- dependency = Dependency.first(name: options[:dependency])
29
-
30
- @@run_complete = true
31
- puts "\r" + " "*24
22
+ class Dependencies < Base
23
+ option :approve, type: :boolean, aliases: :a
24
+ desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve]", "Add a dependency that is not managed by Bundler"
25
+ def add(license, name, version = nil)
26
+ die_on_error {
27
+ DependencyManager.create_non_bundler(license, name, version)
28
+ DependencyManager.approve!(name) if options[:approve]
29
+ }
32
30
  if options[:approve]
33
- dependency.approve!
34
- puts "The #{dependency.name} has been approved!\n\n"
35
- elsif options[:license]
36
- dependency.set_license_manually options[:license]
37
- puts "The #{dependency.name} has been marked as using #{options[:license]} license!\n\n"
31
+ say "The #{name} dependency has been added and approved!", :green
32
+ else
33
+ say "The #{name} dependency has been added!", :green
38
34
  end
35
+ end
36
+
37
+ desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler"
38
+ def remove(name)
39
+ die_on_error {
40
+ DependencyManager.destroy_non_bundler(name)
41
+ }
39
42
 
40
- generate_reports
43
+ say "The #{name} dependency has been removed.", :green
41
44
  end
42
45
  end
43
46
 
44
- private
45
- def generate_reports
46
- Reporter.write_reports
47
+ class Main < Base
48
+ option :quiet, type: :boolean, aliases: :q
49
+ desc "rescan", "Find new dependencies."
50
+ def rescan
51
+ die_on_error {
52
+ spinner {
53
+ DependencyManager.sync_with_bundler
54
+ }
55
+ }
56
+
57
+ action_items
58
+ end
59
+ default_task :rescan
60
+
61
+ desc "approve DEPENDENCY_NAME", "Approve a dependency by name."
62
+ def approve(name)
63
+ die_on_error {
64
+ DependencyManager.approve!(name)
65
+ }
66
+
67
+ say "The #{name} dependency has been approved!", :green
68
+ end
69
+
70
+ desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license."
71
+ def license(license, name)
72
+ die_on_error {
73
+ DependencyManager.license!(name, license)
74
+ }
75
+
76
+ say "The #{name} dependency has been marked as using #{license} license!", :green
77
+ end
78
+
79
+ desc "move", "Move dependency.* files from root directory to doc/."
80
+ def move
81
+ Configuration.move!
82
+ say "Congratulations, you have cleaned up your root directory!'", :green
83
+ end
84
+
85
+ desc "action_items", "List unapproved dependencies"
86
+ def action_items
87
+ unapproved = Dependency.unapproved
88
+
89
+ if unapproved.empty?
90
+ say "All gems are approved for use", :green
91
+ else
92
+ say "Dependencies that need approval:", :red
93
+ say TextReport.new(unapproved)
94
+ exit 1
95
+ end
96
+ end
97
+
98
+ subcommand "dependencies", Dependencies, "manage non-Bundler dependencies"
99
+
100
+ private
101
+
102
+ def spinner
103
+ if options[:quiet]
104
+ yield
105
+ else
106
+ begin
107
+ thread = Thread.new {
108
+ wheel = '\|/-'
109
+ i = 0
110
+ while true do
111
+ print "\r ---------- #{wheel[i]} ----------"
112
+ i = (i + 1) % 4
113
+ end
114
+ }
115
+ yield
116
+ ensure
117
+ if thread
118
+ thread.kill
119
+ puts "\r" + " "*24
120
+ end
121
+ end
122
+ end
123
+ end
47
124
  end
48
125
  end
49
126
  end