license_finder 1.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.rdoc +27 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/README.md +139 -159
  6. data/Rakefile +17 -13
  7. data/features/features/cli_spec.rb +43 -0
  8. data/features/features/configure/add_dependencies_spec.rb +37 -0
  9. data/features/features/configure/approve_dependencies_spec.rb +30 -0
  10. data/features/features/configure/assign_licenses_spec.rb +20 -0
  11. data/features/features/configure/ignore_dependencies_spec.rb +35 -0
  12. data/features/features/configure/ignore_groups_spec.rb +31 -0
  13. data/features/features/configure/name_project_spec.rb +32 -0
  14. data/features/features/configure/whitelist_licenses_spec.rb +40 -0
  15. data/features/features/package_managers/bower_spec.rb +14 -0
  16. data/features/features/package_managers/cocoapods_spec.rb +14 -0
  17. data/features/features/package_managers/gradle_spec.rb +14 -0
  18. data/features/features/package_managers/maven_spec.rb +14 -0
  19. data/features/features/package_managers/npm_spec.rb +14 -0
  20. data/features/features/package_managers/pip_spec.rb +14 -0
  21. data/features/features/report/csv_spec.rb +17 -0
  22. data/features/features/report/html_spec.rb +50 -0
  23. data/{spec → features}/fixtures/Podfile +0 -0
  24. data/{spec → features}/fixtures/build.gradle +0 -0
  25. data/{spec → features}/fixtures/pom.xml +0 -0
  26. data/features/support/testing_dsl.rb +295 -0
  27. data/lib/license_finder.rb +16 -50
  28. data/lib/license_finder/cli.rb +13 -253
  29. data/lib/license_finder/cli/approvals.rb +26 -0
  30. data/lib/license_finder/cli/base.rb +20 -0
  31. data/lib/license_finder/cli/dependencies.rb +39 -0
  32. data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
  33. data/lib/license_finder/cli/ignored_groups.rb +30 -0
  34. data/lib/license_finder/cli/licenses.rb +24 -0
  35. data/lib/license_finder/cli/main.rb +82 -0
  36. data/lib/license_finder/cli/makes_decisions.rb +48 -0
  37. data/lib/license_finder/cli/patched_thor.rb +34 -0
  38. data/lib/license_finder/cli/project_name.rb +31 -0
  39. data/lib/license_finder/cli/whitelist.rb +32 -0
  40. data/lib/license_finder/configuration.rb +14 -145
  41. data/lib/license_finder/decision_applier.rb +46 -0
  42. data/lib/license_finder/decisions.rb +174 -0
  43. data/lib/license_finder/license.rb +13 -32
  44. data/lib/license_finder/license/definitions.rb +15 -13
  45. data/lib/license_finder/license/template.rb +1 -1
  46. data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
  47. data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
  48. data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
  49. data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
  50. data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
  51. data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
  52. data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
  53. data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
  54. data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
  55. data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
  56. data/lib/license_finder/package.rb +77 -7
  57. data/lib/license_finder/package_manager.rb +43 -0
  58. data/lib/license_finder/package_managers/bower.rb +1 -1
  59. data/lib/license_finder/package_managers/bower_package.rb +23 -44
  60. data/lib/license_finder/package_managers/bundler.rb +4 -7
  61. data/lib/license_finder/package_managers/bundler_package.rb +14 -31
  62. data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
  63. data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
  64. data/lib/license_finder/package_managers/gradle.rb +6 -2
  65. data/lib/license_finder/package_managers/gradle_package.rb +6 -30
  66. data/lib/license_finder/package_managers/manual_package.rb +25 -0
  67. data/lib/license_finder/package_managers/maven_package.rb +8 -37
  68. data/lib/license_finder/package_managers/npm.rb +16 -4
  69. data/lib/license_finder/package_managers/npm_package.rb +12 -43
  70. data/lib/license_finder/package_managers/pip_package.rb +17 -37
  71. data/lib/license_finder/platform.rb +0 -16
  72. data/lib/license_finder/possible_license_file.rb +9 -14
  73. data/lib/license_finder/possible_license_files.rb +1 -5
  74. data/lib/license_finder/report.rb +26 -0
  75. data/lib/license_finder/reports/csv_report.rb +58 -0
  76. data/lib/license_finder/reports/erb_report.rb +61 -0
  77. data/lib/license_finder/reports/html_report.rb +10 -1
  78. data/lib/license_finder/reports/markdown_report.rb +7 -1
  79. data/lib/license_finder/reports/templates/bootstrap.css +9 -0
  80. data/lib/license_finder/reports/templates/html_report.erb +105 -0
  81. data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
  82. data/lib/license_finder/reports/text_report.rb +5 -3
  83. data/lib/license_finder/version.rb +3 -0
  84. data/license_finder.gemspec +2 -6
  85. data/release/instructions.md +8 -0
  86. data/spec/feature_helper.rb +11 -0
  87. data/spec/fixtures/config/license_finder.yml +3 -0
  88. data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
  89. data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
  90. data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
  91. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
  92. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
  93. data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
  94. data/spec/lib/license_finder/cli/main_spec.rb +110 -0
  95. data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
  96. data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
  97. data/spec/lib/license_finder/configuration_spec.rb +46 -191
  98. data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
  99. data/spec/lib/license_finder/decisions_spec.rb +347 -0
  100. data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
  101. data/spec/lib/license_finder/license_spec.rb +2 -30
  102. data/spec/lib/license_finder/package_manager_spec.rb +22 -0
  103. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
  104. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
  105. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
  106. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
  107. data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
  108. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
  109. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
  110. data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
  111. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
  112. data/spec/lib/license_finder/package_spec.rb +121 -0
  113. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
  114. data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
  115. data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
  116. data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
  117. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
  118. data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
  119. data/spec/spec_helper.rb +1 -4
  120. data/spec/support/shared_examples_for_package.rb +0 -11
  121. data/spec/support/shared_examples_for_package_manager.rb +1 -0
  122. data/spec/support/stdout_helpers.rb +4 -11
  123. metadata +73 -158
  124. data/db/migrate/201303290935_create_dependencies.rb +0 -14
  125. data/db/migrate/201303291155_create_licenses.rb +0 -13
  126. data/db/migrate/201303291402_create_approvals.rb +0 -13
  127. data/db/migrate/201303291456_create_ancestries.rb +0 -9
  128. data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
  129. data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
  130. data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
  131. data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
  132. data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
  133. data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
  134. data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
  135. data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
  136. data/db/migrate/201307251107_reassociate_license.rb +0 -23
  137. data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
  138. data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
  139. data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
  140. data/db/migrate/201311192010_drop_approvals.rb +0 -5
  141. data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
  142. data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
  143. data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
  144. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
  145. data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
  146. data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
  147. data/features/cli.feature +0 -37
  148. data/features/cocoapods_dependencies.feature +0 -10
  149. data/features/configure_bundler_groups.feature +0 -23
  150. data/features/configure_ignore_dependencies.feature +0 -16
  151. data/features/configure_project_name.feature +0 -10
  152. data/features/configure_whitelist.feature +0 -27
  153. data/features/gradle_dependencies.feature +0 -9
  154. data/features/manually_added.feature +0 -19
  155. data/features/manually_approved.feature +0 -10
  156. data/features/manually_assigned_license.feature +0 -16
  157. data/features/maven_dependencies.feature +0 -9
  158. data/features/multiple_licenses.feature +0 -9
  159. data/features/node_dependencies.feature +0 -9
  160. data/features/python_dependencies.feature +0 -9
  161. data/features/report_csv.feature +0 -15
  162. data/features/report_html.feature +0 -24
  163. data/features/step_definitions/cli_steps.rb +0 -51
  164. data/features/step_definitions/cocoapod_steps.rb +0 -8
  165. data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
  166. data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
  167. data/features/step_definitions/configure_project_name_steps.rb +0 -3
  168. data/features/step_definitions/configure_whitelist_steps.rb +0 -45
  169. data/features/step_definitions/gradle_steps.rb +0 -8
  170. data/features/step_definitions/manually_added_steps.rb +0 -28
  171. data/features/step_definitions/manually_approved_steps.rb +0 -24
  172. data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
  173. data/features/step_definitions/maven_steps.rb +0 -8
  174. data/features/step_definitions/multiple_licenses_steps.rb +0 -14
  175. data/features/step_definitions/node_steps.rb +0 -8
  176. data/features/step_definitions/python_steps.rb +0 -8
  177. data/features/step_definitions/report_csv_steps.rb +0 -20
  178. data/features/step_definitions/report_html_steps.rb +0 -60
  179. data/features/step_definitions/shared_steps.rb +0 -307
  180. data/lib/data/license_finder.example.yml +0 -12
  181. data/lib/license_finder/dependency_manager.rb +0 -92
  182. data/lib/license_finder/package_saver.rb +0 -44
  183. data/lib/license_finder/reports/dependency_report.rb +0 -34
  184. data/lib/license_finder/reports/detailed_text_report.rb +0 -19
  185. data/lib/license_finder/reports/formatted_report.rb +0 -40
  186. data/lib/license_finder/reports/reporter.rb +0 -27
  187. data/lib/license_finder/tables.rb +0 -9
  188. data/lib/license_finder/tables/bundler_group.rb +0 -7
  189. data/lib/license_finder/tables/dependency.rb +0 -113
  190. data/lib/license_finder/tables/manual_approval.rb +0 -13
  191. data/lib/license_finder/yml_to_sql.rb +0 -117
  192. data/lib/templates/html_report.erb +0 -117
  193. data/lib/templates/text_report.erb +0 -3
  194. data/release/gem_version.rb +0 -3
  195. data/release/manual_instructions.md +0 -29
  196. data/release/publish.sh +0 -32
  197. data/spec/fixtures/APACHE-2-LICENSE +0 -202
  198. data/spec/fixtures/GPLv2 +0 -339
  199. data/spec/fixtures/ISC-LICENSE +0 -10
  200. data/spec/fixtures/MIT-LICENSE +0 -22
  201. data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
  202. data/spec/fixtures/README-with-MIT-LICENSE +0 -222
  203. data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
  204. data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
  205. data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
  206. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
  207. data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
  208. data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
  209. data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
  210. data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
  211. data/spec/fixtures/readme/README +0 -0
  212. data/spec/fixtures/readme/Readme.markdown +0 -0
  213. data/spec/lib/license_finder/cli_spec.rb +0 -298
  214. data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
  215. data/spec/lib/license_finder/package_saver_spec.rb +0 -82
  216. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
  217. data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
  218. data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
  219. data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
  220. data/spec/lib/license_finder_spec.rb +0 -16
