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
@@ -14,16 +14,31 @@ module LicenseFinder
14
14
  def self.make_config_file
15
15
  FileUtils.mkdir_p(File.join('.', 'config'))
16
16
  FileUtils.cp(
17
- File.join(File.dirname(__FILE__), '..', '..', 'files', 'license_finder.yml'),
17
+ ROOT_PATH.join('..', 'files', 'license_finder.yml'),
18
18
  config_file_path
19
19
  )
20
20
  end
21
21
 
22
- def initialize(config={})
22
+ def self.move!
23
+ config = config_hash('dependencies_file_dir' => './doc/')
24
+ File.open(config_file_path, 'w') do |f|
25
+ f.write YAML.dump(config)
26
+ end
27
+
28
+ FileUtils.mkdir_p("doc")
29
+ FileUtils.mv(Dir["dependencies.*"], "doc")
30
+ end
31
+
32
+ def self.config_hash(config)
23
33
  if File.exists?(config_file_path)
24
34
  yaml = File.read(config_file_path)
25
35
  config = YAML.load(yaml).merge config
26
36
  end
37
+ config
38
+ end
39
+
40
+ def initialize(config={})
41
+ config = self.class.config_hash(config)
27
42
 
28
43
  @whitelist = config['whitelist'] || []
29
44
  @ignore_groups = (config["ignore_groups"] || []).map(&:to_sym)
@@ -31,12 +46,8 @@ module LicenseFinder
31
46
  FileUtils.mkdir_p(@dependencies_dir)
32
47
  end
33
48
 
34
- def config_file_path
35
- self.class.config_file_path
36
- end
37
-
38
- def database_path
39
- File.expand_path(File.join(dependencies_dir, "dependencies.db"))
49
+ def database_uri
50
+ URI.escape(File.expand_path(File.join(dependencies_dir, "dependencies.db")))
40
51
  end
41
52
 
42
53
  def dependencies_yaml
@@ -51,15 +62,20 @@ module LicenseFinder
51
62
  File.join(dependencies_dir, "dependencies.html")
52
63
  end
53
64
 
54
- def ignore_groups
55
- @ignore_groups.map &:to_sym
56
- end
57
-
58
65
  def whitelisted?(license_name)
59
66
  license = License.find_by_name(license_name) || license_name
60
67
  whitelisted_licenses.include? license
61
68
  end
62
69
 
70
+ def save_to_yaml
71
+ File.open(Configuration.config_file_path, 'w') do |file|
72
+ file.write({
73
+ 'whitelist' => @whitelist,
74
+ 'ignore_groups' => @ignore_groups
75
+ }.to_yaml)
76
+ end
77
+ end
78
+
63
79
  private
64
80
 
65
81
  def whitelisted_licenses
@@ -0,0 +1,49 @@
1
+ module LicenseFinder
2
+ module DependencyManager
3
+ def self.sync_with_bundler
4
+ current_gems = Bundle.current_gems
5
+ modifying {
6
+ current_dependencies = current_gems.map(&:save_as_dependency)
7
+ Dependency.bundler.obsolete(current_dependencies).each(&:destroy)
8
+ }
9
+ end
10
+
11
+ def self.create_non_bundler(license, name, version)
12
+ raise Error.new("#{name} dependency already exists") unless Dependency.where(name: name).empty?
13
+
14
+ modifying {
15
+ dependency = Dependency.new(manual: true, name: name, version: version)
16
+ dependency.license = LicenseAlias.create(name: license)
17
+ dependency.approval = Approval.create
18
+ dependency.save
19
+ }
20
+ end
21
+
22
+ def self.destroy_non_bundler(name)
23
+ modifying { find_by_name(name, Dependency.non_bundler).destroy }
24
+ end
25
+
26
+ def self.license!(name, license)
27
+ modifying { find_by_name(name).license.set_manually(license) }
28
+ end
29
+
30
+ def self.approve!(name)
31
+ modifying { find_by_name(name).approve! }
32
+ end
33
+
34
+ private # not really private, but it looks like it is!
35
+
36
+ def self.find_by_name(name, scope = Dependency)
37
+ dep = scope.first(name: name)
38
+ raise Error.new("could not find dependency named #{name}") unless dep
39
+ dep
40
+ end
41
+
42
+ def self.modifying
43
+ result = yield
44
+ Reporter.write_reports
45
+ result
46
+ end
47
+ end
48
+ end
49
+
@@ -56,9 +56,9 @@ module LicenseFinder
56
56
 
