license_scout 1.3.7 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +195 -0
  3. data/bin/license_scout +3 -59
  4. data/bin/mix_lock_json +0 -0
  5. data/bin/rebar_lock_json +0 -0
  6. data/lib/license_scout/cli.rb +99 -0
  7. data/lib/license_scout/collector.rb +25 -77
  8. data/lib/license_scout/config.rb +94 -0
  9. data/lib/license_scout/data/dependeny_manifest_v2_schema.json +62 -0
  10. data/lib/license_scout/data/exceptions.json +306 -0
  11. data/lib/license_scout/data/licenses.json +4653 -0
  12. data/lib/license_scout/dependency.rb +79 -7
  13. data/lib/license_scout/dependency_manager/base.rb +74 -42
  14. data/lib/license_scout/dependency_manager/berkshelf.rb +25 -50
  15. data/lib/license_scout/dependency_manager/bundler/_bundler_script.rb +1 -1
  16. data/lib/license_scout/dependency_manager/bundler.rb +47 -69
  17. data/lib/license_scout/dependency_manager/cpanm.rb +62 -112
  18. data/lib/license_scout/dependency_manager/dep.rb +29 -36
  19. data/lib/license_scout/dependency_manager/glide.rb +25 -36
  20. data/lib/license_scout/dependency_manager/godep.rb +27 -26
  21. data/lib/license_scout/dependency_manager/habitat.rb +126 -0
  22. data/lib/license_scout/dependency_manager/mix.rb +105 -0
  23. data/lib/license_scout/dependency_manager/npm.rb +30 -86
  24. data/lib/license_scout/dependency_manager/rebar.rb +26 -45
  25. data/lib/license_scout/dependency_manager.rb +19 -5
  26. data/lib/license_scout/exceptions.rb +2 -43
  27. data/lib/license_scout/license.rb +126 -0
  28. data/lib/license_scout/{license_file_analyzer.rb → log.rb} +4 -6
  29. data/lib/license_scout/reporter.rb +149 -55
  30. data/lib/license_scout/spdx.rb +123 -0
  31. data/lib/license_scout/version.rb +1 -1
  32. data/lib/license_scout.rb +2 -0
  33. data/native_parsers/mix_lock_json/README.md +21 -0
  34. data/native_parsers/mix_lock_json/lib/mix_lock_json.ex +20 -0
  35. data/native_parsers/mix_lock_json/mix.exs +31 -0
  36. data/native_parsers/mix_lock_json/mix.lock +3 -0
  37. data/{erl_src → native_parsers}/rebar_lock_json/rebar.lock +2 -2
  38. metadata +144 -67
  39. data/lib/license_scout/canonical_licenses/BSD-2-Clause.txt +0 -19
  40. data/lib/license_scout/canonical_licenses/BSD-3-Clause.txt +0 -27
  41. data/lib/license_scout/canonical_licenses/BSD-4-Clause.txt +0 -31
  42. data/lib/license_scout/canonical_licenses/Chef-MLSA.txt +0 -5
  43. data/lib/license_scout/canonical_licenses/ISC.txt +0 -14
  44. data/lib/license_scout/canonical_licenses/MIT.txt +0 -20
  45. data/lib/license_scout/dependency_manager/bundler/LICENSE.md +0 -23
  46. data/lib/license_scout/dependency_manager/json/README.md +0 -392
  47. data/lib/license_scout/dependency_manager/manual.rb +0 -67
  48. data/lib/license_scout/license_file_analyzer/any_matcher.rb +0 -37
  49. data/lib/license_scout/license_file_analyzer/definitions.rb +0 -219
  50. data/lib/license_scout/license_file_analyzer/header_matcher.rb +0 -34
  51. data/lib/license_scout/license_file_analyzer/matcher.rb +0 -46
  52. data/lib/license_scout/license_file_analyzer/template.rb +0 -45
  53. data/lib/license_scout/license_file_analyzer/templates/Apache2-short.txt +0 -11
  54. data/lib/license_scout/license_file_analyzer/templates/Apache2.txt +0 -170
  55. data/lib/license_scout/license_file_analyzer/templates/BSD-2-Clause-bullets.txt +0 -18
  56. data/lib/license_scout/license_file_analyzer/templates/BSD-2-Clause.txt +0 -19
  57. data/lib/license_scout/license_file_analyzer/templates/BSD-3-Clause-alt-format.txt +0 -24
  58. data/lib/license_scout/license_file_analyzer/templates/BSD-3-Clause.txt +0 -21
  59. data/lib/license_scout/license_file_analyzer/templates/BSD.txt +0 -24
  60. data/lib/license_scout/license_file_analyzer/templates/Chef-MLSA.txt +0 -5
  61. data/lib/license_scout/license_file_analyzer/templates/EPLICENSE.txt +0 -286
  62. data/lib/license_scout/license_file_analyzer/templates/GPL-2.0.txt +0 -339
  63. data/lib/license_scout/license_file_analyzer/templates/GPL-3.0.txt +0 -674
  64. data/lib/license_scout/license_file_analyzer/templates/ISC.txt +0 -2
  65. data/lib/license_scout/license_file_analyzer/templates/LGPL-3.0.txt +0 -165
  66. data/lib/license_scout/license_file_analyzer/templates/MIT.txt +0 -9
  67. data/lib/license_scout/license_file_analyzer/templates/MPL2.txt +0 -373
  68. data/lib/license_scout/license_file_analyzer/templates/Python-2.0.txt +0 -47
  69. data/lib/license_scout/license_file_analyzer/templates/Ruby.txt +0 -52
  70. data/lib/license_scout/license_file_analyzer/text.rb +0 -46
  71. data/lib/license_scout/net_fetcher.rb +0 -106
  72. data/lib/license_scout/options.rb +0 -47
  73. data/lib/license_scout/overrides.rb +0 -1120
  74. /data/{erl_src → native_parsers}/rebar_lock_json/README.md +0 -0
  75. /data/{erl_src → native_parsers}/rebar_lock_json/rebar.config +0 -0
  76. /data/{erl_src → native_parsers}/rebar_lock_json/src/rebar_lock_json.app.src +0 -0
  77. /data/{erl_src → native_parsers}/rebar_lock_json/src/rebar_lock_json.erl +0 -0