@@ -0,0 +1,46 @@
1
+ module LicenseFinder
2
+ class DecisionApplier
3
+ def initialize(options)
4
+ @decisions = options.fetch(:decisions)
5
+ @packages = options.fetch(:packages)
6
+ end
7
+
8
+ def unapproved
9
+ acknowledged.reject(&:approved?)
10
+ end
11
+
12
+ def acknowledged
13
+ base_packages = decisions.packages + packages
14
+ base_packages.
15
+ reject { |package| ignored?(package) }.
16
+ map { |package| with_decided_licenses(package) }.
17
+ map { |package| with_approval(package) }
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :packages, :decisions
23
+
24
+ def ignored?(package)
25
+ decisions.ignored?(package.name) ||
26
+ package.groups.any? { |group| decisions.ignored_group?(group) }
27
+ end
28
+
29
+ def with_decided_licenses(package)
30
+ decisions.licenses_of(package.name).each do |license|
31
+ package.decide_on_license license
32
+ end
33
+ package
34
+ end
35
+
36
+ def with_approval(package)
37
+ if decisions.approved?(package.name)
38
+ package.approved_manually!(decisions.approval_of(package.name))
39
+ elsif package.licenses.any? { |license| decisions.whitelisted?(license) }
40
+ package.whitelisted!
41
+ end
42
+ package
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,174 @@
1
+ module LicenseFinder
2
+ class Decisions
3
+ ######
4
+ # READ
5
+ ######
6
+
7
+ attr_reader :packages, :whitelisted, :ignored, :ignored_groups, :project_name
8
+
9
+ def licenses_of(name)
10
+ @licenses[name]
11
+ end
12
+
13
+ def approval_of(name)
14
+ @approvals[name]
15
+ end
16
+
17
+ def approved?(name)
18
+ @approvals.has_key?(name)
19
+ end
20
+
21
+ def whitelisted?(lic)
22
+ @whitelisted.include?(lic)
23
+ end
24
+
25
+ def ignored?(name)
26
+ @ignored.include?(name)
27
+ end
28
+
29
+ def ignored_group?(name)
30
+ @ignored_groups.include?(name)
31
+ end
32
+
33
+ #######
34
+ # WRITE
35
+ #######
36
+
37
+ TXN = Struct.new(:who, :why, :safe_when) do
38
+ def self.from_hash(txn)
39
+ new(txn[:who], txn[:why], txn[:when])
40
+ end
41
+ end
42
+
43
+ def initialize
44
+ @decisions = []
45
+ @packages = Set.new
46
+ @licenses = Hash.new { |h, k| h[k] = Set.new }
47
+ @approvals = {}
48
+ @whitelisted = Set.new
49
+ @ignored = Set.new
50
+ @ignored_groups = Set.new
51
+ end
52
+
53
+ def add_package(name, version, txn = {})
54
+ @decisions << [:add_package, name, version, txn]
55
+ @packages << ManualPackage.new(name, version)
56
+ self
57
+ end
58
+
59
+ def remove_package(name, txn = {})
60
+ @decisions << [:remove_package, name, txn]
61
+ @packages.delete(ManualPackage.new(name))
62
+ self
63
+ end
64
+
65
+ def license(name, lic, txn = {})
66
+ @decisions << [:license, name, lic, txn]
67
+ @licenses[name] << License.find_by_name(lic)
68
+ self
69
+ end
70
+
71
+ def unlicense(name, lic, txn= {})
72
+ @decisions << [:unlicense, name, lic, txn]
73
+ @licenses[name].delete(License.find_by_name(lic))
74
+ self
75
+ end
76
+
77
+ def approve(name, txn = {})
78
+ @decisions << [:approve, name, txn]
79
+ @approvals[name] = TXN.from_hash(txn)
80
+ self
81
+ end
82
+
83
+ def unapprove(name, txn = {})
84
+ @decisions << [:unapprove, name, txn]
85
+ @approvals.delete(name)
86
+ self
87
+ end
88
+
89
+ def whitelist(lic, txn = {})
90
+ @decisions << [:whitelist, lic, txn]
91
+ @whitelisted << License.find_by_name(lic)
92
+ self
93
+ end
94
+
95
+ def unwhitelist(lic, txn = {})
96
+ @decisions << [:unwhitelist, lic, txn]
97
+ @whitelisted.delete(License.find_by_name(lic))
98
+ self
99
+ end
100
+
101
+ def ignore(name, txn = {})
102
+ @decisions << [:ignore, name, txn]
103
+ @ignored << name
104
+ self
105
+ end
106
+
107
+ def heed(name, txn = {})
108
+ @decisions << [:heed, name, txn]
109
+ @ignored.delete(name)
110
+ self
111
+ end
112
+
113
+ def ignore_group(name, txn = {})
114
+ @decisions << [:ignore_group, name, txn]
115
+ @ignored_groups << name
116
+ self
117
+ end
118
+
119
+ def heed_group(name, txn = {})
120
+ @decisions << [:heed_group, name, txn]
121
+ @ignored_groups.delete(name)
122
+ self
123
+ end
124
+
125
+ def name_project(name, txn = {})
126
+ @decisions << [:name_project, name, txn]
127
+ @project_name = name
128
+ self
129
+ end
130
+
131
+ def unname_project(txn = {})
132
+ @decisions << [:unname_project, txn]
133
+ @project_name = nil
134
+ self
135
+ end
136
+
137
+ #########
138
+ # PERSIST
139
+ #########
140
+
141
+ def self.saved!(file)
142
+ restore(read!(file))
143
+ end
144
+
145
+ def save!(file)
146
+ write!(persist, file)
147
+ end
148
+
149
+ def self.restore(persisted)
150
+ result = new
151
+ if persisted
152
+ YAML.load(persisted).each do |action, *args|
153
+ result.send(action, *args)
154
+ end
155
+ end
156
+ result
157
+ end
158
+
159
+ def persist
160
+ YAML.dump(@decisions)
161
+ end
162
+
163
+ def self.read!(file)
164
+ file.read if file.exist?
165
+ end
166
+
167
+ def write!(value, file)
168
+ file.dirname.mkpath
169
+ file.open('w+') do |f|
170
+ f.print value
171
+ end
172
+ end
173
+ end
174
+ end
@@ -2,12 +2,12 @@ module LicenseFinder
2
2
  class License