57
57
  def license_text
58
58
  unless defined?(@license_text)
59
- template = File.join(ROOT_PATH, "data", "licenses", "#{demodulized_name}.txt").to_s
59
+ template = ROOT_PATH.join("data", "licenses", "#{demodulized_name}.txt")
60
60
 
61
- @license_text = Text.new(File.read(template)).to_s if File.exists?(template)
61
+ @license_text = Text.new(template.read).to_s if template.exist?
62
62
  end
63
63
  @license_text
64
64
  end
@@ -85,6 +85,6 @@ module LicenseFinder
85
85
  end
86
86
  end
87
87
 
88
- Dir[File.join(File.dirname(__FILE__), 'license', '*.rb')].each do |license|
88
+ Pathname.glob(LicenseFinder::ROOT_PATH.join('license_finder', 'license', "*.rb")) do |license|
89
89
  require license
90
90
  end
@@ -1,5 +1,5 @@
1
1
  module LicenseFinder
2
- class LicenseFiles
2
+ class PossibleLicenseFiles
3
3
  LICENSE_FILE_NAMES = %w(LICENSE License Licence COPYING README Readme ReadMe)
4
4
 
5
5
  def initialize(install_path)
@@ -8,7 +8,7 @@ module LicenseFinder
8
8
 
9
9
  attr_reader :install_path
10
10
 
11
- def files
11
+ def find
12
12
  paths_for_license_files.map do |path|
13
13
  get_file_for_path(path)
14
14
  end
@@ -15,7 +15,7 @@ module LicenseFinder
15
15
  end
16
16
 
17
17
  def to_s
18
- filename = File.join(File.dirname(__FILE__), '..', 'templates', "#{self.class.underscored_name}.erb")
18
+ filename = ROOT_PATH.join('templates', "#{self.class.underscored_name}.erb")
19
19
  template = ERB.new(File.read(filename), 0, '-')
20
20
  template.result(binding)
21
21
  end
@@ -2,6 +2,6 @@ require 'rubygems'
2
2
  require 'sequel'
3
3
  require LicenseFinder::Platform.sqlite_load_path
4
4
 
5
- DB = Sequel.connect("#{LicenseFinder::Platform.sqlite_adapter}://#{LicenseFinder.config.database_path}")
5
+ DB = Sequel.connect("#{LicenseFinder::Platform.sqlite_adapter}://#{LicenseFinder.config.database_uri}")
6
6
  Sequel.extension :migration, :core_extensions
7
7
  Sequel::Migrator.run(DB, LicenseFinder::ROOT_PATH.join('../db/migrate'))
@@ -1,30 +1,49 @@
1
1
  module LicenseFinder
2
2
  class Dependency < Sequel::Model
3
+ plugin :boolean_readers
3
4
  many_to_one :license, class: LicenseAlias
4
5
  many_to_one :approval
5
6
  many_to_many :children, join_table: :ancestries, left_key: :parent_dependency_id, right_key: :child_dependency_id, class: self
6
7
  many_to_many :parents, join_table: :ancestries, left_key: :child_dependency_id, right_key: :parent_dependency_id, class: self
7
8
  many_to_many :bundler_groups
8
9
 
9
- def self.destroy_obsolete(current_dependencies)
10
- exclude(id: current_dependencies.map(&:id)).each(&:destroy)
10
+ dataset_module do
11
+ def bundler
12
+ exclude(manual: true)
13
+ end
14
+
15
+ def non_bundler
16
+ bundler.invert
17
+ end
18
+
19
+ def obsolete(current)
20
+ exclude(id: current.map(&:id))
21
+ end
11
22
  end
