license_finder 0.8.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +15 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/Rakefile +21 -0
- data/bin/license_finder +54 -0
- data/db/migrate/201303290935_create_dependencies.rb +14 -0
- data/db/migrate/201303291155_create_licenses.rb +13 -0
- data/db/migrate/201303291402_create_approvals.rb +13 -0
- data/db/migrate/201303291456_create_ancestries.rb +9 -0
- data/db/migrate/201303291519_create_bundler_groups.rb +13 -0
- data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +11 -0
- data/db/migrate/201303291753_allow_null_license_names.rb +7 -0
- data/db/migrate/201304011027_allow_null_dependency_version.rb +7 -0
- data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +5 -0
- data/features/approve_dependencies.feature +14 -0
- data/features/html_report.feature +38 -0
- data/features/ignore_bundle_groups.feature +11 -0
- data/features/license_finder.feature +47 -0
- data/features/license_finder_rake_task.feature +37 -0
- data/features/rails_rake.feature +9 -0
- data/features/set_license.feature +12 -0
- data/features/step_definitions/license_finder_steps.rb +25 -0
- data/features/step_definitions/steps.rb +376 -0
- data/features/text_report.feature +27 -0
- data/features/whitelist.feature +24 -0
- data/files/license_finder.yml +8 -0
- data/lib/data/licenses/Apache2.txt +172 -0
- data/lib/data/licenses/BSD.txt +24 -0
- data/lib/data/licenses/GPLv2.txt +339 -0
- data/lib/data/licenses/ISC.txt +2 -0
- data/lib/data/licenses/LGPL.txt +165 -0
- data/lib/data/licenses/MIT.txt +9 -0
- data/lib/data/licenses/NewBSD.txt +21 -0
- data/lib/data/licenses/Ruby.txt +52 -0
- data/lib/data/licenses/SimplifiedBSD.txt +23 -0
- data/lib/license_finder.rb +47 -0
- data/lib/license_finder/bundle.rb +48 -0
- data/lib/license_finder/bundle_syncer.rb +11 -0
- data/lib/license_finder/bundled_gem.rb +48 -0
- data/lib/license_finder/cli.rb +49 -0
- data/lib/license_finder/configuration.rb +71 -0
- data/lib/license_finder/dependency_report.rb +30 -0
- data/lib/license_finder/gem_saver.rb +69 -0
- data/lib/license_finder/html_report.rb +14 -0
- data/lib/license_finder/license.rb +90 -0
- data/lib/license_finder/license/apache2.rb +8 -0
- data/lib/license_finder/license/bsd.rb +4 -0
- data/lib/license_finder/license/gplv2.rb +4 -0
- data/lib/license_finder/license/isc.rb +3 -0
- data/lib/license_finder/license/lgpl.rb +3 -0
- data/lib/license_finder/license/mit.rb +23 -0
- data/lib/license_finder/license/new_bsd.rb +8 -0
- data/lib/license_finder/license/ruby.rb +11 -0
- data/lib/license_finder/license/simplified_bsd.rb +8 -0
- data/lib/license_finder/license_files.rb +36 -0
- data/lib/license_finder/license_url.rb +12 -0
- data/lib/license_finder/platform.rb +32 -0
- data/lib/license_finder/possible_license_file.rb +32 -0
- data/lib/license_finder/railtie.rb +7 -0
- data/lib/license_finder/reporter.rb +20 -0
- data/lib/license_finder/tables.rb +7 -0
- data/lib/license_finder/tables/approval.rb +4 -0
- data/lib/license_finder/tables/bundler_group.rb +4 -0
- data/lib/license_finder/tables/dependency.rb +31 -0
- data/lib/license_finder/tables/license_alias.rb +22 -0
- data/lib/license_finder/text_report.rb +9 -0
- data/lib/license_finder/yml_to_sql.rb +127 -0
- data/lib/tasks/license_finder.rake +7 -0
- data/lib/templates/html_report.erb +111 -0
- data/lib/templates/text_report.erb +3 -0
- data/license_finder.gemspec +36 -0
- data/readme.md +115 -0
- data/spec/fixtures/APACHE-2-LICENSE +202 -0
- data/spec/fixtures/GPLv2 +339 -0
- data/spec/fixtures/ISC-LICENSE +10 -0
- data/spec/fixtures/MIT-LICENSE +22 -0
- data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +22 -0
- data/spec/fixtures/README-with-MIT-LICENSE +222 -0
- data/spec/fixtures/license_directory/COPYING +0 -0
- data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +25 -0
- data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +339 -0
- data/spec/fixtures/license_directory/LICENSE/LICENSE +191 -0
- data/spec/fixtures/license_directory/LICENSE/MIT.txt +21 -0
- data/spec/fixtures/license_directory/LICENSE/RUBY.txt +60 -0
- data/spec/fixtures/license_names/COPYING.txt +0 -0
- data/spec/fixtures/license_names/LICENSE +0 -0
- data/spec/fixtures/license_names/Licence.rdoc +0 -0
- data/spec/fixtures/license_names/Mit-License +0 -0
- data/spec/fixtures/license_names/README.rdoc +0 -0
- data/spec/fixtures/mit_licensed_gem/LICENSE +22 -0
- data/spec/fixtures/nested_gem/vendor/LICENSE +0 -0
- data/spec/fixtures/nested_readme/vendor/README +0 -0
- data/spec/fixtures/other_licensed_gem/LICENSE +3 -0
- data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
- data/spec/fixtures/readme/README +0 -0
- data/spec/fixtures/readme/Readme.markdown +0 -0
- data/spec/fixtures/utf8_gem/README +210 -0
- data/spec/lib/license_finder/bundle_spec.rb +61 -0
- data/spec/lib/license_finder/bundle_syncer_spec.rb +16 -0
- data/spec/lib/license_finder/bundled_gem_spec.rb +62 -0
- data/spec/lib/license_finder/cli_spec.rb +38 -0
- data/spec/lib/license_finder/configuration_spec.rb +70 -0
- data/spec/lib/license_finder/gem_saver_spec.rb +155 -0
- data/spec/lib/license_finder/html_report_spec.rb +84 -0
- data/spec/lib/license_finder/license/apache_spec.rb +7 -0
- data/spec/lib/license_finder/license/bsd_spec.rb +41 -0
- data/spec/lib/license_finder/license/gplv2_spec.rb +7 -0
- data/spec/lib/license_finder/license/isc_spec.rb +7 -0
- data/spec/lib/license_finder/license/lgpl_spec.rb +7 -0
- data/spec/lib/license_finder/license/mit_spec.rb +33 -0
- data/spec/lib/license_finder/license/new_bsd_spec.rb +35 -0
- data/spec/lib/license_finder/license/ruby_spec.rb +19 -0
- data/spec/lib/license_finder/license/simplified_bsd_spec.rb +7 -0
- data/spec/lib/license_finder/license_files_spec.rb +50 -0
- data/spec/lib/license_finder/license_spec.rb +45 -0
- data/spec/lib/license_finder/license_url_spec.rb +20 -0
- data/spec/lib/license_finder/possible_license_file_spec.rb +37 -0
- data/spec/lib/license_finder/reporter_spec.rb +4 -0
- data/spec/lib/license_finder/tables/dependency_spec.rb +102 -0
- data/spec/lib/license_finder/tables/license_alias_spec.rb +54 -0
- data/spec/lib/license_finder/text_report_spec.rb +31 -0
- data/spec/lib/license_finder/yml_to_sql_spec.rb +99 -0
- data/spec/lib/license_finder_spec.rb +82 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/license_examples.rb +30 -0
- metadata +435 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
2
|
+
of this software and associated documentation files (the "Software"), to deal
|
3
|
+
in the Software without restriction, including without limitation the rights
|
4
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
5
|
+
copies of the Software, and to permit persons to whom the Software is
|
6
|
+
furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in
|
9
|
+
all copies or substantial portions of the Software.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without
|
2
|
+
modification, are permitted provided that the following conditions are met:
|
3
|
+
* Redistributions of source code must retain the above copyright
|
4
|
+
notice, this list of conditions and the following disclaimer.
|
5
|
+
* Redistributions in binary form must reproduce the above copyright
|
6
|
+
notice, this list of conditions and the following disclaimer in the
|
7
|
+
documentation and/or other materials provided with the distribution.
|
8
|
+
* Neither the name of <organization> nor the
|
9
|
+
names of its contributors may be used to endorse or promote products
|
10
|
+
derived from this software without specific prior written permission.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
14
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
15
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
16
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
17
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
18
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
19
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
20
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
21
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
1. You may make and give away verbatim copies of the source form of the
|
2
|
+
software without restriction, provided that you duplicate all of the
|
3
|
+
original copyright notices and associated disclaimers.
|
4
|
+
|
5
|
+
2. You may modify your copy of the software in any way, provided that
|
6
|
+
you do at least ONE of the following:
|
7
|
+
|
8
|
+
a) place your modifications in the Public Domain or otherwise
|
9
|
+
make them Freely Available, such as by posting said
|
10
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
11
|
+
the author to include your modifications in the software.
|
12
|
+
|
13
|
+
b) use the modified software only within your corporation or
|
14
|
+
organization.
|
15
|
+
|
16
|
+
c) give non-standard binaries non-standard names, with
|
17
|
+
instructions on where to get the original software distribution.
|
18
|
+
|
19
|
+
d) make other distribution arrangements with the author.
|
20
|
+
|
21
|
+
3. You may distribute the software in object code or binary form,
|
22
|
+
provided that you do at least ONE of the following:
|
23
|
+
|
24
|
+
a) distribute the binaries and library files of the software,
|
25
|
+
together with instructions (in the manual page or equivalent)
|
26
|
+
on where to get the original distribution.
|
27
|
+
|
28
|
+
b) accompany the distribution with the machine-readable source of
|
29
|
+
the software.
|
30
|
+
|
31
|
+
c) give non-standard binaries non-standard names, with
|
32
|
+
instructions on where to get the original software distribution.
|
33
|
+
|
34
|
+
d) make other distribution arrangements with the author.
|
35
|
+
|
36
|
+
4. You may modify and include the part of the software into any other
|
37
|
+
software (possibly commercial). But some files in the distribution
|
38
|
+
are not written by the author, so that they are not under these terms.
|
39
|
+
|
40
|
+
For the list of those files and their copying conditions, see the
|
41
|
+
file LEGAL.
|
42
|
+
|
43
|
+
5. The scripts and library files supplied as input to or produced as
|
44
|
+
output from the software do not automatically fall under the
|
45
|
+
copyright of the software, but belong to whomever generated them,
|
46
|
+
and may be sold commercially, and may be aggregated with this
|
47
|
+
software.
|
48
|
+
|
49
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
50
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
51
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
52
|
+
PURPOSE.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without
|
2
|
+
modification, are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
5
|
+
list of conditions and the following disclaimer.
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
8
|
+
and/or other materials provided with the distribution.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
11
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
12
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
13
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
14
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
15
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
16
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
17
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
18
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
19
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
20
|
+
|
21
|
+
The views and conclusions contained in the software and documentation are those
|
22
|
+
of the authors and should not be interpreted as representing official policies,
|
23
|
+
either expressed or implied, of the FreeBSD Project.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module LicenseFinder
|
6
|
+
ROOT_PATH = Pathname.new(__FILE__).dirname
|
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'
|
30
|
+
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'
|
34
|
+
|
35
|
+
def self.config
|
36
|
+
@config ||= Configuration.ensure_default
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load_rake_tasks
|
40
|
+
load 'tasks/license_finder.rake'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'license_finder/railtie' if defined?(Rails)
|
45
|
+
require 'license_finder/tables'
|
46
|
+
|
47
|
+
LicenseFinder::YmlToSql.convert_if_required
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class Bundle
|
3
|
+
attr_writer :ignore_groups
|
4
|
+
|
5
|
+
def self.current_gem_dependencies(bundler_definition=nil)
|
6
|
+
new(bundler_definition).gems.map(&:save_or_merge)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(bundler_definition=nil)
|
10
|
+
@definition = bundler_definition || Bundler::Definition.build(gemfile_path, lockfile_path, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def gems
|
14
|
+
return @gems if @gems
|
15
|
+
|
16
|
+
@gems ||= definition.specs_for(included_groups).map do |spec|
|
17
|
+
dependency = dependencies.detect { |dep| dep.name == spec.name }
|
18
|
+
|
19
|
+
BundledGem.new(spec, dependency)
|
20
|
+
end
|
21
|
+
|
22
|
+
@gems
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
attr_reader :definition
|
27
|
+
|
28
|
+
def ignore_groups
|
29
|
+
@ignore_groups ||= LicenseFinder.config.ignore_groups
|
30
|
+
end
|
31
|
+
|
32
|
+
def dependencies
|
33
|
+
@dependencies ||= definition.dependencies
|
34
|
+
end
|
35
|
+
|
36
|
+
def included_groups
|
37
|
+
definition.groups - ignore_groups
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile_path
|
41
|
+
Pathname.new("Gemfile").expand_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def lockfile_path
|
45
|
+
gemfile_path.dirname.join('Gemfile.lock')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class BundledGem
|
3
|
+
attr_reader :parents, :spec, :bundler_dependency
|
4
|
+
|
5
|
+
def initialize(spec, bundler_dependency = nil)
|
6
|
+
@spec = spec
|
7
|
+
@bundler_dependency = bundler_dependency
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
"#{dependency_name} #{dependency_version}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def parents
|
15
|
+
@parents ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def dependency_name
|
19
|
+
@spec.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def dependency_version
|
23
|
+
@spec.version.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def children
|
27
|
+
@children ||= @spec.dependencies.collect(&:name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def determine_license
|
31
|
+
return @spec.license if @spec.license
|
32
|
+
|
33
|
+
license_files.map(&:license).compact.first || 'other'
|
34
|
+
end
|
35
|
+
|
36
|
+
def license_files
|
37
|
+
LicenseFiles.new(@spec.full_gem_path).files
|
38
|
+
end
|
39
|
+
|
40
|
+
def sort_order
|
41
|
+
dependency_name.downcase
|
42
|
+
end
|
43
|
+
|
44
|
+
def save_or_merge
|
45
|
+
GemSaver.find_or_initialize_by_name(@spec.name, self).save
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
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
|
11
|
+
|
12
|
+
unapproved = Dependency.unapproved
|
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)
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
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
|
32
|
+
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"
|
38
|
+
end
|
39
|
+
|
40
|
+
generate_reports
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def generate_reports
|
46
|
+
Reporter.write_reports
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :whitelist, :ignore_groups, :dependencies_dir
|
4
|
+
|
5
|
+
def self.config_file_path
|
6
|
+
File.join('.', 'config', 'license_finder.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.ensure_default
|
10
|
+
make_config_file unless File.exists?(config_file_path)
|
11
|
+
new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.make_config_file
|
15
|
+
FileUtils.mkdir_p(File.join('.', 'config'))
|
16
|
+
FileUtils.cp(
|
17
|
+
File.join(File.dirname(__FILE__), '..', '..', 'files', 'license_finder.yml'),
|
18
|
+
config_file_path
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(config={})
|
23
|
+
if File.exists?(config_file_path)
|
24
|
+
yaml = File.read(config_file_path)
|
25
|
+
config = YAML.load(yaml).merge config
|
26
|
+
end
|
27
|
+
|
28
|
+
@whitelist = config['whitelist'] || []
|
29
|
+
@ignore_groups = (config["ignore_groups"] || []).map(&:to_sym)
|
30
|
+
@dependencies_dir = config['dependencies_file_dir'] || './doc/'
|
31
|
+
FileUtils.mkdir_p(@dependencies_dir)
|
32
|
+
end
|
33
|
+
|
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"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def dependencies_yaml
|
43
|
+
File.join(dependencies_dir, "dependencies.yml")
|
44
|
+
end
|
45
|
+
|
46
|
+
def dependencies_text
|
47
|
+
File.join(dependencies_dir, "dependencies.txt")
|
48
|
+
end
|
49
|
+
|
50
|
+
def dependencies_html
|
51
|
+
File.join(dependencies_dir, "dependencies.html")
|
52
|
+
end
|
53
|
+
|
54
|
+
def ignore_groups
|
55
|
+
@ignore_groups.map &:to_sym
|
56
|
+
end
|
57
|
+
|
58
|
+
def whitelisted?(license_name)
|
59
|
+
license = License.find_by_name(license_name) || license_name
|
60
|
+
whitelisted_licenses.include? license
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def whitelisted_licenses
|
66
|
+
whitelist.map do |license_name|
|
67
|
+
License.find_by_name(license_name) || license_name
|
68
|
+
end.compact
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class DependencyReport
|
3
|
+
def self.underscored_name
|
4
|
+
@underscored_name ||= begin
|
5
|
+
str = name.dup
|
6
|
+
str.sub!(/.*::/, '')
|
7
|
+
str.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
8
|
+
str.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
9
|
+
str.downcase!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(dependencies=[])
|
14
|
+
@dependencies = Array dependencies
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
filename = File.join(File.dirname(__FILE__), '..', 'templates', "#{self.class.underscored_name}.erb")
|
19
|
+
template = ERB.new(File.read(filename), 0, '-')
|
20
|
+
template.result(binding)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
attr_reader :dependencies
|
25
|
+
|
26
|
+
def sorted_dependencies
|
27
|
+
dependencies.sort_by(&:name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class GemSaver
|
3
|
+
extend Forwardable
|
4
|
+
def_delegators :spec, :name, :version, :summary, :description, :homepage
|
5
|
+
def_delegators :bundled_gem, :bundler_dependency, :determine_license, :children
|
6
|
+
|
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
|
11
|
+
new(dependency, bundled_gem)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(dependency, bundled_gem)
|
15
|
+
@bundled_gem = bundled_gem
|
16
|
+
@dependency = dependency
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
DB.transaction do
|
21
|
+
apply_dependency_definition
|
22
|
+
refresh_bundler_groups
|
23
|
+
refresh_children
|
24
|
+
apply_better_license
|
25
|
+
end
|
26
|
+
dependency
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :dependency, :bundled_gem
|
32
|
+
|
33
|
+
def spec
|
34
|
+
bundled_gem.spec
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply_dependency_definition
|
38
|
+
dependency.version = version.to_s
|
39
|
+
dependency.summary = summary
|
40
|
+
dependency.description = description
|
41
|
+
dependency.homepage = homepage
|
42
|
+
dependency.license ||= LicenseAlias.create(name: determine_license)
|
43
|
+
dependency.save
|
44
|
+
end
|
45
|
+
|
46
|
+
def refresh_bundler_groups
|
47
|
+
dependency.remove_all_bundler_groups
|
48
|
+
if bundler_dependency
|
49
|
+
bundler_dependency.groups.each { |group|
|
50
|
+
dependency.add_bundler_group BundlerGroup.find_or_create(name: group.to_s)
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def refresh_children
|
56
|
+
dependency.remove_all_children
|
57
|
+
children.each do |child|
|
58
|
+
dependency.add_child Dependency.find_or_create(name: child.to_s)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def apply_better_license
|
63
|
+
if dependency.license && !dependency.license.manual && determine_license != 'other'
|
64
|
+
dependency.license.name = determine_license
|
65
|
+
dependency.license.save
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|