3
3
  class << self
4
4
  def all
5
- @all ||= Definitions.all(LicenseFinder.config.whitelist)
5
+ @all ||= Definitions.all
6
6
  end
7
7
 
8
8
  def find_by_name(name)
9
- name ||= "other"
10
- all.detect { |l| l.matches_name? name } || Definitions.build_unrecognized(name, LicenseFinder.config.whitelist)
9
+ name ||= "unknown"
10
+ all.detect { |l| l.matches_name? name } || Definitions.build_unrecognized(name)
11
11
  end
12
12
 
13
13
  def find_by_text(text)
@@ -15,20 +15,11 @@ module LicenseFinder
15
15
  end
16
16
  end
17
17
 
18
- autoload :Definitions, "license_finder/license/definitions"
19
- autoload :Text, "license_finder/license/text"
20
- autoload :Template, "license_finder/license/template"
21
- autoload :Matcher, "license_finder/license/matcher"
22
- autoload :HeaderMatcher, "license_finder/license/header_matcher"
23
- autoload :AnyMatcher, "license_finder/license/any_matcher"
24
- autoload :NoneMatcher, "license_finder/license/none_matcher"
25
-
26
18
  def initialize(settings)
27
19
  @short_name = settings.fetch(:short_name)
28
20
  @pretty_name = settings.fetch(:pretty_name, short_name)