12
23
 
13
24
  def self.unapproved
14
25
  all.reject(&:approved?)
15
26
  end
16
27
 
28
+ def self.named(name)
29
+ d = find_or_create(name: name.to_s)
30
+ d.ensure_approval_exists!
31
+ d
32
+ end
33
+
17
34
  def approve!
18
35
  approval.state = true
19
36
  approval.save
20
37
  end
21
38
 
22
39
  def approved?
23
- (license && license.whitelisted?) || (approval && approval.state)
40
+ (license && license.whitelisted?) || approval.state
24
41
  end
25
42
 
26
- def set_license_manually(name)
27
- license.set_manually(name)
43
+ def ensure_approval_exists!
44
+ return if approval
45
+ self.approval = Approval.create
46
+ save
28
47
  end
29
48
  end
30
49
  end
@@ -41,6 +41,7 @@ module LicenseFinder
41
41
  @dep = create_dependency
42
42
  @dep.license = create_license
43
43
  @dep.approval = create_approval
44
+ @dep.manual = non_bundler_source?
44
45
  associate_bundler_groups
45
46
  @dep.save
46
47
  end
@@ -57,6 +58,10 @@ module LicenseFinder
57
58
  end
58
59
  end
59
60
 
61
+ def non_bundler_source?
62
+ @legacy_attrs['source'] == "bundle" ? false : true
63
+ end
64
+
60
65
  def create_dependency
61
66
  Sql::Dependency.convert(legacy_attrs)
62
67
  end
@@ -3,5 +3,5 @@ task :license_finder do
3
3
  puts "DEPRECATION WARNING: 'rake license_finder' is going to be removed
4
4
  for the 1.0.0 release. Please instead use the command line utility 'license_finder'
5
5
  or refer to the README for avalible command line utilities"
6
- LicenseFinder::CLI.check_for_action_items
6
+ LicenseFinder::CLI::Main.new.rescan
7
7
  end
@@ -2,8 +2,8 @@ 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.1"
6
- s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards", "Paul Meskers", "Brent Wheeldon", "David Tengdin"]
5
+ s.version = "0.8.2"
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"
9
9
  s.summary = "Audit the OSS licenses of your application's dependencies."
@@ -20,12 +20,14 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "bundler"
22
22
  s.add_dependency "sequel"
23
+ s.add_dependency "thor"
23
24
  s.add_dependency LicenseFinder::Platform.sqlite_gem
24
25
 
25
- %w(rspec rake xpath cucumber database_cleaner).each do |gem|
26
+ %w(rspec rake xpath cucumber).each do |gem|
26
27
  s.add_development_dependency gem
27
28
  end
28
29
 
30
+ s.add_development_dependency "database_cleaner", "0.9.1"
29
31
  s.add_development_dependency "capybara", "~> 2.0.0"
30
32
  s.add_development_dependency "rails", "~> 3.2.0"
31
33
 