@@ -1,392 +0,0 @@
1
- # JSON implementation for Ruby ![Travis Widget]
2
- [Travis Widget]: http://travis-ci.org/flori/json.svg?branch=master
3
-
4
- ## Description
5
-
6
- This is a implementation of the JSON specification according to RFC 7159
7
- http://www.ietf.org/rfc/rfc7159.txt . Starting from version 1.0.0 on there
8
- will be two variants available:
9
-
10
- * A pure ruby variant, that relies on the iconv and the stringscan
11
- extensions, which are both part of the ruby standard library.
12
- * The quite a bit faster native extension variant, which is in parts
13
- implemented in C or Java and comes with its own unicode conversion
14
- functions and a parser generated by the ragel state machine compiler
15
- http://www.complang.org/ragel/ .
16
-
17
- Both variants of the JSON generator generate UTF-8 character sequences by
18
- default. If an :ascii\_only option with a true value is given, they escape all
19
- non-ASCII and control characters with \uXXXX escape sequences, and support
20
- UTF-16 surrogate pairs in order to be able to generate the whole range of
21
- unicode code points.
22
-
23
- All strings, that are to be encoded as JSON strings, should be UTF-8 byte
24
- sequences on the Ruby side. To encode raw binary strings, that aren't UTF-8
25
- encoded, please use the to\_json\_raw\_object method of String (which produces
26
- an object, that contains a byte array) and decode the result on the receiving
27
- endpoint.
28
-
29
- ## Installation
30
-
31
- It's recommended to use the extension variant of JSON, because it's faster than
32
- the pure ruby variant. If you cannot build it on your system, you can settle
33
- for the latter.
34
-
35
- Just type into the command line as root:
36
-
37
- ```
38
- # rake install
39
- ```
40
-
41
- The above command will build the extensions and install them on your system.
42
-
43
- ```
44
- # rake install_pure
45
- ```
46
-
47
- or
48
-
49
- ```
50
- # ruby install.rb
51
- ```
52
-
53
- will just install the pure ruby implementation of JSON.
54
-
55
- If you use Rubygems you can type
56
-
57
- ```
58
- # gem install json
59
- ```
60
-
61
- instead, to install the newest JSON version.
62
-
63
- There is also a pure ruby json only variant of the gem, that can be installed
64
- with:
65
-
66
- ```
67
- # gem install json_pure
68
- ```
69
-
70
- ## Compiling the extensions yourself
71
-
72
- If you want to create the `parser.c` file from its `parser.rl` file or draw nice
73
- graphviz images of the state machines, you need ragel from:
74
- http://www.complang.org/ragel/
75
-
76
- ## Usage
77
-
78
- To use JSON you can
79
-
80
- ```ruby
81
- require 'json'
82
- ```
83
-
84
- to load the installed variant (either the extension `'json'` or the pure
85
- variant `'json_pure'`). If you have installed the extension variant, you can
86
- pick either the extension variant or the pure variant by typing
87
-
88
- ```ruby
89
- require 'json/ext'
90
- ```
91
-
92
- or
93
-
94
- ```ruby
95
- require 'json/pure'
96
- ```
97
-
98
- Now you can parse a JSON document into a ruby data structure by calling
99
-
100
- ```ruby
101
- JSON.parse(document)
102
- ```
103
-
104
- If you want to generate a JSON document from a ruby data structure call
105
- ```ruby
106
- JSON.generate(data)
107
- ```
108
-
109
- You can also use the `pretty_generate` method (which formats the output more
110
- verbosely and nicely) or `fast_generate` (which doesn't do any of the security
111
- checks generate performs, e. g. nesting deepness checks).
112
-
113
- There are also the JSON and JSON[] methods which use parse on a String or
114
- generate a JSON document from an array or hash:
115
-
116
- ```ruby
117
- document = JSON 'test' => 23 # => "{\"test\":23}"
118
- document = JSON['test' => 23] # => "{\"test\":23}"
119
- ```
120
-
121
- and
122
-
123
- ```ruby
124
- data = JSON '{"test":23}' # => {"test"=>23}
125
- data = JSON['{"test":23}'] # => {"test"=>23}
126
- ```
127
-
128
- You can choose to load a set of common additions to ruby core's objects if
129
- you
130
-
131
- ```ruby
132
- require 'json/add/core'
133
- ```
134
-
135
- After requiring this you can, e. g., serialise/deserialise Ruby ranges:
136
-
137
- ```ruby
138
- JSON JSON(1..10) # => 1..10
139
- ```
140
-
141
- To find out how to add JSON support to other or your own classes, read the
142
- section "More Examples" below.
143
-
144
- To get the best compatibility to rails' JSON implementation, you can
145
-
146
- ```ruby
147
- require 'json/add/rails'
148
- ```
149
-
150
- Both of the additions attempt to require `'json'` (like above) first, if it has
151
- not been required yet.
152
-
153
- ## More Examples
154
-
155
- To create a JSON document from a ruby data structure, you can call
156
- `JSON.generate` like that:
157
-
158
- ```ruby
159
- json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
160
- # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"
161
- ```
162
-
163
- To get back a ruby data structure from a JSON document, you have to call
164
- JSON.parse on it:
165
-
166
- ```ruby
167
- JSON.parse json
168
- # => [1, 2, {"a"=>3.141}, false, true, nil, "4..10"]
169
- ```
170
-
171
- Note, that the range from the original data structure is a simple
172
- string now. The reason for this is, that JSON doesn't support ranges
173
- or arbitrary classes. In this case the json library falls back to call
174
- `Object#to_json`, which is the same as `#to_s.to_json`.
175
-
176
- It's possible to add JSON support serialization to arbitrary classes by
177
- simply implementing a more specialized version of the `#to_json method`, that
178
- should return a JSON object (a hash converted to JSON with `#to_json`) like
179
- this (don't forget the `*a` for all the arguments):
180
-
181
- ```ruby
182
- class Range
183
- def to_json(*a)
184
- {
185
- 'json_class' => self.class.name, # = 'Range'
186
- 'data' => [ first, last, exclude_end? ]
187
- }.to_json(*a)
188
- end
189
- end
190
- ```
191
-
192
- The hash key `json_class` is the class, that will be asked to deserialise the
193
- JSON representation later. In this case it's `Range`, but any namespace of
194
- the form `A::B` or `::A::B` will do. All other keys are arbitrary and can be
195
- used to store the necessary data to configure the object to be deserialised.
196
-
197
- If a the key `json_class` is found in a JSON object, the JSON parser checks
198
- if the given class responds to the `json_create` class method. If so, it is
199
- called with the JSON object converted to a Ruby hash. So a range can
200
- be deserialised by implementing `Range.json_create` like this:
201
-
202
- ```ruby
203
- class Range
204
- def self.json_create(o)
205
- new(*o['data'])
206
- end
207
- end
208
- ```
209
-
210
- Now it possible to serialise/deserialise ranges as well:
211
-
212
- ```ruby
213
- json = JSON.generate [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
214
- # => "[1,2,{\"a\":3.141},false,true,null,{\"json_class\":\"Range\",\"data\":[4,10,false]}]"
215
- JSON.parse json
216
- # => [1, 2, {"a"=>3.141}, false, true, nil, 4..10]
217
- ```
218
-
219
- `JSON.generate` always creates the shortest possible string representation of a
220
- ruby data structure in one line. This is good for data storage or network
221
- protocols, but not so good for humans to read. Fortunately there's also
222
- `JSON.pretty_generate` (or `JSON.pretty_generate`) that creates a more readable
223
- output:
224
-
225
- ```ruby
226
- puts JSON.pretty_generate([1, 2, {"a"=>3.141}, false, true, nil, 4..10])
227
- [
228
- 1,
229
- 2,
230
- {
231
- "a": 3.141
232
- },
233
- false,
234
- true,
235
- null,
236
- {
237
- "json_class": "Range",
238
- "data": [
239
- 4,
240
- 10,
241
- false
242
- ]
243
- }
244
- ]
245
- ```
246
-
247
- There are also the methods `Kernel#j` for generate, and `Kernel#jj` for
248
- `pretty_generate` output to the console, that work analogous to Core Ruby's `p` and
249
- the `pp` library's `pp` methods.
250
-
251
- The script `tools/server.rb` contains a small example if you want to test, how
252
- receiving a JSON object from a webrick server in your browser with the
253
- javasript prototype library http://www.prototypejs.org works.
254
-
255
- ## Speed Comparisons
256
-
257
- I have created some benchmark results (see the benchmarks/data-p4-3Ghz
258
- subdir of the package) for the JSON-parser to estimate the speed up in the C
259
- extension:
260
-
261
- ```
262
- Comparing times (call_time_mean):
263
- 1 ParserBenchmarkExt#parser 900 repeats:
264
- 553.922304770 ( real) -> 21.500x
265
- 0.001805307
266
- 2 ParserBenchmarkYAML#parser 1000 repeats:
267
- 224.513358139 ( real) -> 8.714x
268
- 0.004454078
269
- 3 ParserBenchmarkPure#parser 1000 repeats:
270
- 26.755020642 ( real) -> 1.038x
271
- 0.037376163
272
- 4 ParserBenchmarkRails#parser 1000 repeats:
273
- 25.763381731 ( real) -> 1.000x
274
- 0.038814780
275
- calls/sec ( time) -> speed covers
276
- secs/call
277
- ```
278
-
279
- In the table above 1 is `JSON::Ext::Parser`, 2 is `YAML.load` with YAML
280
- compatbile JSON document, 3 is is `JSON::Pure::Parser`, and 4 is
281
- `ActiveSupport::JSON.decode`. The ActiveSupport JSON-decoder converts the
282
- input first to YAML and then uses the YAML-parser, the conversion seems to
283
- slow it down so much that it is only as fast as the `JSON::Pure::Parser`!
284
-
285
- If you look at the benchmark data you can see that this is mostly caused by
286
- the frequent high outliers - the median of the Rails-parser runs is still
287
- overall smaller than the median of the `JSON::Pure::Parser` runs:
288
-
289
- ```
290
- Comparing times (call_time_median):
291
- 1 ParserBenchmarkExt#parser 900 repeats:
292
- 800.592479481 ( real) -> 26.936x
293
- 0.001249075
294
- 2 ParserBenchmarkYAML#parser 1000 repeats:
295
- 271.002390644 ( real) -> 9.118x
296
- 0.003690004
297
- 3 ParserBenchmarkRails#parser 1000 repeats:
298
- 30.227910865 ( real) -> 1.017x
299
- 0.033082008
300
- 4 ParserBenchmarkPure#parser 1000 repeats:
301
- 29.722384421 ( real) -> 1.000x
302
- 0.033644676
303
- calls/sec ( time) -> speed covers
304
- secs/call
305
- ```
306
-
307
- I have benchmarked the `JSON-Generator` as well. This generated a few more
308
- values, because there are different modes that also influence the achieved
309
- speed:
310
-
311
- ```
312
- Comparing times (call_time_mean):
313
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
314
- 547.354332608 ( real) -> 15.090x
315
- 0.001826970
316
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
317
- 443.968212317 ( real) -> 12.240x
318
- 0.002252414
319
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
320
- 375.104545883 ( real) -> 10.341x
321
- 0.002665923
322
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
323
- 49.978706968 ( real) -> 1.378x
324
- 0.020008521
325
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
326
- 38.531868759 ( real) -> 1.062x
327
- 0.025952543
328
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
329
- 36.927649925 ( real) -> 1.018x 7 (>=3859)
330
- 0.027079979
331
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
332
- 36.272134441 ( real) -> 1.000x 6 (>=3859)
333
- 0.027569373
334
- calls/sec ( time) -> speed covers
335
- secs/call
336
- ```
337
-
338
- In the table above 1-3 are `JSON::Ext::Generator` methods. 4, 6, and 7 are
339
- `JSON::Pure::Generator` methods and 5 is the Rails JSON generator. It is now a
340
- bit faster than the `generator_safe` and `generator_pretty` methods of the pure
341
- variant but slower than the others.
342
-
343
- To achieve the fastest JSON document output, you can use the `fast_generate`
344
- method. Beware, that this will disable the checking for circular Ruby data
345
- structures, which may cause JSON to go into an infinite loop.
346
-
347
- Here are the median comparisons for completeness' sake:
348
-
349
- ```
350
- Comparing times (call_time_median):
351
- 1 GeneratorBenchmarkExt#generator_fast 1000 repeats:
352
- 708.258020939 ( real) -> 16.547x
353
- 0.001411915
354
- 2 GeneratorBenchmarkExt#generator_safe 1000 repeats:
355
- 569.105020353 ( real) -> 13.296x
356
- 0.001757145
357
- 3 GeneratorBenchmarkExt#generator_pretty 900 repeats:
358
- 482.825371244 ( real) -> 11.280x
359
- 0.002071142
360
- 4 GeneratorBenchmarkPure#generator_fast 1000 repeats:
361
- 62.717626652 ( real) -> 1.465x
362
- 0.015944481
363
- 5 GeneratorBenchmarkRails#generator 1000 repeats:
364
- 43.965681162 ( real) -> 1.027x
365
- 0.022745013
366
- 6 GeneratorBenchmarkPure#generator_safe 1000 repeats:
367
- 43.929073409 ( real) -> 1.026x 7 (>=3859)
368
- 0.022763968
369
- 7 GeneratorBenchmarkPure#generator_pretty 1000 repeats:
370
- 42.802514491 ( real) -> 1.000x 6 (>=3859)
371
- 0.023363113
372
- calls/sec ( time) -> speed covers
373
- secs/call
374
- ```
375
-
376
- ## Author
377
-
378
- Florian Frank <mailto:flori@ping.de>
379
-
380
- ## License
381
-
382
- Ruby License, see https://www.ruby-lang.org/en/about/license.txt.
383
-
384
- ## Download
385
-
386
- The latest version of this library can be downloaded at
387
-
388
- * https://rubygems.org/gems/json
389
-
390
- Online Documentation should be located at
391
-
392
- * http://json.rubyforge.org
@@ -1,67 +0,0 @@
1
- #
2
- # Copyright:: Copyright 2016, Chef Software Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require "license_scout/dependency_manager/base"
19
- require "license_scout/dependency"
20
- require "license_scout/overrides"
21
-
22
- module LicenseScout
23
- module DependencyManager
24
- class Manual < Base
25
- def name
26
- "manual"
27
- end
28
-
29
- def detected?
30
- !options.manual_licenses.nil?
31
- end
32
-
33
- def dependencies
34
- validate_input!
35
-
36
- options.manual_licenses.map do |d|
37
- create_dependency(
38
- d[:name],
39
- d[:version],
40
- d[:license],
41
- resolve_license_file_locations(d[:license_files]),
42
- d[:dependency_manager]
43
- )
44
- end
45
- end
46
-
47
- def resolve_license_file_locations(license_files)
48
- LicenseScout::Overrides::OverrideLicenseSet.new(license_files)
49
- .resolve_locations(project_dir)
50
- end
51
-
52
- def validate_input!
53
- unless options.manual_licenses.is_a?(Array)
54
- raise LicenseScout::Exceptions::InvalidManualDependency.new("Invalid manual dependency is specified. :manual_licenses should be an Array in options.")
55
- end
56
-
57
- options.manual_licenses.each do |l|
58
- l.keys.each do |k|
59
- unless %i{name version license license_files dependency_manager}.include?(k)
60
- raise LicenseScout::Exceptions::InvalidManualDependency.new("Invalid manual dependency is specified. Key '#{k}' is not supported.")
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,37 +0,0 @@
1
- # Copied from https://github.com/pivotal/LicenseFinder
2
- #
3
- # The MIT License
4
- #
5
- # Copyright (c) 2012 Pivotal Labs
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in
15
- # all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- # THE SOFTWARE.
24
-
25
- module LicenseScout
26
- module LicenseFileAnalyzer
27
- class AnyMatcher
28
- def initialize(*matchers)
29
- @matchers = matchers
30
- end
31
-
32
- def matches_text?(text)
33
- @matchers.any? { |m| m.matches_text? text }
34
- end
35
- end
36
- end
37
- end
@@ -1,219 +0,0 @@
1
- # Copied from https://github.com/pivotal/LicenseFinder
2
- #
3
- # The MIT License
4
- #
5
- # Copyright (c) 2012 Pivotal Labs
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in
15
- # all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- # THE SOFTWARE.
24
-
25
- require "license_scout/license_file_analyzer/matcher"
26
- require "license_scout/license_file_analyzer/any_matcher"
27
- require "license_scout/license_file_analyzer/header_matcher"
28
- require "license_scout/license_file_analyzer/template"
29
-
30
- module LicenseScout
31
- module LicenseFileAnalyzer
32
-
33
- class License
34
-
35
- attr_reader :matcher
36
- attr_reader :short_name
37
-
38
- def initialize(short_name:, matcher: nil)
39
- @short_name = short_name
40
- @matcher = matcher || Matcher.from_template(Template.named(short_name))
41
- end
42
-
43
- def matches_text?(text)
44
- matcher.matches_text?(text)
45
- end
46
-
47
- end
48
-
49
- module Definitions
50
- extend self
51
-
52
- def all
53
- [
54
- apache2,
55
- bsd,
56
- gplv2,
57
- gplv3,
58
- isc,
59
- lgpl,
60
- mit,
61
- mpl2,
62
- bsd_3_clause,
63
- python,
64
- ruby,
65
- bsd_2_clause,
66
- erlang_public,
67
- chef_mlsa,
68
- ]
69
- end
70
-
71
- private
72
-
73
- def apache2
74
- matcher = AnyMatcher.new(
75
- Matcher.from_template(Template.named("Apache2")),
76
- Matcher.from_template(Template.named("Apache2-short"))
77
- )
78
-
79
- License.new(
80
- short_name: "Apache-2.0",
81
- matcher: matcher
82
- )
83
- end
84
-
85
- def bsd
86
- License.new(
87
- short_name: "BSD"
88
- )
89
- end
90
-
91
- def gplv2
92
- License.new(
93
- short_name: "GPL-2.0"
94
- )
95
- end
96
-
97
- def gplv3
98
- License.new(
99
- short_name: "GPL-3.0"
100
- )
101
- end
102
-
103
- def isc
104
- License.new(
105
- short_name: "ISC"
106
- )
107
- end
108
-
109
- def lgpl
110
- License.new(
111
- short_name: "LGPL-3.0"
112
- )
113
- end
114
-
115
- def mit
116
- url_regexp = %r{MIT Licen[sc]e.*http://(?:www\.)?opensource\.org/licenses/mit-license}
117
- header_regexp = /The MIT Licen[sc]e/
118
- one_liner_regexp = /is released under the MIT licen[sc]e/
119
-
120
- matcher = AnyMatcher.new(
121
- Matcher.from_template(Template.named("MIT")),
122
- Matcher.from_regex(url_regexp),
123
- HeaderMatcher.new(Matcher.from_regex(header_regexp)),
124
- Matcher.from_regex(one_liner_regexp)
125
- )
126
-
127
- License.new(
128
- short_name: "MIT",
129
- matcher: matcher
130
- )
131
- end
132
-
133
- def mpl2
134
- header_regexp = /Mozilla Public Licen[sc]e, version 2.0/
135
-
136
- matcher = AnyMatcher.new(
137
- Matcher.from_template(Template.named("MPL2")),
138
- HeaderMatcher.new(Matcher.from_regex(header_regexp))
139
- )
140
-
141
- License.new(
142
- short_name: "MPL-2.0",
143
- matcher: matcher
144
- )
145
- end
146
-
147
- def bsd_3_clause
148
- substitution = [
149
- "Neither the name of <organization> nor the names of <possessive> contributors may be used to endorse or promote products derived from this software without specific prior written permission.",
150
- "The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.",
151
- ]
152
-
153
- template = Template.named("BSD-3-Clause")
154
- alternate_content = template.content.gsub(*substitution)
155
-
156
- alt_format_template = Template.named("BSD-3-Clause-alt-format")
157
- alt_format_with_alt_content = alt_format_template.content.gsub(*substitution)
158
-
159
- matcher = AnyMatcher.new(
160
- Matcher.from_template(template),
161
- Matcher.from_text(alternate_content),
162
- Matcher.from_template(alt_format_template),
163
- Matcher.from_text(alt_format_with_alt_content)
164
- )
165
-
166
- License.new(
167
- short_name: "BSD-3-Clause",
168
- matcher: matcher
169
- )
170
- end
171
-
172
- def python
173
- License.new(
174
- short_name: "Python-2.0"
175
- )
176
- end
177
-
178
- def ruby
179
- url = "http://www.ruby-lang.org/en/LICENSE.txt"
180
-
181
- matcher = AnyMatcher.new(
182
- Matcher.from_template(Template.named("Ruby")),
183
- Matcher.from_text(url)
184
- )
185
-
186
- License.new(
187
- short_name: "Ruby",
188
- matcher: matcher
189
- )
190
- end
191
-
192
- def bsd_2_clause
193
- matcher = AnyMatcher.new(
194
- Matcher.from_template(Template.named("BSD-2-Clause")),
195
- Matcher.from_template(Template.named("BSD-2-Clause-bullets"))
196
- )
197
-
198
- License.new(
199
- short_name: "BSD-2-Clause",
200
- matcher: matcher
201
- )
202
- end
203
-
204
- def erlang_public
205
- License.new(
206
- short_name: "Erlang-Public",
207
- matcher: Matcher.from_template(Template.named("EPLICENSE"))
208
- )
209
- end
210
-
211
- def chef_mlsa
212
- License.new(
213
- short_name: "Chef-MLSA"
214
- )
215
- end
216
-
217
- end
218
- end
219
- end