license_finder 0.9.4-java → 0.9.5-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -7
- data/.travis.yml +1 -3
- data/CHANGELOG.rdoc +13 -0
- data/db/migrate/201307251004_data_fix_manual_licenses.rb +2 -2
- data/db/migrate/201307251107_reassociate_license.rb +18 -18
- data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +7 -0
- data/db/migrate/201311192003_reassociate_manual_approval.rb +14 -0
- data/db/migrate/201311192010_drop_approvals.rb +5 -0
- data/features/cli.feature +1 -1
- data/features/html_report.feature +1 -1
- data/features/{non_bundler_dependencies.feature → manually_managed_dependencies.feature} +6 -6
- data/features/step_definitions/html_report_steps.rb +2 -9
- data/features/step_definitions/{non_bundler_steps.rb → manually_managed_steps.rb} +0 -0
- data/features/step_definitions/shared_steps.rb +4 -8
- data/lib/license_finder.rb +21 -17
- data/lib/license_finder/bower.rb +3 -34
- data/lib/license_finder/bower_package.rb +63 -0
- data/lib/license_finder/bundler.rb +73 -0
- data/lib/license_finder/bundler_package.rb +33 -0
- data/lib/license_finder/cli.rb +33 -35
- data/lib/license_finder/dependency_manager.rb +14 -23
- data/lib/license_finder/license/apache2.rb +1 -1
- data/lib/license_finder/license/lgpl.rb +1 -0
- data/lib/license_finder/npm.rb +22 -39
- data/lib/license_finder/npm_package.rb +61 -0
- data/lib/license_finder/package.rb +14 -80
- data/lib/license_finder/package_saver.rb +13 -75
- data/lib/license_finder/pip.rb +21 -33
- data/lib/license_finder/pip_package.rb +51 -0
- data/lib/license_finder/platform.rb +3 -15
- data/lib/license_finder/possible_license_file.rb +0 -4
- data/lib/license_finder/possible_license_files.rb +4 -0
- data/lib/license_finder/tables.rb +2 -2
- data/lib/license_finder/tables/bundler_group.rb +3 -0
- data/lib/license_finder/tables/dependency.rb +43 -18
- data/lib/license_finder/tables/license_alias.rb +4 -0
- data/lib/license_finder/yml_to_sql.rb +22 -30
- data/license_finder.gemspec +3 -3
- data/readme.md +5 -5
- data/spec/lib/license_finder/bower_package_spec.rb +56 -0
- data/spec/lib/license_finder/bower_spec.rb +3 -24
- data/spec/lib/license_finder/bundler_package_spec.rb +62 -0
- data/spec/lib/license_finder/{bundle_spec.rb → bundler_spec.rb} +7 -7
- data/spec/lib/license_finder/cli_spec.rb +6 -6
- data/spec/lib/license_finder/dependency_manager_spec.rb +14 -15
- data/spec/lib/license_finder/html_report_spec.rb +2 -3
- data/spec/lib/license_finder/markdown_report_spec.rb +4 -4
- data/spec/lib/license_finder/npm_package_spec.rb +51 -0
- data/spec/lib/license_finder/npm_spec.rb +25 -25
- data/spec/lib/license_finder/package_saver_spec.rb +50 -190
- data/spec/lib/license_finder/pip_package_spec.rb +74 -0
- data/spec/lib/license_finder/pip_spec.rb +33 -55
- data/spec/lib/license_finder/tables/dependency_spec.rb +83 -32
- data/spec/lib/license_finder/yml_to_sql_spec.rb +5 -12
- data/spec/spec_helper.rb +22 -2
- metadata +30 -18
- data/lib/license_finder/bundle.rb +0 -74
- data/lib/license_finder/tables/approval.rb +0 -4
- data/spec/lib/license_finder/package_spec.rb +0 -98
@@ -3,19 +3,13 @@ require 'forwardable'
|
|
3
3
|
module LicenseFinder
|
4
4
|
class PackageSaver
|
5
5
|
extend Forwardable
|
6
|
-
def_delegators :
|
7
|
-
def_delegators :package, :bundler_dependency, :license, :children, :groups, :summary, :description
|
6
|
+
def_delegators :package, :license, :children, :groups, :summary, :description, :version, :homepage
|
8
7
|
|
9
8
|
attr_reader :dependency, :package
|
10
9
|
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.save_packages(current_packages)
|
17
|
-
current_packages.map do |package|
|
18
|
-
PackageSaver.find_or_create_by_name(package).save
|
10
|
+
def self.save_all(packages)
|
11
|
+
packages.map do |package|
|
12
|
+
find_or_create_by_name(package).save
|
19
13
|
end
|
20
14
|
end
|
21
15
|
|
@@ -26,79 +20,23 @@ module LicenseFinder
|
|
26
20
|
|
27
21
|
def save
|
28
22
|
DB.transaction do
|
29
|
-
apply_dependency_definition
|
30
|
-
sync_bundler_groups
|
31
|
-
sync_children
|
32
|
-
apply_better_license
|
33
|
-
end
|
34
|
-
dependency
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def spec
|
40
|
-
package.spec
|
41
|
-
end
|
42
|
-
|
43
|
-
def apply_dependency_definition
|
44
|
-
if values_have_changed?
|
45
23
|
dependency.version = version.to_s
|
46
24
|
dependency.summary = summary
|
47
25
|
dependency.description = description
|
48
26
|
dependency.homepage = homepage
|
49
|
-
dependency.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def values_have_changed?
|
54
|
-
return dependency.version != version.to_s ||
|
55
|
-
dependency.summary != summary ||
|
56
|
-
dependency.description != description ||
|
57
|
-
dependency.homepage != homepage
|
58
|
-
end
|
59
|
-
|
60
|
-
def sync_bundler_groups
|
61
|
-
existing_groups = dependency.bundler_groups
|
62
|
-
new_groups = groups.map(&:to_s)
|
63
|
-
|
64
|
-
existing_groups.reverse.each do |group|
|
65
|
-
unless new_groups.include?(group.name)
|
66
|
-
dependency.remove_bundler_group(group)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
new_groups.each do |group|
|
71
|
-
unless existing_groups.map(&:name).include? group
|
72
|
-
dependency.add_bundler_group BundlerGroup.find_or_create(name: group)
|
73
|
-
end
|
27
|
+
dependency.bundler_group_names = groups.map(&:to_s)
|
28
|
+
dependency.children_names = children
|
29
|
+
dependency.apply_better_license license
|
30
|
+
dependency.save_changes
|
74
31
|
end
|
32
|
+
dependency
|
75
33
|
end
|
76
34
|
|
77
|
-
|
78
|
-
existing_children = dependency.children
|
79
|
-
new_children = children
|
80
|
-
|
81
|
-
existing_children.reverse.each do |child|
|
82
|
-
unless new_children.include?(child.name)
|
83
|
-
dependency.remove_child(child)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
new_children.each do |child|
|
88
|
-
unless existing_children.map(&:name).include?(child)
|
89
|
-
dependency.add_child Dependency.named(child)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
35
|
+
private
|
93
36
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
if dependency.license.nil? || bundled_license != dependency.license.name
|
98
|
-
dependency.license = LicenseAlias.find_or_create(name: bundled_license)
|
99
|
-
dependency.save
|
100
|
-
end
|
101
|
-
end
|
37
|
+
def self.find_or_create_by_name(package)
|
38
|
+
dependency = Dependency.named(package.name)
|
39
|
+
new(dependency, package)
|
102
40
|
end
|
103
41
|
end
|
104
42
|
end
|
data/lib/license_finder/pip.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'httparty'
|
3
|
-
require 'license_finder/package'
|
4
3
|
|
5
4
|
module LicenseFinder
|
6
5
|
class Pip
|
7
|
-
GET_DEPENDENCIES_PY = <<-PYTHON
|
6
|
+
GET_DEPENDENCIES_PY = <<-PYTHON.gsub(/\n+/, ";")
|
8
7
|
from pip.util import get_installed_distributions
|
9
8
|
|
10
9
|
dists = [(x.project_name, x.version, x.location) for x in get_installed_distributions()]
|
@@ -13,47 +12,36 @@ dists = ["[\\\"{0}\\\", \\\"{1}\\\", \\\"{2}\\\"]".format(*dist) for dist in dis
|
|
13
12
|
print "[" + ",".join(dists) + "]"
|
14
13
|
PYTHON
|
15
14
|
|
16
|
-
def self.
|
17
|
-
|
15
|
+
def self.current_packages
|
16
|
+
output = `python -c '#{GET_DEPENDENCIES_PY}'`
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
:version => dist_ary[1],
|
27
|
-
:full_gem_path => File.join(dist_ary[2], dist_ary[0]),
|
28
|
-
:python? => true
|
29
|
-
))
|
18
|
+
JSON(output).map do |(name, version, install_dir)|
|
19
|
+
PipPackage.new(
|
20
|
+
name,
|
21
|
+
version,
|
22
|
+
File.join(install_dir, name),
|
23
|
+
pypi_def(name, version)
|
24
|
+
)
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
33
|
-
def self.
|
28
|
+
def self.active?
|
34
29
|
File.exists?(requirements_path)
|
35
30
|
end
|
36
31
|
|
37
|
-
def self.license_for(package)
|
38
|
-
info = package.json
|
39
|
-
license = info.fetch("license", "UNKNOWN")
|
40
|
-
|
41
|
-
if license == "UNKNOWN"
|
42
|
-
classifiers = info.fetch("classifiers", [])
|
43
|
-
license = classifiers.map do |c|
|
44
|
-
if c.start_with?("License")
|
45
|
-
c.gsub(/^License.*::\s*(.*)$/, '\1')
|
46
|
-
end
|
47
|
-
end.compact.first
|
48
|
-
end
|
49
|
-
|
50
|
-
license || "other"
|
51
|
-
end
|
52
|
-
|
53
32
|
private
|
54
33
|
|
55
34
|
def self.requirements_path
|
56
35
|
Pathname.new('requirements.txt').expand_path
|
57
36
|
end
|
37
|
+
|
38
|
+
def self.pypi_def(name, version)
|
39
|
+
response = HTTParty.get("https://pypi.python.org/pypi/#{name}/#{version}/json")
|
40
|
+
if response.code == 200
|
41
|
+
JSON.parse(response.body).fetch("info", {})
|
42
|
+
else
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
end
|
58
46
|
end
|
59
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class PipPackage < Package
|
3
|
+
def initialize(name, version, install_path, pypi_def)
|
4
|
+
@name = name
|
5
|
+
@version = version
|
6
|
+
@install_path = install_path
|
7
|
+
@pypi_def = pypi_def
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :name, :version
|
11
|
+
|
12
|
+
def summary
|
13
|
+
pypi_def.fetch("summary", "")
|
14
|
+
end
|
15
|
+
|
16
|
+
def description
|
17
|
+
pypi_def.fetch("description", "")
|
18
|
+
end
|
19
|
+
|
20
|
+
def children
|
21
|
+
[] # no way to determine child deps from pip (maybe?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def groups
|
25
|
+
[] # no concept of dev/test groups in pip (maybe?)
|
26
|
+
end
|
27
|
+
|
28
|
+
def homepage
|
29
|
+
nil # no way to extract homepage from pip (maybe?)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :install_path, :pypi_def
|
35
|
+
|
36
|
+
def license_from_spec
|
37
|
+
license = pypi_def.fetch("license", "UNKNOWN")
|
38
|
+
|
39
|
+
if license == "UNKNOWN"
|
40
|
+
classifiers = pypi_def.fetch("classifiers", [])
|
41
|
+
license = classifiers.map do |c|
|
42
|
+
if c.start_with?("License")
|
43
|
+
c.gsub(/^License.*::\s*(.*)$/, '\1')
|
44
|
+
end
|
45
|
+
end.compact.first
|
46
|
+
end
|
47
|
+
|
48
|
+
license
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,27 +1,15 @@
|
|
1
1
|
module LicenseFinder
|
2
2
|
module Platform
|
3
3
|
def self.sqlite_adapter
|
4
|
-
|
5
|
-
'jdbc:sqlite'
|
6
|
-
else
|
7
|
-
'sqlite'
|
8
|
-
end
|
4
|
+
java? ? 'jdbc:sqlite' : 'sqlite'
|
9
5
|
end
|
10
6
|
|
11
7
|
def self.sqlite_gem
|
12
|
-
|
13
|
-
'jdbc-sqlite3'
|
14
|
-
else
|
15
|
-
'sqlite3'
|
16
|
-
end
|
8
|
+
java? ? 'jdbc-sqlite3' : 'sqlite3'
|
17
9
|
end
|
18
10
|
|
19
11
|
def self.sqlite_load_path
|
20
|
-
|
21
|
-
'jdbc/sqlite3'
|
22
|
-
else
|
23
|
-
'sqlite3'
|
24
|
-
end
|
12
|
+
java? ? 'jdbc/sqlite3' : 'sqlite3'
|
25
13
|
end
|
26
14
|
|
27
15
|
def self.java?
|
@@ -2,6 +2,10 @@ module LicenseFinder
|
|
2
2
|
class PossibleLicenseFiles
|
3
3
|
LICENSE_FILE_NAMES = %w(LICENSE License Licence COPYING README Readme ReadMe)
|
4
4
|
|
5
|
+
def self.find(install_path)
|
6
|
+
new(install_path).find
|
7
|
+
end
|
8
|
+
|
5
9
|
def initialize(install_path)
|
6
10
|
@install_path = install_path
|
7
11
|
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_uri}")
|
5
|
+
LicenseFinder::DB = Sequel.connect("#{LicenseFinder::Platform.sqlite_adapter}://#{LicenseFinder.config.database_uri}")
|
6
6
|
Sequel.extension :migration, :core_extensions
|
7
|
-
Sequel::Migrator.run(DB, LicenseFinder::ROOT_PATH.join('../db/migrate'))
|
7
|
+
Sequel::Migrator.run(LicenseFinder::DB, LicenseFinder::ROOT_PATH.join('../db/migrate'))
|
@@ -2,18 +2,17 @@ module LicenseFinder
|
|
2
2
|
class Dependency < Sequel::Model
|
3
3
|
plugin :boolean_readers
|
4
4
|
many_to_one :license, class: LicenseAlias
|
5
|
-
many_to_one :approval
|
6
5
|
many_to_many :children, join_table: :ancestries, left_key: :parent_dependency_id, right_key: :child_dependency_id, class: self
|
7
6
|
many_to_many :parents, join_table: :ancestries, left_key: :child_dependency_id, right_key: :parent_dependency_id, class: self
|
8
7
|
many_to_many :bundler_groups
|
9
8
|
|
10
9
|
dataset_module do
|
11
|
-
def
|
12
|
-
|
10
|
+
def managed
|
11
|
+
manually_managed.invert
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
16
|
-
|
14
|
+
def manually_managed
|
15
|
+
where(manual: true)
|
17
16
|
end
|
18
17
|
|
19
18
|
def obsolete(current)
|
@@ -26,32 +25,58 @@ module LicenseFinder
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def self.named(name)
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
find_or_create(name: name.to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
def bundler_group_names=(names)
|
32
|
+
current_groups = names.map { |name| BundlerGroup.named(name) }
|
33
|
+
|
34
|
+
remove, add = set_diff(bundler_groups, current_groups)
|
35
|
+
|
36
|
+
remove.each { |g| remove_bundler_group(g) }
|
37
|
+
add.each { |g| add_bundler_group(g) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def children_names=(names)
|
41
|
+
current_children = names.map { |name| Dependency.named(name) }
|
42
|
+
|
43
|
+
remove, add = set_diff(children, current_children)
|
44
|
+
|
45
|
+
remove.each { |c| remove_child(c) }
|
46
|
+
add.each { |c| add_child(c) }
|
32
47
|
end
|
33
48
|
|
34
49
|
def approve!
|
35
|
-
|
36
|
-
|
50
|
+
self.manually_approved = true
|
51
|
+
save
|
37
52
|
end
|
38
53
|
|
39
54
|
def approved?
|
40
|
-
|
41
|
-
# as truthy, so we catch this here for jruby support.
|
42
|
-
(license && license.whitelisted?) || (approval.state && approval.state != 0)
|
55
|
+
(license && license.whitelisted?) || manually_approved?
|
43
56
|
end
|
44
57
|
|
45
58
|
def set_license_manually!(license_name)
|
46
|
-
self.license = LicenseAlias.
|
59
|
+
self.license = LicenseAlias.named(license_name)
|
47
60
|
self.license_manual = true
|
48
61
|
save
|
49
62
|
end
|
50
63
|
|
51
|
-
def
|
52
|
-
return if
|
53
|
-
|
54
|
-
|
64
|
+
def apply_better_license(license_name)
|
65
|
+
return if license_manual
|
66
|
+
if license.nil? || license.name != license_name
|
67
|
+
self.license = LicenseAlias.named(license_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
# Foreign method, belongs on Set
|
74
|
+
#
|
75
|
+
# Returns a pair of sets, which contain the elements that would have to be
|
76
|
+
# removed from (and respectively added to) the first set in order to obtain
|
77
|
+
# the second set.
|
78
|
+
def set_diff(older, newer)
|
79
|
+
return older - newer, newer - older
|
55
80
|
end
|
56
81
|
end
|
57
82
|
end
|
@@ -40,8 +40,7 @@ module LicenseFinder
|
|
40
40
|
def convert
|
41
41
|
@dep = create_dependency
|
42
42
|
@dep.license = create_license
|
43
|
-
@dep.
|
44
|
-
@dep.manual = non_bundler_source?
|
43
|
+
@dep.manual = manually_managed?
|
45
44
|
associate_bundler_groups
|
46
45
|
@dep.save
|
47
46
|
end
|
@@ -58,8 +57,8 @@ module LicenseFinder
|
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
def
|
62
|
-
@legacy_attrs['source']
|
60
|
+
def manually_managed?
|
61
|
+
@legacy_attrs['source'] != "bundle"
|
63
62
|
end
|
64
63
|
|
65
64
|
def create_dependency
|
@@ -70,10 +69,6 @@ module LicenseFinder
|
|
70
69
|
LicenseAlias.find_or_create(name: legacy_attrs['license'])
|
71
70
|
end
|
72
71
|
|
73
|
-
def create_approval
|
74
|
-
Sql::Approval.convert(legacy_attrs)
|
75
|
-
end
|
76
|
-
|
77
72
|
def find_children
|
78
73
|
Sql::Dependency.where(name: legacy_attrs['children'])
|
79
74
|
end
|
@@ -85,38 +80,35 @@ module LicenseFinder
|
|
85
80
|
end
|
86
81
|
|
87
82
|
module Sql
|
88
|
-
|
89
|
-
|
83
|
+
class Dependency < Sequel::Model
|
84
|
+
plugin :boolean_readers
|
85
|
+
|
86
|
+
many_to_one :license, class: LicenseAlias
|
87
|
+
many_to_many :children, join_table: :ancestries, left_key: :parent_dependency_id, right_key: :child_dependency_id, class: self
|
88
|
+
many_to_many :bundler_groups
|
89
|
+
|
90
|
+
VALID_ATTRIBUTES = {
|
91
|
+
'name' => 'name',
|
92
|
+
'version' => 'version',
|
93
|
+
'summary' => 'summary',
|
94
|
+
'description' => 'description',
|
95
|
+
'homepage' => 'homepage',
|
96
|
+
'approved' => 'manually_approved'
|
97
|
+
}
|
98
|
+
|
99
|
+
def self.convert(attrs)
|
90
100
|
create remap_attrs(attrs)
|
91
101
|
end
|
92
102
|
|
93
|
-
def remap_attrs(legacy_attrs)
|
94
|
-
|
103
|
+
def self.remap_attrs(legacy_attrs)
|
104
|
+
VALID_ATTRIBUTES.each_with_object({}) do |(legacy_key, new_key), new_attrs|
|
95
105
|
new_attrs[new_key] = legacy_attrs[legacy_key]
|
96
106
|
end
|
97
107
|
end
|
98
108
|
end
|
99
109
|
|
100
|
-
class Dependency < Sequel::Model
|
101
|
-
extend Convertable
|
102
|
-
VALID_ATTRIBUTES = Hash[*%w[name version summary description homepage].map { |k| [k, k] }.flatten]
|
103
|
-
|
104
|
-
many_to_one :license, class: LicenseAlias
|
105
|
-
many_to_one :approval
|
106
|
-
many_to_many :children, join_table: :ancestries, left_key: :parent_dependency_id, right_key: :child_dependency_id, class: self
|
107
|
-
many_to_many :bundler_groups
|
108
|
-
end
|
109
|
-
|
110
110
|
class BundlerGroup < Sequel::Model
|
111
111
|
end
|
112
|
-
|
113
|
-
class Approval < Sequel::Model
|
114
|
-
extend Convertable
|
115
|
-
|
116
|
-
VALID_ATTRIBUTES = {
|
117
|
-
'approved' => 'state'
|
118
|
-
}
|
119
|
-
end
|
120
112
|
end
|
121
113
|
end
|
122
114
|
end
|