data/readme.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # License Finder
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/pivotal/LicenseFinder.png)](http://travis-ci.org/pivotal/LicenseFinder)
4
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/pivotal/LicenseFinder)
4
+ [![Code Climate](https://codeclimate.com/github/pivotal/LicenseFinder.png)](https://codeclimate.com/github/pivotal/LicenseFinder)
5
5
 
6
6
  With bundler it's easy for your project to depend on many gems. This decomposition is nice, but managing licenses becomes difficult. This tool gathers info about the licenses of the gems in your project.
7
7
 
8
+
8
9
  ## Installation
9
10
 
10
11
  Add license_finder to your project's Gemfile and `bundle`:
@@ -13,6 +14,7 @@ Add license_finder to your project's Gemfile and `bundle`:
13
14
  gem 'license_finder'
14
15
  ```
15
16
 
17
+
16
18
  ## Usage
17
19
 
18
20
  License finder will generate reports of action items - i.e., dependencies that do not fall within your license "whitelist".
@@ -21,26 +23,12 @@ License finder will generate reports of action items - i.e., dependencies that d
21
23
  $ license_finder
22
24
  ```
23
25
 
24
- The first time you run this, `license_finder` will create a default configuration file `./config/license_finder.yml`:
25
-
26
-
27
- ```yaml
28
- ---
29
- whitelist:
30
- #- MIT
31
- #- Apache 2.0
32
- ignore_groups:
33
- #- test
34
- #- development
35
- dependencies_file_dir: './doc/'
36
- ```
37
-
38
- This allows you to configure bundler groups and add licenses to the whitelist.
26
+ (Note) If you wish to run license_finder without the progress spinner use the -q or --quiet option.
39
27
 
40
28
  On a brand new Rails project, you could expect `license_finder` to output something like the following
41
- (assuming you whitelisted the MIT license in your `config/license_finder.yml`):
29
+ (assuming you whitelisted the MIT license -- see [Configuration](#configuration)):
42
30
 
43
- ```
31
+ ```yaml
44
32
  Dependencies that need approval:
45
33
 
46
34
  highline, 1.6.14, ruby
@@ -52,7 +40,8 @@ rubyzip, 0.9.9, ruby
52
40
  xml-simple, 1.1.1, other
53
41
  ```
54
42
 
55
- The executable task will also write out a dependencies.db, dependencies.txt, and dependencies.html file in the doc/ directory (by default).
43
+ The executable task will also write out a dependencies.db, dependencies.txt, and dependencies.html file in the doc/
44
+ directory (by default -- see [Configuration](#configuration)).
56
45
 
57
46
  The latter two files are human readable reports that you could send to your non-technical business partners, lawyers, etc.
58
47
 
@@ -60,12 +49,15 @@ The latter two files are human readable reports that you could send to your non-
60
49
  unapproved dependencies. You could use this in a CI build, for example, to alert you whenever someone adds an
61
50
  unapproved dependency to the project.
62
51
 
63
- ### Manually recording licenses
52
+ Run `license_finder help` to see other available commands.
53
+
54
+ ### Manually setting licenses
64
55
 
65
- When you have dependencies marked as having an 'other' license, `license_finder` you should manually research what the actual license is. Once this has been established, you can record this information with the `-l` or `--license` option as such:
56
+ When `license_finder` reports that a dependency's license is 'other', you should manually research what the actual
57
+ license is. When you have established the real license, you can record it with:
66
58
 
67
59
  ```sh
68
- $ license_finder -l MIT my_unknown_dependency
60
+ $ license_finder license MIT my_unknown_dependency
69
61
  ```
70
62
 
71
63
  This command would assign the MIT license to the dependency `my_unknown_dependency`.
@@ -73,8 +65,8 @@ This command would assign the MIT license to the dependency `my_unknown_dependen
73
65
  ### Manually approving dependencies
74
66
 
75
67
  Whenever you have a dependency that falls outside of your whitelist, `license_finder` will tell you.
76
- If your business decides that this is an acceptable risk, you can manually approve the dependency by using the `-a` or
77
- `--approve` option of the `license_finder` command.
68
+ If your business decides that this is an acceptable risk, you can manually approve the dependency by using the
69
+ `license_finder approve` command.
78
70
 
79
71
  For example, lets assume you've only
80
72
  whitelisted the "MIT" license in your `config/license_finder.yml`. You then add the `awesome_gpl_gem` to your Gemfile,
@@ -88,25 +80,95 @@ awesome_gpl_gem, 1.0.0, GPL
88
80
  Your business tells you that in this case, it's acceptable to use this gem. You now run:
89
81
 
90
82
  ```sh
91
- $ license_finder -a awesome_gpl_gem
83
+ $ license_finder approve awesome_gpl_gem
92
84
  ```
93
85
 
94
86
  If you rerun `license_finder`, you should no longer see `awesome_gpl_gem` in the output.
95
87
 
88
+ ### Managing ignored Bundler groups
89
+
90
+ Bundler groups can be added to an ignore list which will prevent LicenseFinder from evaluating their licenses.
91
+ These groups can be managed with the `ignored_bundler_groups` command.
92
+
93
+ To list currently ignored Bundler groups:
94
+
95
+ ```sh
96
+ $ license_finder ignored_bundler_groups list
97
+ ```
98
+
99
+ To add a group to the ignored Bundler groups:
100
+
101
+ ```sh
102
+ $ license_finder ignored_bundler_groups add development
103
+ ```
104
+
105
+ To remove a group from the ignored Bundler groups:
106
+
107
+ ```sh
108
+ $ license_finder ignored_bundler_groups remove development
109
+ ```
110
+
111
+ ### Managing non-Bundler dependencies
112
+
113
+ license_finder can track dependencies that Bundler doesn't know about (JS libraries that don't
114
+ appear in your Gemfile, etc.)
115
+
116
+ ```sh
117
+ $ license_finder dependencies add MIT my_js_dep 0.1.2
118
+ ```
119
+
120
+ To automatically approve a non-bundler dependency when you add it, use:
121
+
122
+ ```sh
123
+ $ license_finder dependencies add MIT my_js_dep 0.1.2 --approve
124
+ ```
125
+
126
+ The version is optional. Run `license_finder dependencies help` for additional documentation about
127
+ managing non-Bundler dependencies.
128
+
129
+ license_finder cannot automatically detect when a non-Bundler dependency has been removed from your
130
+ project, so you can use:
131
+
132
+ ```sh
133
+ $ license_finder dependencies remove my_js_dep
134
+ ```
135
+
136
+ ## Configuration
137
+
138
+ The first time you run `license_finder` it will create a default configuration file `./config/license_finder.yml`:
139
+
140
+ ```yaml
141
+ ---
142
+ whitelist:
143
+ #- MIT
144
+ #- Apache 2.0
145
+ ignore_groups:
146
+ #- test
147
+ #- development
148
+ dependencies_file_dir: './doc/'
149
+ ```
150
+
151
+ By modifying this file, you can configure license_finder's behavior. `Whitelisted` licenses will be automatically approved
152
+ and `ignore_groups` will limit which dependencies are included in your license report. You can store the license database
153
+ and text files in another directory by changing `dependencies_file_dir`.
154
+
155
+
96
156
  ## Upgrade for pre 0.8.0 users
97
157
 
98
158
  If you wish to cleanup your root directory you can run:
99
159
 
100
160
  ```sh
101
- $ license_finder -m
161
+ $ license_finder move
102
162
  ```
103
163
 
104
164
  This will move your dependencies.* files to the /doc directory and update the config.
105
165
 
166
+
106
167
  ## Compatibility
107
168
 
108
169
  license_finder is compatible with ruby 1.9, and ruby 2.0. There is also experimental support for jruby.
109
170
 
171
+
110
172
  ## A note to gem authors / maintainers
111
173
 
112
174
  For the good of humanity, please add a license to your gemspec!
@@ -120,6 +182,21 @@ end
120
182
 
121
183
  And add a `LICENSE` file to your gem that contains your license text.
122
184
 
185
+
186
+ ## Support
187
+
188
+ * Send an email to the list: [license-finder@googlegroups.com](license-finder@googlegroups.com)
189
+ * View the project backlog at Pivotal Tracker: [https://www.pivotaltracker.com/s/projects/234851](https://www.pivotaltracker.com/s/projects/234851)
190
+
191
+
192
+ ## Contributing
193
+
194
+ * Fork the project
195
+ * Create a feature branch
196
+ * Make your feature addition or bug fix (with tests)
197
+ * Rebase on top of master
198
+ * Send a pull request
199
+
123
200
  ## License
124
201
 
125
202
  LicenseFinder is released under the MIT License. http://www.opensource.org/licenses/mit-license