29
21
  @other_names = settings.fetch(:other_names, [])
30
22
  @url = settings.fetch(:url)
31
- @whitelisted = settings.fetch(:whitelisted, false)
32
23
  @matcher = settings.fetch(:matcher) { Matcher.from_template(Template.named(short_name)) }
33
24
  end
34
25
 
@@ -46,14 +37,6 @@ module LicenseFinder
46
37
  matcher.matches_text?(text)
47
38
  end
48
39
 
49
- def whitelisted?
50
- @whitelisted
51
- end
52
-
53
- def whitelist
54
- copy(whitelisted: true)
55
- end
56
-
57
40
  def eql?(other)
58
41
  name == other.name
59
42
  end
@@ -70,17 +53,15 @@ module LicenseFinder
70
53
  def names
71
54
  ([short_name, pretty_name] + other_names).uniq
72
55
  end
73
-
74
- def copy(overrides)
75
- settings = {
76
- short_name: short_name,
77
- pretty_name: pretty_name,
78
- other_names: other_names,
79
- url: url,
80
- whitelisted: whitelisted?,
81
- matcher: matcher
82
- }
83
- self.class.new(settings.merge(overrides))
84
- end
85
56
  end
86
57
  end
58
+
59
+ require "license_finder/license/text"
60
+ require "license_finder/license/template"
61
+
62
+ require "license_finder/license/matcher"
63
+ require "license_finder/license/header_matcher"
64
+ require "license_finder/license/any_matcher"
65
+ require "license_finder/license/none_matcher"
66
+
67
+ require "license_finder/license/definitions"
@@ -3,7 +3,7 @@ module LicenseFinder
3
3
  module Definitions
4
4
  extend self
5
5
 
6
- def all(whitelist)
6
+ def all
7
7
  [
8
8
  apache2,
9
9
  bsd,
@@ -15,32 +15,34 @@ module LicenseFinder
15
15
  python,
16
16
  ruby,
17
17
  simplifiedbsd
18
- ].map { |license|
19
- whitelist_if_necessary(license, whitelist)
20
- }
18
+ ]
21
19
  end
22
20
 
23
- def build_unrecognized(name, whitelist)
24
- result = License.new(
21
+ def build_unrecognized(name)
22
+ License.new(
25
23
  short_name: name,
26
24
  url: nil,
27
25
  matcher: NoneMatcher.new
28
26
  )
29
- whitelist_if_necessary(result, whitelist)
30
27
  end
31
28
 
32
29
  private
33
30
 
34
- def whitelist_if_necessary(license, whitelist)
35
- whitelisted = whitelist.any? { |name| license.matches_name? name }
36
- whitelisted ? license.whitelist : license
37
- end
38
-
39
31
  def apache2
40
32
  License.new(
41
33
  short_name: "Apache2",
42
34
  pretty_name: "Apache 2.0",
43
- other_names: ["Apache-2.0", "Apache Software License", "Apache License 2.0", "Apache License Version 2.0", "Apache Public License 2.0"],
35
+ other_names: [
36
+ "Apache-2.0",
37
+ "Apache Software License",
38
+ "Apache License 2.0",
39
+ "Apache License Version 2.0",
40
+ "Apache Public License 2.0",
41
+ "The Apache Software License, Version 2.0",
42
+ "Apache 2",
43
+ "Apache License",
44
+ "Apache License, Version 2.0"
45
+ ],
44
46
  url: "http://www.apache.org/licenses/LICENSE-2.0.txt"
45
47
  )
46
48
  end
@@ -2,7 +2,7 @@ module LicenseFinder
2
2
  class License
3
3
  class Template
4
4
  def self.named(name)
5
- path = ROOT_PATH.join("data", "licenses", "#{name}.txt")
5
+ path = ROOT_PATH.join("license", "templates", "#{name}.txt")
6
6
  new(path.read)
7
7
  end
8
8
 
@@ -9,8 +9,10 @@ module LicenseFinder
9
9
  # Additional guidelines are:
10
10
  #
11
11
  # - if you're going to use Package#licenses ...
12
- # - implement #licenses_names_from_spec
13
- # - implement #install_path
12
+ # - and the package spec will report licenses,
13
+ # pass :spec_licenses in the constructor options
14
+ # - and the package's files can be searched for licenses
15
+ # pass :install_path in the constructor options
14
16
  # - else
15
17
  # - implement #licenses
16
18
  #
@@ -29,15 +31,70 @@ module LicenseFinder
29
31
  end
30
32
  end
31
33
 
32
- def initialize options={}
34
+ def initialize(name, version = nil, options={})
33
35
  @logger = options[:logger] || LicenseFinder::Logger::Default.new
36
+
37
+ @name = name
38
+ @version = version
39
+ @summary = options[:summary] || ""
40
+ @description = options[:description] || ""
41
+ @homepage = options[:homepage] || ""
42
+ @children = options[:children] || []
43
+ @parents = Set.new # will be figured out later by package manager
44
+ @groups = options[:groups] || []
45
+
46
+ ## APPROVAL
47
+ @whitelisted = false
48
+ @manual_approval = nil
49
+
50
+ ## LICENSING
51
+ @license_names_from_spec = options[:spec_licenses] || []
52
+ @install_path = options[:install_path]
53
+ @missing = options[:missing] || false
54
+ @decided_licenses = Set.new
55
+ end
56
+
57
+ attr_reader :name, :version,
58
+ :summary, :description, :homepage,
59
+ :children, :parents, :groups
60
+
61
+ ## APPROVAL
62
+
63
+ def approved_manually!(approval)
64
+ @manual_approval = approval
65
+ end
66
+
67
+ def whitelisted!
68
+ @whitelisted = true
69
+ end
70
+
71
+ def approved?
72
+ approved_manually? || whitelisted?
34
73
  end
35
74
 
75
+ def approved_manually?
76
+ !@manual_approval.nil?
77
+ end
78
+
79
+ def whitelisted?
80
+ @whitelisted
81
+ end
82
+
83
+ attr_reader :manual_approval
84
+
85
+ ## LICENSING
86
+
87
+ attr_reader :license_names_from_spec # stubbed in tests, otherwise private
88
+ attr_reader :install_path # checked in tests, otherwise private
89
+
36
90
  def licenses
37
- @licenses ||= determine_license.to_set
91
+ @licenses ||= determine_licenses.to_set
38
92
  end
39
93
 
40
- def determine_license
94
+ def determine_licenses
95
+ dl = @decided_licenses
96
+ return dl if dl.any?
97
+
41
98
  lfs = licenses_from_spec
42
99
  return lfs if lfs.any?
43
100
 
@@ -47,6 +104,10 @@ module LicenseFinder
47
104
  [default_license].to_set
48
105
  end
49
106
 
107
+ def decide_on_license(license)
108
+ @decided_licenses << license
109
+ end
110
+
50
111
  def licenses_from_spec
51
112
  license_names_from_spec.map do |name|
52
113
  License.find_by_name(name).tap do |license|
@@ -71,8 +132,17 @@ module LicenseFinder
71
132
  License.find_by_name nil
72
133
  end
73
134
 
74
- def install_path
75
- nil
135
+ def missing?
136
+ @missing
76
137
  end
77
138
  end
78
139
  end
140
+
141
+ require 'license_finder/package_managers/manual_package'
142
+ require 'license_finder/package_managers/bower_package'
143
+ require 'license_finder/package_managers/bundler_package'
144
+ require 'license_finder/package_managers/pip_package'
145
+ require 'license_finder/package_managers/npm_package'
146
+ require 'license_finder/package_managers/maven_package'
147
+ require 'license_finder/package_managers/gradle_package'
148
+ require 'license_finder/package_managers/cocoa_pods_package'